added behaviour

This commit is contained in:
Giulio De Donato 2021-06-09 18:33:14 +02:00
parent ba45aaa81b
commit 45f8787ba4
5 changed files with 36 additions and 16 deletions

View file

@ -8,13 +8,14 @@
#define BT_NXT_CMD 1 #define BT_NXT_CMD 1
#define BT_PRV_CMD 2 #define BT_PRV_CMD 2
#define BT_SEL_CMD 3 #define BT_SEL_CMD 3
// #define BT_FULL_RESET_CMD 4 #define BT_RST_CMD 4
/* /*
Note: Some future commands will include additional parameters, so we Note: Some future commands will include additional parameters, so we
defines these aliases up front. defines these aliases up front.
*/ */
#define BT_RST BT_RST_CMD 0
#define BT_CLR BT_CLR_CMD 0 #define BT_CLR BT_CLR_CMD 0
#define BT_NXT BT_NXT_CMD 0 #define BT_NXT BT_NXT_CMD 0
#define BT_PRV BT_PRV_CMD 0 #define BT_PRV BT_PRV_CMD 0

View file

@ -13,6 +13,7 @@ int zmk_ble_clear_bonds();
int zmk_ble_prof_next(); int zmk_ble_prof_next();
int zmk_ble_prof_prev(); int zmk_ble_prof_prev();
int zmk_ble_prof_select(uint8_t index); int zmk_ble_prof_select(uint8_t index);
int zmk_ble_reset_clear_all_bonds();
int zmk_ble_active_profile_index(); int zmk_ble_active_profile_index();
bt_addr_le_t *zmk_ble_active_profile_addr(); bt_addr_le_t *zmk_ble_active_profile_addr();

View file

@ -24,6 +24,8 @@ static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
switch (binding->param1) { switch (binding->param1) {
case BT_CLR_CMD: case BT_CLR_CMD:
return zmk_ble_clear_bonds(); return zmk_ble_clear_bonds();
case BT_RST_CMD:
return zmk_ble_reset_clear_all_bonds();
case BT_NXT_CMD: case BT_NXT_CMD:
return zmk_ble_prof_next(); return zmk_ble_prof_next();
case BT_PRV_CMD: case BT_PRV_CMD:

View file

@ -548,6 +548,28 @@ static void zmk_ble_ready(int err) {
update_advertising(); update_advertising();
} }
int zmk_ble_reset_clear_all_bonds() {
LOG_WRN("Clearing all existing BLE bond information from the keyboard");
for (int i = 0; i < 10; i++) {
bt_unpair(i, NULL);
}
int ret = 0;
for (int i = 0; i < PROFILE_COUNT; i++) {
char setting_name[15];
sprintf(setting_name, "ble/profiles/%d", i);
int err = settings_delete(setting_name);
if (err) {
LOG_ERR("Failed to delete setting: %d", err);
ret -= 1;
}
}
update_advertising();
return ret;
}
static int zmk_ble_init(const struct device *_arg) { static int zmk_ble_init(const struct device *_arg) {
int err = bt_enable(NULL); int err = bt_enable(NULL);
@ -573,21 +595,7 @@ static int zmk_ble_init(const struct device *_arg) {
#endif #endif
#if IS_ENABLED(CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START) #if IS_ENABLED(CONFIG_ZMK_BLE_CLEAR_BONDS_ON_START)
LOG_WRN("Clearing all existing BLE bond information from the keyboard"); zmk_ble_reset_clear_all_bonds();
for (int i = 0; i < 10; i++) {
bt_unpair(i, NULL);
}
for (int i = 0; i < PROFILE_COUNT; i++) {
char setting_name[15];
sprintf(setting_name, "ble/profiles/%d", i);
err = settings_delete(setting_name);
if (err) {
LOG_ERR("Failed to delete setting: %d", err);
}
}
#endif #endif
bt_conn_cb_register(&conn_callbacks); bt_conn_cb_register(&conn_callbacks);

View file

@ -36,6 +36,8 @@ Here is a table describing the command for each define:
| `BT_NXT` | Switch to the next profile, cycling through to the first one when the end is reached. | | `BT_NXT` | Switch to the next profile, cycling through to the first one when the end is reached. |
| `BT_PRV` | Switch to the previous profile, cycling through to the last one when the beginning is reached. | | `BT_PRV` | Switch to the previous profile, cycling through to the last one when the beginning is reached. |
| `BT_SEL` | Select the 0-indexed profile by number. Please note: this definition must include a number as an argument in the keymap to work correctly. eg. `BT_SEL 0` | | `BT_SEL` | Select the 0-indexed profile by number. Please note: this definition must include a number as an argument in the keymap to work correctly. eg. `BT_SEL 0` |
| `BT_RST` | Clear bond information between the keyboard and host for all profiles. |
## Bluetooth Behavior ## Bluetooth Behavior
@ -73,6 +75,12 @@ The bluetooth behavior completes an bluetooth action given on press.
&bt BT_SEL 1 &bt BT_SEL 1
``` ```
1. Clear the bond information between the keyboard and host for all profiles:
```
&bt BT_RST
```
## Bluetooth Pairing and Profiles ## Bluetooth Pairing and Profiles
ZMK support bluetooth “profiles” which allows connection to multiple devices (5 by default). Each profile stores the bluetooth MAC address of a peer, which can be empty if a profile has not been paired with a device yet. Upon switching to a profile, ZMK does the following: ZMK support bluetooth “profiles” which allows connection to multiple devices (5 by default). Each profile stores the bluetooth MAC address of a peer, which can be empty if a profile has not been paired with a device yet. Upon switching to a profile, ZMK does the following: