diff --git a/app/src/battery.c b/app/src/battery.c index c6466272082e..5fdf803462f8 100644 --- a/app/src/battery.c +++ b/app/src/battery.c @@ -18,6 +18,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include #include #include +#include #include static uint8_t last_state_of_charge = 0; @@ -52,13 +53,15 @@ 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); + if (zmk_activity_get_state() == ZMK_ACTIVITY_ACTIVE) { + LOG_DBG("Setting BAS GATT battery level to %d.", last_state_of_charge); - rc = bt_bas_set_battery_level(last_state_of_charge); + rc = bt_bas_set_battery_level(last_state_of_charge); - if (rc != 0) { - LOG_WRN("Failed to set BAS GATT battery level (err %d)", rc); - return rc; + if (rc != 0) { + LOG_WRN("Failed to set BAS GATT battery level (err %d)", rc); + return rc; + } } #endif rc = ZMK_EVENT_RAISE(new_zmk_battery_state_changed(