From d5ea4269757e4b6e1d4a4185a34f359210eac310 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Mon, 2 Nov 2020 00:10:21 -0500 Subject: refactor(battery): Fire event on battery event. --- app/src/battery.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'app/src/battery.c') diff --git a/app/src/battery.c b/app/src/battery.c index 9496570..e78b2fb 100644 --- a/app/src/battery.c +++ b/app/src/battery.c @@ -14,6 +14,9 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); +#include +#include + struct device *battery; static int zmk_battery_update(struct device *battery) { @@ -35,7 +38,16 @@ static int zmk_battery_update(struct device *battery) { LOG_DBG("Setting BAS GATT battery level to %d.", state_of_charge.val1); - return bt_gatt_bas_set_battery_level(state_of_charge.val1); + rc = bt_gatt_bas_set_battery_level(state_of_charge.val1); + + if (rc != 0) { + LOG_WRN("Failed to set BAS GATT battery level (err %d)", rc); + return rc; + } + + struct battery_state_changed *ev = new_battery_state_changed(); + ev->state_of_charge = state_of_charge.val1; + return ZMK_EVENT_RAISE(ev); } static void zmk_battery_work(struct k_work *work) { -- cgit v1.2.3