summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/include/zmk/battery.h9
-rw-r--r--app/include/zmk/events/battery_state_changed.h2
-rw-r--r--app/src/battery.c11
3 files changed, 15 insertions, 7 deletions
diff --git a/app/include/zmk/battery.h b/app/include/zmk/battery.h
new file mode 100644
index 0000000..f62219c
--- /dev/null
+++ b/app/include/zmk/battery.h
@@ -0,0 +1,9 @@
+/*
+ * Copyright (c) 2021 The ZMK Contributors
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#pragma once
+
+uint8_t zmk_battery_state_of_charge();
diff --git a/app/include/zmk/events/battery_state_changed.h b/app/include/zmk/events/battery_state_changed.h
index c03f647..6a003d8 100644
--- a/app/include/zmk/events/battery_state_changed.h
+++ b/app/include/zmk/events/battery_state_changed.h
@@ -14,6 +14,4 @@ struct zmk_battery_state_changed {
uint8_t state_of_charge;
};
-int32_t zmk_battery_state_of_charge();
-
ZMK_EVENT_DECLARE(zmk_battery_state_changed); \ No newline at end of file
diff --git a/app/src/battery.c b/app/src/battery.c
index a99660c..c63008e 100644
--- a/app/src/battery.c
+++ b/app/src/battery.c
@@ -15,13 +15,14 @@
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/event_manager.h>
+#include <zmk/battery.h>
#include <zmk/events/battery_state_changed.h>
const struct device *battery;
-static int32_t last_state_of_charge = 0;
+static uint8_t last_state_of_charge = 0;
-int32_t zmk_battery_state_of_charge() { return last_state_of_charge; }
+uint8_t zmk_battery_state_of_charge() { return last_state_of_charge; }
static int zmk_battery_update(const struct device *battery) {
struct sensor_value state_of_charge;
@@ -43,9 +44,9 @@ 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;
- LOG_DBG("Setting BAS GATT battery level to %d.", state_of_charge.val1);
+ LOG_DBG("Setting BAS GATT battery level to %d.", last_state_of_charge);
- rc = bt_bas_set_battery_level(state_of_charge.val1);
+ 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);
@@ -53,7 +54,7 @@ static int zmk_battery_update(const struct device *battery) {
}
rc = ZMK_EVENT_RAISE(new_zmk_battery_state_changed(
- (struct zmk_battery_state_changed){.state_of_charge = state_of_charge.val1}));
+ (struct zmk_battery_state_changed){.state_of_charge = last_state_of_charge}));
}
return rc;