Skip to content

Commit

Permalink
feat(display): Add config to show battery level in percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
caksoylar authored and petejohanson committed Dec 10, 2022
1 parent 6ccb528 commit 58eb7a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/src/display/widgets/Kconfig
Expand Up @@ -15,6 +15,13 @@ config ZMK_WIDGET_BATTERY_STATUS
default y if BT
select LVGL_USE_LABEL

if ZMK_WIDGET_BATTERY_STATUS

config ZMK_WIDGET_BATTERY_STATUS_SHOW_PERCENTAGE
bool "Show battery level percentage in text"

endif

config ZMK_WIDGET_OUTPUT_STATUS
bool "Widget for keyboard output status icons"
depends on BT && (!ZMK_SPLIT_BLE || ZMK_SPLIT_ROLE_CENTRAL)
Expand Down
8 changes: 7 additions & 1 deletion app/src/display/widgets/battery_status.c
Expand Up @@ -27,7 +27,7 @@ struct battery_status_state {
};

static void set_battery_symbol(lv_obj_t *label, struct battery_status_state state) {
char text[8] = {};
char text[9] = {};

uint8_t level = state.level;

Expand All @@ -37,6 +37,11 @@ static void set_battery_symbol(lv_obj_t *label, struct battery_status_state stat
}
#endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */

#if IS_ENABLED(CONFIG_ZMK_WIDGET_BATTERY_STATUS_SHOW_PERCENTAGE)
char perc[5] = {};
snprintf(perc, sizeof(perc), "%3u%%", level);
strcat(text, perc);
#else
if (level > 95) {
strcat(text, LV_SYMBOL_BATTERY_FULL);
} else if (level > 65) {
Expand All @@ -48,6 +53,7 @@ static void set_battery_symbol(lv_obj_t *label, struct battery_status_state stat
} else {
strcat(text, LV_SYMBOL_BATTERY_EMPTY);
}
#endif
lv_label_set_text(label, text);
lv_obj_align(label, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
}
Expand Down

0 comments on commit 58eb7a3

Please sign in to comment.