@@ -302,11 +302,17 @@ bmp_error_t bmp_state_change_cb(bmp_api_event_t event)
302302 {
303303 case USB_CONNECTED :
304304 is_usb_connected_ = true;
305+ if (!is_ble_connected ()) {
306+ select_usb ();
307+ }
305308 update_config_files ();
306309 break ;
307310
308311 case USB_DISCONNECTED :
309312 is_usb_connected_ = false;
313+ if (is_ble_connected ()) {
314+ select_ble ();
315+ }
310316 break ;
311317
312318 case BLE_ADVERTISING_START :
@@ -320,11 +326,18 @@ bmp_error_t bmp_state_change_cb(bmp_api_event_t event)
320326
321327 case BLE_CONNECTED :
322328 is_ble_connected_ = true;
329+ if (!is_usb_connected ()) {
330+ select_ble ();
331+ }
323332 bmp_indicator_set (INDICATOR_CONNECTED , 0 );
324333 break ;
325334
326335 case BLE_DISCONNECTED :
327336 is_ble_connected_ = false;
337+ // Disable below code because BLE could be disconnected unintentionally
338+ // if (is_usb_connected()) {
339+ // select_usb();
340+ // }
328341 break ;
329342
330343 default :
@@ -523,6 +536,14 @@ bool get_ble_enabled() { return ble_enabled & has_ble; }
523536void set_ble_enabled (bool enabled ) { ble_enabled = enabled ; }
524537bool get_usb_enabled () { return usb_enabled & has_usb ; }
525538void set_usb_enabled (bool enabled ) { usb_enabled = enabled ; }
539+ void select_ble (void ) {
540+ ble_enabled = true;
541+ usb_enabled = false;
542+ }
543+ void select_usb (void ) {
544+ ble_enabled = false;
545+ usb_enabled = true;
546+ }
526547
527548extern bool via_keymap_update_flag ;
528549
@@ -591,12 +612,10 @@ bool process_record_user_bmp(uint16_t keycode, keyrecord_t* record) {
591612 set_usb_enabled (true);
592613 return false;
593614 case SEL_BLE :
594- set_usb_enabled (false);
595- set_ble_enabled (true);
615+ select_ble ();
596616 return false;
597617 case SEL_USB :
598- set_ble_enabled (false);
599- set_usb_enabled (true);
618+ select_usb ();
600619 return false;
601620 case ADV_ID0 ... ADV_ID7 :
602621 BMPAPI -> ble .advertise (keycode - ADV_ID0 );
0 commit comments