Skip to content

Commit

Permalink
feat(ble): Allow disabling BLE BAS reporting
Browse files Browse the repository at this point in the history
The battery reporting has been known to cause macOS computers to wakeup repeatedly. In some cases (e.g. display or custom lighting implementation) one might want to collect battery SOC without broadcasting over BLE
  • Loading branch information
ReFil committed Oct 18, 2023
1 parent 5d19dae commit 2e782c8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ config ZMK_BLE_CLEAR_BONDS_ON_START
bool "Configuration that clears all bond information from the keyboard on startup."
default n

config ZMK_BLE_BATTERY_REPORTING
bool "Explicitly enable or disable the BLE BAS reporting, can cause wakeups on MacOS"
default y

# HID GATT notifications sent this way are *not* picked up by Linux, and possibly others.
config BT_GATT_NOTIFY_MULTIPLE
default n
Expand Down
4 changes: 2 additions & 2 deletions app/src/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static int zmk_battery_update(const struct device *battery) {

if (last_state_of_charge != state_of_charge.val1) {
last_state_of_charge = state_of_charge.val1;

#if IS_ENABLED(CONFIG_ZMK_BLE_BATTERY_REPORTING)
LOG_DBG("Setting BAS GATT battery level to %d.", last_state_of_charge);

rc = bt_bas_set_battery_level(last_state_of_charge);
Expand All @@ -60,7 +60,7 @@ static int zmk_battery_update(const struct device *battery) {
LOG_WRN("Failed to set BAS GATT battery level (err %d)", rc);
return rc;
}

#endif
rc = ZMK_EVENT_RAISE(new_zmk_battery_state_changed(
(struct zmk_battery_state_changed){.state_of_charge = last_state_of_charge}));
}
Expand Down
11 changes: 7 additions & 4 deletions docs/docs/config/battery.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ See [Configuration Overview](index.md) for instructions on how to change these s

Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/app/Kconfig)

| Config | Type | Description | Default |
| ------------------------------------ | ---- | ------------------------------------------------------ | ------- |
| `CONFIG_ZMK_BATTERY_REPORTING` | bool | Enables/disables all battery level detection/reporting | n |
| `CONFIG_ZMK_BATTERY_REPORT_INTERVAL` | int | Battery level report interval in seconds | 60 |
| Config | Type | Description | Default |
| ------------------------------------ | ---- | ------------------------------------------------------------------------------------------------- | ------- |
| `CONFIG_ZMK_BATTERY_REPORTING` | bool | Enables/disables all battery level detection/reporting | n |
| `CONFIG_ZMK_BATTERY_REPORT_INTERVAL` | int | Battery level report interval in seconds | 60 |
| `CONFIG_ZMK_BLE_BATTERY_REPORTING` | bool | Enables/disables battery level reporting over BLE (Dependent on `CONFIG_ZMK_BATTERY_REPORTING=y`) | y |

Note: MacOS devices can be repeatedly woken up from sleep by the battery level reports

### Devicetree

Expand Down

0 comments on commit 2e782c8

Please sign in to comment.