From 8776911da5005d42cd0bdf108b23deca16d7ec82 Mon Sep 17 00:00:00 2001 From: ReFil <31960031+ReFil@users.noreply.github.com> Date: Wed, 15 Nov 2023 18:03:30 +0000 Subject: [PATCH] feat(ble): Allow disabling BLE BAS reporting 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 * Update docs/docs/config/battery.md Co-authored-by: Cem Aksoylar --- app/Kconfig | 2 +- app/src/battery.c | 4 ++-- docs/docs/config/battery.md | 6 ++++++ docs/docs/config/system.md | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index 072795e3..1b3eb6de 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -321,7 +321,7 @@ config ZMK_BATTERY_REPORTING bool "Battery level detection/reporting" default n select SENSOR - select BT_BAS if ZMK_BLE + imply BT_BAS if ZMK_BLE config ZMK_IDLE_TIMEOUT int "Milliseconds of inactivity before entering idle state (OLED shutoff, etc)" diff --git a/app/src/battery.c b/app/src/battery.c index 87a25e08..c6466272 100644 --- a/app/src/battery.c +++ b/app/src/battery.c @@ -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_BT_BAS) LOG_DBG("Setting BAS GATT battery level to %d.", last_state_of_charge); rc = bt_bas_set_battery_level(last_state_of_charge); @@ -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})); } diff --git a/docs/docs/config/battery.md b/docs/docs/config/battery.md index c56a30ef..8d65a00a 100644 --- a/docs/docs/config/battery.md +++ b/docs/docs/config/battery.md @@ -22,6 +22,12 @@ While `CONFIG_ZMK_BATTERY_REPORTING` is disabled by default it is implied by `CO ::: +:::note BLE reporting on MacOS + +On macOS the BLE battery reporting packets can cause the computer to wakeup from sleep. To prevent this, the battery _reporting_ service can be disabled by setting `CONFIG_BT_BAS=n`. This setting is independent of battery _monitoring_, for instance the battery level can still be indicated on a display. + +::: + ### Devicetree Applies to: [`/chosen` node](https://docs.zephyrproject.org/latest/guides/dts/intro.html#aliases-and-chosen-nodes) diff --git a/docs/docs/config/system.md b/docs/docs/config/system.md index 25d51940..b9dd580d 100644 --- a/docs/docs/config/system.md +++ b/docs/docs/config/system.md @@ -66,6 +66,7 @@ for more information on configuring Bluetooth. | Config | Type | Description | Default | | ------------------------------------------- | ---- | --------------------------------------------------------------------- | ------- | | `CONFIG_BT` | bool | Enable Bluetooth support | | +| `CONFIG_BT_BAS` | bool | Enable the Bluetooth BAS (battery reporting service) | y | | `CONFIG_BT_MAX_CONN` | int | Maximum number of simultaneous Bluetooth connections | 5 | | `CONFIG_BT_MAX_PAIRED` | int | Maximum number of paired Bluetooth devices | 5 | | `CONFIG_ZMK_BLE` | bool | Enable ZMK as a Bluetooth keyboard | |