From a8ed0c37f12137db25ab6e60d2745132cd0d7563 Mon Sep 17 00:00:00 2001 From: "Andrew J.Swan" Date: Thu, 12 Oct 2023 14:42:22 +0300 Subject: [PATCH 1/2] 2023.9.1-91: Add set_progressbar_color --- components/ehmtxv2/EHMTX.cpp | 14 +++++++++++++- components/ehmtxv2/EHMTX.h | 4 ++++ components/ehmtxv2/EHMTX_queue.cpp | 12 +++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index 8250a2b3..c6b4c31b 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -438,6 +438,7 @@ namespace esphome #endif register_service(&EHMTX::icon_screen_progress, "icon_screen_progress", {"icon_name", "text", "progress", "lifetime", "screen_time", "default_font", "r", "g", "b"}); + register_service(&EHMTX::set_progressbar_color, "set_progressbar_color", {"icon_name", "r", "g", "b", "bg_r", "bg_g", "bg_b"}); ESP_LOGD(TAG, "Setup and running!"); } @@ -491,7 +492,7 @@ namespace esphome this->info_rcolor = Color((uint8_t)rr, (uint8_t)rg, (uint8_t)rb); this->info_font = df; this->info_y_offset = y_offset; - ESP_LOGD(TAG, "info text color left: r: %d g: %d b: %d right: r: %d g: %d b: %d y_offset %d", lr, lg, lb, rr, rg, rb,y_offset); + ESP_LOGD(TAG, "info text color left: r: %d g: %d b: %d right: r: %d g: %d b: %d y_offset %d", lr, lg, lb, rr, rg, rb, y_offset); } void EHMTX::update() // called from polling component @@ -1047,6 +1048,17 @@ namespace esphome screen->status(); } + void EHMTX::set_progressbar_color(std::string iconname, int r, int g, int b, int bg_r, int bg_g, int bg_b) + { + EHMTX_queue *screen = this->find_mode_icon_queue_element(MODE_ICON_PROGRESS, get_screen_id(iconname)); + + screen->progressbar_color = (r + g + b == C_BLACK) ? esphome::display::COLOR_OFF : Color((uint8_t)r, (uint8_t)g, (uint8_t)b); + screen->progressbar_back_color = (bg_r + bg_g + bg_b == C_BLACK) ? esphome::display::COLOR_OFF : Color((uint8_t)bg_r, (uint8_t)bg_g, (uint8_t)bg_b); + + ESP_LOGD(TAG, "icon progress screen iconname: %s color progressbar: r: %d g: %d b: %d background: r: %d g: %d b: %d", iconname.c_str(), r, g, b, bg_r, bg_g, bg_b); + screen->status(); + } + void EHMTX::icon_clock(std::string iconname, int lifetime, int screen_time, bool default_font, int r, int g, int b) { std::string ic = get_icon_name(iconname); diff --git a/components/ehmtxv2/EHMTX.h b/components/ehmtxv2/EHMTX.h index b65e695d..b3364919 100644 --- a/components/ehmtxv2/EHMTX.h +++ b/components/ehmtxv2/EHMTX.h @@ -15,6 +15,7 @@ const uint8_t CA_RED = 200; // alarm const uint8_t CA_BLUE = 50; const uint8_t CA_GREEN = 50; const uint8_t CG_GREY = 50; +const uint8_t C_BLACK = 0; const uint8_t D_LIFETIME = 5; const uint8_t D_SCREEN_TIME = 10; @@ -201,6 +202,7 @@ namespace esphome void blank_screen(int lifetime = D_LIFETIME, int screen_time = D_SCREEN_TIME); void color_screen(int lifetime = D_LIFETIME, int screen_time = D_SCREEN_TIME, int r = C_RED, int g = C_GREEN, int b = C_BLUE); void icon_screen_progress(std::string icon, std::string text, int progress, int lifetime = D_LIFETIME, int screen_time = D_SCREEN_TIME, bool default_font = true, int r = C_RED, int g = C_GREEN, int b = C_BLUE); + void set_progressbar_color(std::string icon, int r = C_BLACK, int g = C_BLACK, int b = C_BLACK, int bg_r = C_BLACK, int bg_g = C_BLACK, int bg_b = C_BLACK); void bitmap_screen(std::string text, int lifetime = D_LIFETIME, int screen_time = D_SCREEN_TIME); void color_gauge(std::string text); @@ -257,6 +259,8 @@ namespace esphome uint8_t icon; uint16_t scroll_reset; Color text_color; + Color progressbar_color; + Color progressbar_back_color; show_mode mode; int8_t progress; diff --git a/components/ehmtxv2/EHMTX_queue.cpp b/components/ehmtxv2/EHMTX_queue.cpp index cc06e61a..14f50e01 100644 --- a/components/ehmtxv2/EHMTX_queue.cpp +++ b/components/ehmtxv2/EHMTX_queue.cpp @@ -79,6 +79,8 @@ namespace esphome this->text = ""; this->default_font = true; this->progress = 0; + this->progressbar_color = esphome::display::COLOR_OFF; + this->progressbar_back_color = esphome::display::COLOR_OFF; } void EHMTX_queue::status() @@ -538,7 +540,15 @@ namespace esphome if (this->progress != 0) { - color_ = esphome::light::ESPHSVColor(this->progress * 120 / 100 + (this->progress < 0 ? 120 : 0), 255, 240).to_rgb(); + if (this->progressbar_color == esphome::display::COLOR_OFF) + { + color_ = esphome::light::ESPHSVColor(this->progress * 120 / 100 + (this->progress < 0 ? 120 : 0), 255, 240).to_rgb(); + } + else + { + color_ = this->progressbar_color; + this->config_->display->line(9, 7, 31, 7, this->progressbar_back_color); + } this->config_->display->line(9, 7, 9 + abs(this->progress) * 22 / 100, 7, color_); } } From 5e6cd02f12782b3b202cec5f3aa0e93179bddf62 Mon Sep 17 00:00:00 2001 From: "Andrew J.Swan" Date: Thu, 12 Oct 2023 14:48:26 +0300 Subject: [PATCH 2/2] 2023.9.1-91: Add set_progressbar_color to Readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d3c825a..f7b288c3 100644 --- a/README.md +++ b/README.md @@ -755,6 +755,7 @@ Numerous features are accessible with services from home assistant and lambdas t |`brightness`|"value"|set the display brightness| |`alert_screen`|"icon_name", "text", "screen_time", "default_font", "r", "g", "b"|show the specified icon with text, screen forced and lifetime = screen_time| |`icon_screen_progress`|"icon_name", "text", "progress", "lifetime", "screen_time", "default_font", "r", "g", "b"|show the specified icon with text and with progress bar on bottom| +|`set_progressbar_color`|"icon_name", "r", "g", "b", "bg_r", "bg_g", "bg_b"|sets the specified screen with progress bar, the specified color of the progress bar, and the background color of the progress bar. if you set the color to black, the color display will work according to the progress value| |`icon_clock`|"icon_name", "lifetime", "screen_time", "default_font", "r", "g", "b"|show the specified icon with time, there is support for [displaying text on top of the icon](#icon_text)| |`icon_date`|"icon_name", "lifetime", "screen_time", "default_font", "r", "g", "b"|show the specified icon with date, there is support for [displaying text on top of the icon](#icon_text)| |`graph_screen`|lifetime", "screen_time"|show graph as defined in the YAML file| @@ -770,7 +771,7 @@ Numerous features are accessible with services from home assistant and lambdas t - **lifetime**: how long does this screen stay in the queue (minutes) - **screen_time**: how long is this screen display in the loop (seconds). For short text without scrolling it is shown the defined time, longer text is scrolled at least `scroll_count` times. - **default_font**: use the default font (true) or the special font (false) -- **progress**: сan take a value from -100 to 100, the color of the progress bar is calculated automatically, if the progress is in the range `0..100`, then `from red to green`, if in the range `-100..0`, then from `green to red`. +- **progress**: сan take a value from -100 to 100, the color of the progress bar is calculated automatically, if no colors are specified in the function `set_progressbar_color`, then if the progress is in the range `0..100`, then `from red to green`, if in the range `-100..0`, then from `green to red`. - **value**: the brightness 0..255 ### Night mode