From 3bc86af1897e9e04824e6bbda80138bdf63f133b Mon Sep 17 00:00:00 2001 From: ReFil <31960031+ReFil@users.noreply.github.com> Date: Wed, 18 Oct 2023 09:10:46 +0100 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 --- app/Kconfig | 2 +- app/src/battery.c | 4 ++-- docs/docs/config/battery.md | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index 658bcdabcaf..9852744741f 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -324,7 +324,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 87a25e08a2d..c6466272082 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 73b4ee92933..3183d03faa0 100644 --- a/docs/docs/config/battery.md +++ b/docs/docs/config/battery.md @@ -7,6 +7,12 @@ See the [battery level feature page](../features/battery.md) for more details on See [Configuration Overview](index.md) for instructions on how to change these settings. +:::note + +On MacOS the BLE battery reporting packets can cause the computer to wakeup from sleep, the battery service can be disabled indepently of battery monitoring (allowing the battery level to be displayed on a screen or through a custom lighting implementation) by setting `CONFIG_BT_BAS=n` + +::: + ### Devicetree Applies to: [`/chosen` node](https://docs.zephyrproject.org/latest/guides/dts/intro.html#aliases-and-chosen-nodes)