diff options
author | zhiayang <[email protected]> | 2024-02-19 19:15:19 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2024-02-19 19:15:19 -0500 |
commit | a9ae6796a088730d7377f660e78af17f11bb87c7 (patch) | |
tree | c3500baf5096bc64afe72912e43cd20e13d49b97 /app | |
parent | fda6a5f18534ac7c480fdec5854f063432733f69 (diff) | |
download | zmk-a9ae6796a088730d7377f660e78af17f11bb87c7.tar.gz zmk-a9ae6796a088730d7377f660e78af17f11bb87c7.zip |
fix(display): Proper initial display of battery status
* fix initial display of battery status on displays, and also fix a null deref
Diffstat (limited to 'app')
-rw-r--r-- | app/boards/arm/corneish_zen/widgets/battery_status.c | 4 | ||||
-rw-r--r-- | app/boards/shields/nice_view/widgets/status.c | 4 | ||||
-rw-r--r-- | app/src/display/widgets/battery_status.c | 4 |
3 files changed, 9 insertions, 3 deletions
diff --git a/app/boards/arm/corneish_zen/widgets/battery_status.c b/app/boards/arm/corneish_zen/widgets/battery_status.c index 011319c408..39b811b53f 100644 --- a/app/boards/arm/corneish_zen/widgets/battery_status.c +++ b/app/boards/arm/corneish_zen/widgets/battery_status.c @@ -66,8 +66,10 @@ void battery_status_update_cb(struct battery_status_state state) { } static struct battery_status_state battery_status_get_state(const zmk_event_t *eh) { + const struct zmk_battery_state_changed *ev = as_zmk_battery_state_changed(eh); + return (struct battery_status_state) { - .level = zmk_battery_state_of_charge(), + .level = (ev != NULL) ? ev->state_of_charge : zmk_battery_state_of_charge(), #if IS_ENABLED(CONFIG_USB_DEVICE_STACK) .usb_present = zmk_usb_is_powered(), #endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */ diff --git a/app/boards/shields/nice_view/widgets/status.c b/app/boards/shields/nice_view/widgets/status.c index 93139eca0a..061b7127ce 100644 --- a/app/boards/shields/nice_view/widgets/status.c +++ b/app/boards/shields/nice_view/widgets/status.c @@ -210,8 +210,10 @@ static void battery_status_update_cb(struct battery_status_state state) { } static struct battery_status_state battery_status_get_state(const zmk_event_t *eh) { + const struct zmk_battery_state_changed *ev = as_zmk_battery_state_changed(eh); + return (struct battery_status_state) { - .level = zmk_battery_state_of_charge(), + .level = (ev != NULL) ? ev->state_of_charge : zmk_battery_state_of_charge(), #if IS_ENABLED(CONFIG_USB_DEVICE_STACK) .usb_present = zmk_usb_is_powered(), #endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */ diff --git a/app/src/display/widgets/battery_status.c b/app/src/display/widgets/battery_status.c index 06f55f3f40..bec6964ba9 100644 --- a/app/src/display/widgets/battery_status.c +++ b/app/src/display/widgets/battery_status.c @@ -9,6 +9,7 @@ #include <zephyr/logging/log.h> LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); +#include <zmk/battery.h> #include <zmk/display.h> #include <zmk/display/widgets/battery_status.h> #include <zmk/usb.h> @@ -63,8 +64,9 @@ void battery_status_update_cb(struct battery_status_state state) { static struct battery_status_state battery_status_get_state(const zmk_event_t *eh) { const struct zmk_battery_state_changed *ev = as_zmk_battery_state_changed(eh); + return (struct battery_status_state) { - .level = ev->state_of_charge, + .level = (ev != NULL) ? ev->state_of_charge : zmk_battery_state_of_charge(), #if IS_ENABLED(CONFIG_USB_DEVICE_STACK) .usb_present = zmk_usb_is_powered(), #endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */ |