Skip to content

Commit 8404c50

Browse files
Select USB/BLE automatically if keyboard has one connection
1 parent 7ecf45f commit 8404c50

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

tmk_core/protocol/nrf/bmp.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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; }
523536
void set_ble_enabled(bool enabled) { ble_enabled = enabled; }
524537
bool get_usb_enabled() { return usb_enabled & has_usb; }
525538
void 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

527548
extern 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);

tmk_core/protocol/nrf/bmp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ bool get_ble_enabled();
2323
void set_ble_enabled(bool enabled);
2424
bool get_usb_enabled();
2525
void set_usb_enabled(bool enabled);
26+
void select_ble(void);
27+
void select_usb(void);
2628
bool is_ble_connected();
2729
bool is_usb_connected();
2830

0 commit comments

Comments
 (0)