|
|
|
@ -21,7 +21,7 @@ static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets);
@@ -21,7 +21,7 @@ static sys_slist_t widgets = SYS_SLIST_STATIC_INIT(&widgets);
|
|
|
|
|
|
|
|
|
|
struct battery_status_state { |
|
|
|
|
uint8_t level; |
|
|
|
|
#if IS_ENABLED(CONFIG_USB) |
|
|
|
|
#if IS_ENABLED(CONFIG_USB_DEVICE_STACK) |
|
|
|
|
bool usb_present; |
|
|
|
|
#endif |
|
|
|
|
}; |
|
|
|
@ -31,11 +31,11 @@ static void set_battery_symbol(lv_obj_t *label, struct battery_status_state stat
@@ -31,11 +31,11 @@ static void set_battery_symbol(lv_obj_t *label, struct battery_status_state stat
|
|
|
|
|
|
|
|
|
|
uint8_t level = state.level; |
|
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_USB) |
|
|
|
|
#if IS_ENABLED(CONFIG_USB_DEVICE_STACK) |
|
|
|
|
if (state.usb_present) { |
|
|
|
|
strcpy(text, LV_SYMBOL_CHARGE); |
|
|
|
|
} |
|
|
|
|
#endif /* IS_ENABLED(CONFIG_USB) */ |
|
|
|
|
#endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */ |
|
|
|
|
|
|
|
|
|
if (level > 95) { |
|
|
|
|
strcat(text, LV_SYMBOL_BATTERY_FULL); |
|
|
|
@ -59,9 +59,9 @@ void battery_status_update_cb(struct battery_status_state state) {
@@ -59,9 +59,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) { |
|
|
|
|
return (struct battery_status_state) { |
|
|
|
|
.level = bt_bas_get_battery_level(), |
|
|
|
|
#if IS_ENABLED(CONFIG_USB) |
|
|
|
|
#if IS_ENABLED(CONFIG_USB_DEVICE_STACK) |
|
|
|
|
.usb_present = zmk_usb_is_powered(), |
|
|
|
|
#endif /* IS_ENABLED(CONFIG_USB) */ |
|
|
|
|
#endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */ |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -69,9 +69,9 @@ ZMK_DISPLAY_WIDGET_LISTENER(widget_battery_status, struct battery_status_state,
@@ -69,9 +69,9 @@ ZMK_DISPLAY_WIDGET_LISTENER(widget_battery_status, struct battery_status_state,
|
|
|
|
|
battery_status_update_cb, battery_status_get_state) |
|
|
|
|
|
|
|
|
|
ZMK_SUBSCRIPTION(widget_battery_status, zmk_battery_state_changed); |
|
|
|
|
#if IS_ENABLED(CONFIG_USB) |
|
|
|
|
#if IS_ENABLED(CONFIG_USB_DEVICE_STACK) |
|
|
|
|
ZMK_SUBSCRIPTION(widget_battery_status, zmk_usb_conn_state_changed); |
|
|
|
|
#endif /* IS_ENABLED(CONFIG_USB) */ |
|
|
|
|
#endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */ |
|
|
|
|
|
|
|
|
|
int zmk_widget_battery_status_init(struct zmk_widget_battery_status *widget, lv_obj_t *parent) { |
|
|
|
|
widget->obj = lv_label_create(parent, NULL); |
|
|
|
|