From 3987236c09b69191975787c8bb3bec54609752ea Mon Sep 17 00:00:00 2001 From: Pawel Bogut Date: Sat, 11 Nov 2023 21:33:08 +0100 Subject: [PATCH] feat(nice_view): Show big battery percentage instead of WPM widget --- app/boards/shields/nice_view/Kconfig.defconfig | 4 ++++ app/boards/shields/nice_view/widgets/peripheral_status.c | 4 ++++ app/boards/shields/nice_view/widgets/status.c | 2 ++ app/boards/shields/nice_view/widgets/util.c | 8 ++++++++ 4 files changed, 18 insertions(+) diff --git a/app/boards/shields/nice_view/Kconfig.defconfig b/app/boards/shields/nice_view/Kconfig.defconfig index d8e7cb0d..6d7d06c8 100644 --- a/app/boards/shields/nice_view/Kconfig.defconfig +++ b/app/boards/shields/nice_view/Kconfig.defconfig @@ -36,6 +36,10 @@ config NICE_VIEW_WIDGET_STATUS config NICE_VIEW_BATTERY_SHOW_PERCENTAGE bool "Show battery percentage instead of icon" +config NICE_VIEW_BATTERY_SHOW_BIG_PERCENTAGE + bool "Show battery percentage instead of WPM widget" + select LV_FONT_MONTSERRAT_26 + config NICE_VIEW_WIDGET_INVERTED bool "Invert custom status widget colors" diff --git a/app/boards/shields/nice_view/widgets/peripheral_status.c b/app/boards/shields/nice_view/widgets/peripheral_status.c index 4c0c2263..94d470fb 100644 --- a/app/boards/shields/nice_view/widgets/peripheral_status.c +++ b/app/boards/shields/nice_view/widgets/peripheral_status.c @@ -116,7 +116,11 @@ int zmk_widget_status_init(struct zmk_widget_status *widget, lv_obj_t *parent) { lv_obj_t *art = lv_img_create(widget->obj); bool random = sys_rand32_get() & 1; lv_img_set_src(art, random ? &balloon : &mountain); +#if IS_ENABLED(CONFIG_NICE_VIEW_BATTERY_SHOW_BIG_PERCENTAGE) + lv_obj_align(art, LV_ALIGN_TOP_LEFT, -48, 0); +#else lv_obj_align(art, LV_ALIGN_TOP_LEFT, 0, 0); +#endif sys_slist_append(&widgets, &widget->node); widget_battery_status_init(); diff --git a/app/boards/shields/nice_view/widgets/status.c b/app/boards/shields/nice_view/widgets/status.c index 453fd650..f2d90797 100644 --- a/app/boards/shields/nice_view/widgets/status.c +++ b/app/boards/shields/nice_view/widgets/status.c @@ -86,6 +86,7 @@ static void draw_top(lv_obj_t *widget, lv_color_t cbuf[], const struct status_st lv_canvas_draw_text(canvas, 0, 0, CANVAS_SIZE, &label_dsc, output_text); +#if !IS_ENABLED(CONFIG_NICE_VIEW_BATTERY_SHOW_BIG_PERCENTAGE) // Draw WPM lv_canvas_draw_rect(canvas, 0, 21, 68, 42, &rect_white_dsc); lv_canvas_draw_rect(canvas, 1, 22, 66, 40, &rect_black_dsc); @@ -117,6 +118,7 @@ static void draw_top(lv_obj_t *widget, lv_color_t cbuf[], const struct status_st points[i].y = 60 - (state->wpm[i] - min) * 36 / range; } lv_canvas_draw_line(canvas, points, 10, &line_dsc); +#endif // Rotate canvas rotate_canvas(canvas, cbuf); diff --git a/app/boards/shields/nice_view/widgets/util.c b/app/boards/shields/nice_view/widgets/util.c index c324b10c..a553836f 100644 --- a/app/boards/shields/nice_view/widgets/util.c +++ b/app/boards/shields/nice_view/widgets/util.c @@ -30,6 +30,14 @@ void draw_battery(lv_obj_t *canvas, const struct status_state *state) { lv_draw_rect_dsc_t rect_white_dsc; init_rect_dsc(&rect_white_dsc, LVGL_FOREGROUND); +#if IS_ENABLED(CONFIG_NICE_VIEW_BATTERY_SHOW_BIG_PERCENTAGE) + char big_text[4] = {}; + sprintf(big_text, "%i%%", state->battery); + lv_draw_label_dsc_t big_label_dsc; + init_label_dsc(&big_label_dsc, LVGL_FOREGROUND, &lv_font_montserrat_26, LV_TEXT_ALIGN_CENTER); + lv_canvas_draw_text(canvas, 0, 25, 68, &big_label_dsc, big_text); +#endif + #if IS_ENABLED(CONFIG_NICE_VIEW_BATTERY_SHOW_PERCENTAGE) char text[4] = {}; sprintf(text, "%i%%", state->battery);