Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Battery percentage widget for nice!view vertical layout #2000

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/boards/shields/nice_view/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ 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_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"

Expand Down
4 changes: 4 additions & 0 deletions app/boards/shields/nice_view/widgets/peripheral_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions app/boards/shields/nice_view/widgets/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions app/boards/shields/nice_view/widgets/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ 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);
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);
Expand All @@ -41,6 +61,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,
Expand Down