summaryrefslogtreecommitdiff
path: root/app/src/battery.c
diff options
context:
space:
mode:
authorPete Johanson <peter@peterjohanson.com>2020-11-02 00:10:21 -0500
committerPete Johanson <peter@peterjohanson.com>2020-12-02 16:04:56 -0500
commitd5ea4269757e4b6e1d4a4185a34f359210eac310 (patch)
tree9cf7ea1777c7b1662da0910c881c640badbbbd89 /app/src/battery.c
parentf8af592a9c330d8c431cdd1e843b87bfe4446460 (diff)
refactor(battery): Fire event on battery event.
Diffstat (limited to 'app/src/battery.c')
-rw-r--r--app/src/battery.c14
1 files changed, 13 insertions, 1 deletions
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 <zmk/event-manager.h>
+#include <zmk/events/battery-state-changed.h>
+
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) {