From fe73b637c337720f3e7398760acd27118e38fa6b Mon Sep 17 00:00:00 2001 From: Rory Hayes Date: Sat, 14 Jul 2018 21:43:09 -0700 Subject: [PATCH] add battery icon to powerbutton menu --- 8bkc-components/gui-util/8bkcgui-widgets.c | 18 ++++++++++++++++++ 8bkc-components/gui-util/8bkcgui-widgets.h | 7 +++++++ 8bkc-components/powerbtn_menu/powerbtn_menu.c | 4 ++++ 3 files changed, 29 insertions(+) diff --git a/8bkc-components/gui-util/8bkcgui-widgets.c b/8bkc-components/gui-util/8bkcgui-widgets.c index 8d35cf5..b7c0d26 100644 --- a/8bkc-components/gui-util/8bkcgui-widgets.c +++ b/8bkc-components/gui-util/8bkcgui-widgets.c @@ -267,4 +267,22 @@ int kcugui_menu(kcugui_menuitem_t *menu, char *desc, kcugui_menu_cb_t cb, void * oldkeys=keys; } while (prKeys==0); } +} + +void kcugui_drawBatteryIcon() { + // draw outer battery frame and fill it with black + UG_DrawFrame(KC_SCREEN_W-17, 0, KC_SCREEN_W-3, 6, C_WHITE); + UG_FillFrame(KC_SCREEN_W-16, 1, KC_SCREEN_W-4, 5, C_BLACK); + // draw the positive contact + UG_DrawFrame(KC_SCREEN_W-2, 2, KC_SCREEN_W-1, 4, C_WHITE); + + // collect battery info and select appropriate filler color + int b = kchal_get_bat_pct(); + UG_COLOR batColor; + if (b < 20) batColor = C_RED; + else if (b < 50) batColor = C_GOLD; + else batColor = C_LIME; + + // fill in battery, relative to battery SOC + UG_FillFrame(KC_SCREEN_W-16, 1, KC_SCREEN_W-4-(((100-b)*12)/100), 5, batColor); } \ No newline at end of file diff --git a/8bkc-components/gui-util/8bkcgui-widgets.h b/8bkc-components/gui-util/8bkcgui-widgets.h index 7c58246..424be69 100644 --- a/8bkc-components/gui-util/8bkcgui-widgets.h +++ b/8bkc-components/gui-util/8bkcgui-widgets.h @@ -137,6 +137,13 @@ typedef int (*kcugui_menu_cb_t)(int button, char **desc, kcugui_menuitem_t **men */ int kcugui_menu(kcugui_menuitem_t *menu, char *desc, kcugui_menu_cb_t cb, void *usrptr); +/** + * @brief Draws battery state-of-charge icon + * + * Shows a small battery icon in the top-right, indicate the current battery remaining. + */ +void kcugui_drawBatteryIcon(); + #ifdef __cplusplus } #endif diff --git a/8bkc-components/powerbtn_menu/powerbtn_menu.c b/8bkc-components/powerbtn_menu/powerbtn_menu.c index f5c9d13..99bd903 100644 --- a/8bkc-components/powerbtn_menu/powerbtn_menu.c +++ b/8bkc-components/powerbtn_menu/powerbtn_menu.c @@ -2,6 +2,8 @@ #include #include #include "8bkc-hal.h" +#include "ugui.h" +#include "8bkcgui-widgets.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -172,6 +174,8 @@ int powerbtn_menu_show(uint16_t *fb) { renderGfx(fb, 14, 25+16, 14, 130, (v*60)/256, 4); } + kcugui_drawBatteryIcon(); + if (doRefresh) { kchal_send_fb(fb); }