From 85379b359cc0ffac0b113fd53bd2dbac8660c9a6 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 28 Aug 2023 15:01:09 +1000 Subject: Add some cool battery icons --- src/ui/CMakeLists.txt | 2 ++ src/ui/icons/battery_20.c | 52 ++++++++++++++++++++++++++++++++++++++ src/ui/icons/battery_40.c | 52 ++++++++++++++++++++++++++++++++++++++ src/ui/icons/battery_60.c | 52 ++++++++++++++++++++++++++++++++++++++ src/ui/icons/battery_80.c | 52 ++++++++++++++++++++++++++++++++++++++ src/ui/icons/battery_empty.c | 52 ++++++++++++++++++++++++++++++++++++++ src/ui/icons/battery_full.c | 52 ++++++++++++++++++++++++++++++++++++++ src/ui/widget_top_bar.cpp | 37 +++++++++++++++++---------- tools/fonts/mkfonts.sh | 23 +++++++++++++++++ tools/icons/raw/battery_20.png | Bin 0 -> 617 bytes tools/icons/raw/battery_40.png | Bin 0 -> 617 bytes tools/icons/raw/battery_60.png | Bin 0 -> 618 bytes tools/icons/raw/battery_80.png | Bin 0 -> 622 bytes tools/icons/raw/battery_empty.png | Bin 0 -> 614 bytes tools/icons/raw/battery_full.png | Bin 0 -> 618 bytes tools/mkfonts.sh | 23 ----------------- 16 files changed, 360 insertions(+), 37 deletions(-) create mode 100644 src/ui/icons/battery_20.c create mode 100644 src/ui/icons/battery_40.c create mode 100644 src/ui/icons/battery_60.c create mode 100644 src/ui/icons/battery_80.c create mode 100644 src/ui/icons/battery_empty.c create mode 100644 src/ui/icons/battery_full.c create mode 100755 tools/fonts/mkfonts.sh create mode 100644 tools/icons/raw/battery_20.png create mode 100644 tools/icons/raw/battery_40.png create mode 100644 tools/icons/raw/battery_60.png create mode 100644 tools/icons/raw/battery_80.png create mode 100644 tools/icons/raw/battery_empty.png create mode 100644 tools/icons/raw/battery_full.png delete mode 100755 tools/mkfonts.sh diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 6b5c393a..af261412 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -8,6 +8,8 @@ idf_component_register( "themes.cpp" "widget_top_bar.cpp" "screen.cpp" "screen_onboarding.cpp" "modal_progress.cpp" "modal.cpp" "modal_confirm.cpp" "screen_settings.cpp" "splash.c" "font_fusion.c" "font_symbols.c" + "icons/battery_empty.c" "icons/battery_full.c" "icons/battery_20.c" + "icons/battery_40.c" "icons/battery_60.c" "icons/battery_80.c" INCLUDE_DIRS "include" REQUIRES "drivers" "lvgl" "tinyfsm" "events" "system_fsm" "database" "esp_timer" "battery") target_compile_options(${COMPONENT_LIB} PRIVATE ${EXTRA_WARNINGS}) diff --git a/src/ui/icons/battery_20.c b/src/ui/icons/battery_20.c new file mode 100644 index 00000000..0ae909b9 --- /dev/null +++ b/src/ui/icons/battery_20.c @@ -0,0 +1,52 @@ +#ifdef __has_include + #if __has_include("lvgl.h") + #ifndef LV_LVGL_H_INCLUDE_SIMPLE + #define LV_LVGL_H_INCLUDE_SIMPLE + #endif + #endif +#endif + +#if defined(LV_LVGL_H_INCLUDE_SIMPLE) + #include "lvgl.h" +#else + #include "lvgl/lvgl.h" +#endif + + +#ifndef LV_ATTRIBUTE_MEM_ALIGN +#define LV_ATTRIBUTE_MEM_ALIGN +#endif + +#ifndef LV_ATTRIBUTE_IMG_BATTERY_20 +#define LV_ATTRIBUTE_IMG_BATTERY_20 +#endif + +const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_BATTERY_20 uint8_t battery_20_map[] = { + 0x00, 0x00, 0x00, 0xff, /*Color of index 0*/ + 0xfd, 0xfe, 0xfd, 0xff, /*Color of index 1*/ + 0x26, 0xc1, 0x38, 0xff, /*Color of index 2*/ + 0x01, 0xbe, 0x37, 0xff, /*Color of index 3*/ + + 0x55, 0x00, 0x55, + 0x54, 0x00, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xff, 0x15, + 0x54, 0x00, 0x15, +}; + +const lv_img_dsc_t battery_20 = { + .header.cf = LV_IMG_CF_INDEXED_2BIT, + .header.always_zero = 0, + .header.reserved = 0, + .header.w = 12, + .header.h = 12, + .data_size = 52, + .data = battery_20_map, +}; diff --git a/src/ui/icons/battery_40.c b/src/ui/icons/battery_40.c new file mode 100644 index 00000000..07310273 --- /dev/null +++ b/src/ui/icons/battery_40.c @@ -0,0 +1,52 @@ +#ifdef __has_include + #if __has_include("lvgl.h") + #ifndef LV_LVGL_H_INCLUDE_SIMPLE + #define LV_LVGL_H_INCLUDE_SIMPLE + #endif + #endif +#endif + +#if defined(LV_LVGL_H_INCLUDE_SIMPLE) + #include "lvgl.h" +#else + #include "lvgl/lvgl.h" +#endif + + +#ifndef LV_ATTRIBUTE_MEM_ALIGN +#define LV_ATTRIBUTE_MEM_ALIGN +#endif + +#ifndef LV_ATTRIBUTE_IMG_BATTERY_40 +#define LV_ATTRIBUTE_IMG_BATTERY_40 +#endif + +const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_BATTERY_40 uint8_t battery_40_map[] = { + 0x00, 0x00, 0x00, 0xff, /*Color of index 0*/ + 0xfd, 0xfe, 0xfd, 0xff, /*Color of index 1*/ + 0x26, 0xc1, 0x38, 0xff, /*Color of index 2*/ + 0x01, 0xbe, 0x37, 0xff, /*Color of index 3*/ + + 0x55, 0x00, 0x55, + 0x54, 0x00, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xff, 0x15, + 0x54, 0xff, 0x15, + 0x54, 0x00, 0x15, +}; + +const lv_img_dsc_t battery_40 = { + .header.cf = LV_IMG_CF_INDEXED_2BIT, + .header.always_zero = 0, + .header.reserved = 0, + .header.w = 12, + .header.h = 12, + .data_size = 52, + .data = battery_40_map, +}; diff --git a/src/ui/icons/battery_60.c b/src/ui/icons/battery_60.c new file mode 100644 index 00000000..ac7db567 --- /dev/null +++ b/src/ui/icons/battery_60.c @@ -0,0 +1,52 @@ +#ifdef __has_include + #if __has_include("lvgl.h") + #ifndef LV_LVGL_H_INCLUDE_SIMPLE + #define LV_LVGL_H_INCLUDE_SIMPLE + #endif + #endif +#endif + +#if defined(LV_LVGL_H_INCLUDE_SIMPLE) + #include "lvgl.h" +#else + #include "lvgl/lvgl.h" +#endif + + +#ifndef LV_ATTRIBUTE_MEM_ALIGN +#define LV_ATTRIBUTE_MEM_ALIGN +#endif + +#ifndef LV_ATTRIBUTE_IMG_BATTERY_60 +#define LV_ATTRIBUTE_IMG_BATTERY_60 +#endif + +const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_BATTERY_60 uint8_t battery_60_map[] = { + 0x00, 0x00, 0x00, 0xff, /*Color of index 0*/ + 0xfd, 0xfe, 0xfd, 0xff, /*Color of index 1*/ + 0x26, 0xc1, 0x38, 0xff, /*Color of index 2*/ + 0x01, 0xbe, 0x37, 0xff, /*Color of index 3*/ + + 0x55, 0x00, 0x55, + 0x54, 0x00, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xff, 0x15, + 0x54, 0xff, 0x15, + 0x54, 0x00, 0x15, +}; + +const lv_img_dsc_t battery_60 = { + .header.cf = LV_IMG_CF_INDEXED_2BIT, + .header.always_zero = 0, + .header.reserved = 0, + .header.w = 12, + .header.h = 12, + .data_size = 52, + .data = battery_60_map, +}; diff --git a/src/ui/icons/battery_80.c b/src/ui/icons/battery_80.c new file mode 100644 index 00000000..086c0708 --- /dev/null +++ b/src/ui/icons/battery_80.c @@ -0,0 +1,52 @@ +#ifdef __has_include + #if __has_include("lvgl.h") + #ifndef LV_LVGL_H_INCLUDE_SIMPLE + #define LV_LVGL_H_INCLUDE_SIMPLE + #endif + #endif +#endif + +#if defined(LV_LVGL_H_INCLUDE_SIMPLE) + #include "lvgl.h" +#else + #include "lvgl/lvgl.h" +#endif + + +#ifndef LV_ATTRIBUTE_MEM_ALIGN +#define LV_ATTRIBUTE_MEM_ALIGN +#endif + +#ifndef LV_ATTRIBUTE_IMG_BATTERY_80 +#define LV_ATTRIBUTE_IMG_BATTERY_80 +#endif + +const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_BATTERY_80 uint8_t battery_80_map[] = { + 0x00, 0x00, 0x00, 0xff, /*Color of index 0*/ + 0xfd, 0xfe, 0xfd, 0xff, /*Color of index 1*/ + 0x26, 0xc1, 0x38, 0xff, /*Color of index 2*/ + 0x01, 0xbe, 0x37, 0xff, /*Color of index 3*/ + + 0x55, 0x00, 0x55, + 0x54, 0x00, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0x55, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xff, 0x15, + 0x54, 0xff, 0x15, + 0x54, 0x00, 0x15, +}; + +const lv_img_dsc_t battery_80 = { + .header.cf = LV_IMG_CF_INDEXED_2BIT, + .header.always_zero = 0, + .header.reserved = 0, + .header.w = 12, + .header.h = 12, + .data_size = 52, + .data = battery_80_map, +}; diff --git a/src/ui/icons/battery_empty.c b/src/ui/icons/battery_empty.c new file mode 100644 index 00000000..ed356167 --- /dev/null +++ b/src/ui/icons/battery_empty.c @@ -0,0 +1,52 @@ +#ifdef __has_include + #if __has_include("lvgl.h") + #ifndef LV_LVGL_H_INCLUDE_SIMPLE + #define LV_LVGL_H_INCLUDE_SIMPLE + #endif + #endif +#endif + +#if defined(LV_LVGL_H_INCLUDE_SIMPLE) + #include "lvgl.h" +#else + #include "lvgl/lvgl.h" +#endif + + +#ifndef LV_ATTRIBUTE_MEM_ALIGN +#define LV_ATTRIBUTE_MEM_ALIGN +#endif + +#ifndef LV_ATTRIBUTE_IMG_BATTERY_EMPTY +#define LV_ATTRIBUTE_IMG_BATTERY_EMPTY +#endif + +const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_BATTERY_EMPTY uint8_t battery_empty_map[] = { + 0xfd, 0xfd, 0xfd, 0xff, /*Color of index 0*/ + 0x00, 0x00, 0x00, 0xff, /*Color of index 1*/ + 0x26, 0x2c, 0xfa, 0xff, /*Color of index 2*/ + 0x00, 0x00, 0x00, 0x00, /*Color of index 3*/ + + 0x00, 0x55, 0x00, + 0x01, 0x55, 0x40, + 0x01, 0x00, 0x40, + 0x01, 0x00, 0x40, + 0x01, 0x00, 0x40, + 0x01, 0x00, 0x40, + 0x01, 0x00, 0x40, + 0x01, 0x00, 0x40, + 0x01, 0x00, 0x40, + 0x01, 0xaa, 0x40, + 0x01, 0xaa, 0x40, + 0x01, 0x55, 0x40, +}; + +const lv_img_dsc_t battery_empty = { + .header.cf = LV_IMG_CF_INDEXED_2BIT, + .header.always_zero = 0, + .header.reserved = 0, + .header.w = 12, + .header.h = 12, + .data_size = 52, + .data = battery_empty_map, +}; diff --git a/src/ui/icons/battery_full.c b/src/ui/icons/battery_full.c new file mode 100644 index 00000000..fffd5a73 --- /dev/null +++ b/src/ui/icons/battery_full.c @@ -0,0 +1,52 @@ +#ifdef __has_include + #if __has_include("lvgl.h") + #ifndef LV_LVGL_H_INCLUDE_SIMPLE + #define LV_LVGL_H_INCLUDE_SIMPLE + #endif + #endif +#endif + +#if defined(LV_LVGL_H_INCLUDE_SIMPLE) + #include "lvgl.h" +#else + #include "lvgl/lvgl.h" +#endif + + +#ifndef LV_ATTRIBUTE_MEM_ALIGN +#define LV_ATTRIBUTE_MEM_ALIGN +#endif + +#ifndef LV_ATTRIBUTE_IMG_BATTERY_FULL +#define LV_ATTRIBUTE_IMG_BATTERY_FULL +#endif + +const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_BATTERY_FULL uint8_t battery_full_map[] = { + 0x00, 0x00, 0x00, 0xff, /*Color of index 0*/ + 0xfd, 0xfe, 0xfd, 0xff, /*Color of index 1*/ + 0x26, 0xc1, 0x38, 0xff, /*Color of index 2*/ + 0x01, 0xbe, 0x37, 0xff, /*Color of index 3*/ + + 0x55, 0x00, 0x55, + 0x54, 0x00, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xaa, 0x15, + 0x54, 0xff, 0x15, + 0x54, 0xff, 0x15, + 0x54, 0x00, 0x15, +}; + +const lv_img_dsc_t battery_full = { + .header.cf = LV_IMG_CF_INDEXED_2BIT, + .header.always_zero = 0, + .header.reserved = 0, + .header.w = 12, + .header.h = 12, + .data_size = 52, + .data = battery_full_map, +}; diff --git a/src/ui/widget_top_bar.cpp b/src/ui/widget_top_bar.cpp index 851b617f..c5c3d88b 100644 --- a/src/ui/widget_top_bar.cpp +++ b/src/ui/widget_top_bar.cpp @@ -16,6 +16,13 @@ #include "widgets/lv_img.h" #include "widgets/lv_label.h" +LV_IMG_DECLARE(battery_empty); +LV_IMG_DECLARE(battery_20); +LV_IMG_DECLARE(battery_40); +LV_IMG_DECLARE(battery_60); +LV_IMG_DECLARE(battery_80); +LV_IMG_DECLARE(battery_full); + namespace ui { namespace widgets { @@ -48,8 +55,7 @@ TopBar::TopBar(lv_obj_t* parent, const Configuration& config) { playback_ = lv_label_create(container_); lv_label_set_text(playback_, ""); - battery_ = lv_label_create(container_); - lv_label_set_text(battery_, ""); + battery_ = lv_img_create(container_); } auto TopBar::Update(const State& state) -> void { @@ -65,18 +71,21 @@ auto TopBar::Update(const State& state) -> void { break; } - lv_label_set_text(battery_, std::to_string(state.battery_percent).c_str()); - // if (state.battery_percent >= 95) { - // lv_label_set_text(battery_, "100"); - // } else if (state.battery_percent >= 70) { - // lv_label_set_text(battery_, ">70"); - // } else if (state.battery_percent >= 40) { - // lv_label_set_text(battery_, ">40"); - // } else if (state.battery_percent >= 10) { - // lv_label_set_text(battery_, ">10"); - // } else { - // lv_label_set_text(battery_, "0"); - // } + if (state.battery_percent >= 95) { + lv_img_set_src(battery_, &battery_full); + } else if (state.battery_percent >= 75) { + lv_img_set_src(battery_, &battery_80); + lv_label_set_text(battery_, ">70"); + } else if (state.battery_percent >= 55) { + lv_img_set_src(battery_, &battery_60); + lv_label_set_text(battery_, ">40"); + } else if (state.battery_percent >= 35) { + lv_img_set_src(battery_, &battery_40); + } else if (state.battery_percent >= 15) { + lv_img_set_src(battery_, &battery_20); + } else { + lv_img_set_src(battery_, &battery_empty); + } } } // namespace widgets diff --git a/tools/fonts/mkfonts.sh b/tools/fonts/mkfonts.sh new file mode 100755 index 00000000..7888512a --- /dev/null +++ b/tools/fonts/mkfonts.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# To install this tool: +# npm i lv_font_conv -g +lv_font_conv \ + --font fonts/fusion/fusion-pixel-12px-proportional.ttf \ + -r 0x2000-0x206F \ + -r 0x20-0x7F,0xA0-0xFF \ + -r 0x3000-0x303f,0x3040-0x309F,0x30A0-0x30FF,0xFF00-0xFFEF,0x4E00-0x9FAF \ + --size 12 \ + --bpp 1 --format lvgl -o font_fusion.c + +lv_font_conv \ + --font fonts/font-awesome/FontAwesome5-Solid+Brands+Regular.woff \ + -r 0xf244,0xf243,0xf242,0xf241,0xf240 `# battery indicators, empty->full` \ + -r 0xf104,0xf0d7 \ + -r 61441,61448,61451,61452,61452,61453,61457,61459,61461,61465 \ + -r 61468,61473,61478,61479,61480,61502,61512,61515,61516,61517 \ + -r 61521,61522,61523,61524,61543,61544,61550,61552,61553,61556 \ + -r 61559,61560,61561,61563,61587,61589,61636,61637,61639,61671 \ + -r 61674,61683,61724,61732,61787,61931,62016,62017,62018,62019 \ + -r 62020,62087,62099,62212,62189,62810,63426,63650 \ + --size 12 \ + --bpp 1 --format lvgl -o font_symbols.c diff --git a/tools/icons/raw/battery_20.png b/tools/icons/raw/battery_20.png new file mode 100644 index 00000000..9012376f Binary files /dev/null and b/tools/icons/raw/battery_20.png differ diff --git a/tools/icons/raw/battery_40.png b/tools/icons/raw/battery_40.png new file mode 100644 index 00000000..88a0b448 Binary files /dev/null and b/tools/icons/raw/battery_40.png differ diff --git a/tools/icons/raw/battery_60.png b/tools/icons/raw/battery_60.png new file mode 100644 index 00000000..d86c997a Binary files /dev/null and b/tools/icons/raw/battery_60.png differ diff --git a/tools/icons/raw/battery_80.png b/tools/icons/raw/battery_80.png new file mode 100644 index 00000000..344b3703 Binary files /dev/null and b/tools/icons/raw/battery_80.png differ diff --git a/tools/icons/raw/battery_empty.png b/tools/icons/raw/battery_empty.png new file mode 100644 index 00000000..c9176e8c Binary files /dev/null and b/tools/icons/raw/battery_empty.png differ diff --git a/tools/icons/raw/battery_full.png b/tools/icons/raw/battery_full.png new file mode 100644 index 00000000..57122a23 Binary files /dev/null and b/tools/icons/raw/battery_full.png differ diff --git a/tools/mkfonts.sh b/tools/mkfonts.sh deleted file mode 100755 index 7888512a..00000000 --- a/tools/mkfonts.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh -# To install this tool: -# npm i lv_font_conv -g -lv_font_conv \ - --font fonts/fusion/fusion-pixel-12px-proportional.ttf \ - -r 0x2000-0x206F \ - -r 0x20-0x7F,0xA0-0xFF \ - -r 0x3000-0x303f,0x3040-0x309F,0x30A0-0x30FF,0xFF00-0xFFEF,0x4E00-0x9FAF \ - --size 12 \ - --bpp 1 --format lvgl -o font_fusion.c - -lv_font_conv \ - --font fonts/font-awesome/FontAwesome5-Solid+Brands+Regular.woff \ - -r 0xf244,0xf243,0xf242,0xf241,0xf240 `# battery indicators, empty->full` \ - -r 0xf104,0xf0d7 \ - -r 61441,61448,61451,61452,61452,61453,61457,61459,61461,61465 \ - -r 61468,61473,61478,61479,61480,61502,61512,61515,61516,61517 \ - -r 61521,61522,61523,61524,61543,61544,61550,61552,61553,61556 \ - -r 61559,61560,61561,61563,61587,61589,61636,61637,61639,61671 \ - -r 61674,61683,61724,61732,61787,61931,62016,62017,62018,62019 \ - -r 62020,62087,62099,62212,62189,62810,63426,63650 \ - --size 12 \ - --bpp 1 --format lvgl -o font_symbols.c -- cgit v1.2.3