From 300e1d2630d3d5b1591a75f5dad885f8686867d3 Mon Sep 17 00:00:00 2001 From: Pawel Bogut Date: Sat, 11 Nov 2023 21:30:55 +0100 Subject: [PATCH 1/2] feat(nice_view): Add option to show battery percentage on vertical view --- app/boards/shields/nice_view/Kconfig.defconfig | 3 +++ app/boards/shields/nice_view/widgets/util.c | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/boards/shields/nice_view/Kconfig.defconfig b/app/boards/shields/nice_view/Kconfig.defconfig index 53edc1cc..d8e7cb0d 100644 --- a/app/boards/shields/nice_view/Kconfig.defconfig +++ b/app/boards/shields/nice_view/Kconfig.defconfig @@ -33,6 +33,9 @@ config NICE_VIEW_WIDGET_STATUS select LV_USE_IMG select LV_USE_CANVAS +config NICE_VIEW_BATTERY_SHOW_PERCENTAGE + bool "Show battery percentage instead of icon" + config NICE_VIEW_WIDGET_INVERTED bool "Invert custom status widget colors" diff --git a/app/boards/shields/nice_view/widgets/util.c b/app/boards/shields/nice_view/widgets/util.c index b4915ab7..c324b10c 100644 --- a/app/boards/shields/nice_view/widgets/util.c +++ b/app/boards/shields/nice_view/widgets/util.c @@ -30,6 +30,18 @@ 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_PERCENTAGE) + char text[4] = {}; + sprintf(text, "%i%%", state->battery); + lv_draw_label_dsc_t label_dsc; + init_label_dsc(&label_dsc, LVGL_FOREGROUND, &lv_font_montserrat_16, LV_TEXT_ALIGN_CENTER); + lv_canvas_draw_text(canvas, 0, 5, 68, &label_dsc, text); + if (state->charging) { + lv_draw_img_dsc_t img_dsc; + lv_draw_img_dsc_init(&img_dsc); + lv_canvas_draw_img(canvas, 1, -1, &bolt, &img_dsc); + } +#else lv_canvas_draw_rect(canvas, 0, 2, 29, 12, &rect_white_dsc); lv_canvas_draw_rect(canvas, 1, 3, 27, 10, &rect_black_dsc); lv_canvas_draw_rect(canvas, 2, 4, (state->battery + 2) / 4, 8, &rect_white_dsc); @@ -41,6 +53,7 @@ void draw_battery(lv_obj_t *canvas, const struct status_state *state) { lv_draw_img_dsc_init(&img_dsc); lv_canvas_draw_img(canvas, 9, -1, &bolt, &img_dsc); } +#endif } void init_label_dsc(lv_draw_label_dsc_t *label_dsc, lv_color_t color, const lv_font_t *font, From 3987236c09b69191975787c8bb3bec54609752ea Mon Sep 17 00:00:00 2001 From: Pawel Bogut Date: Sat, 11 Nov 2023 21:33:08 +0100 Subject: [PATCH 2/2] 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);