diff --git a/README.md b/README.md index 8999b4ce..64443188 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,9 @@ - Added a pseudo-icon `blank` - empty icon, no display. - Added screen with scroll icon along with long text, `icon_text_screen`, `rainbow_icon_text_screen`. - Added `bitmap_stack`screen. Screen that allows you to display from 1 to 64 icons described in the configuration. - +- Added a screen with the ability to display a progress bar, text, progress value `(-100..100)` + - `text_screen_progress(text, value, progress, lifetime, screen_time, default_font, value_color_as_progress, r, g, b)` + ### EspHoMaTriX 2023.9.0 - Added the ability to display graph as defined in the YAML file @@ -759,7 +761,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| +|`set_progressbar_color`|"icon_name", "mode", "r", "g", "b", "bg_r", "bg_g", "bg_b"|sets the specified by name and [mode](#modes) 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| @@ -769,7 +771,8 @@ Numerous features are accessible with services from home assistant and lambdas t |`rainbow_bitmap_small`|"icon", "text", "lifetime", "screen_time", "default_font"|show 8x8 image as text, and text in rainbow colors| |`icon_text_screen`|"icon_name", "text", "lifetime", "screen_time", "default_font", "r", "g", "b"|show the specified icon with text and scroll icon along with long text| |`rainbow_icon_text_screen`|"icon_name", "text", "lifetime", "screen_time", "default_font"|show the specified icon with text in rainbow color and scroll icon along with long text| -|`bitmap_stack`|"icons", "lifetime", "screen_time"|show or scroll from 1 to 64 icons described in the configuration. [See examples](#bitmap_stack-example)| +|`bitmap_stack`|"icons", "lifetime", "screen_time"|show or scroll from 1 to 64 icons described in the configuration| +|`text_screen_progress`|"text", "value", "progress", "lifetime", "screen_time", "default_font", "value_color_as_progress", "r", "g", "b"|show the specified short text with value and with progress bar on bottom| #### Parameter description @@ -783,6 +786,7 @@ Numerous features are accessible with services from home assistant and lambdas t - **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 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_color_as_progress**: display the value with the color of the current color on the progress bar - **value**: the brightness 0..255 ### Night mode @@ -1040,6 +1044,7 @@ For example, if you have multiple icons named weather_sunny, weather_rain & weat |MODE_ICON_TEXT_SCREEN| 21| |MODE_RAINBOW_ICON_TEXT_SCREEN| 22| |MODE_BITMAP_STACK_SCREEN| 23| +|MODE_TEXT_PROGRESS| 24| **(D)** Service **display_on** / **display_off** diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index 0503c810..40f834ba 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -641,8 +641,9 @@ namespace esphome register_service(&EHMTX::fire_screen, "fire_screen", {"lifetime", "screen_time"}); #endif + register_service(&EHMTX::text_screen_progress, "text_screen_progress", {"text", "value", "progress", "lifetime", "screen_time", "default_font", "value_color_as_progress", "r", "g", "b"}); 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"}); + register_service(&EHMTX::set_progressbar_color, "set_progressbar_color", {"icon_name", "mode", "r", "g", "b", "bg_r", "bg_g", "bg_b"}); ESP_LOGD(TAG, "Setup and running!"); } @@ -735,7 +736,8 @@ namespace esphome (mode == MODE_RAINBOW_ICON) || (mode == MODE_ICON_PROGRESS) || (mode == MODE_ICON_TEXT_SCREEN) || - (mode == MODE_RAINBOW_ICON_TEXT_SCREEN)) + (mode == MODE_RAINBOW_ICON_TEXT_SCREEN) || + (mode == MODE_TEXT_PROGRESS)) { if (strcmp(this->queue[i]->icon_name.c_str(), icon_name.c_str()) != 0) { @@ -876,6 +878,7 @@ namespace esphome case MODE_ICON_PROGRESS: case MODE_ICON_TEXT_SCREEN: case MODE_RAINBOW_ICON_TEXT_SCREEN: + case MODE_TEXT_PROGRESS: infotext = this->queue[i]->icon_name.c_str(); break; case MODE_RAINBOW_TEXT: @@ -1179,7 +1182,8 @@ namespace esphome (mode == MODE_RAINBOW_ICON) || (mode == MODE_ICON_PROGRESS) || (mode == MODE_ICON_TEXT_SCREEN) || - (mode == MODE_RAINBOW_ICON_TEXT_SCREEN)) + (mode == MODE_RAINBOW_ICON_TEXT_SCREEN) || + (mode == MODE_TEXT_PROGRESS)) { if (this->string_has_ending(icon_name, "*")) { @@ -1284,6 +1288,27 @@ namespace esphome screen->status(); } + void EHMTX::text_screen_progress(std::string text, std::string value, int progress, int lifetime, int screen_time, bool default_font, bool value_color_as_progress, int r, int g, int b) + { + EHMTX_queue *screen = this->find_mode_icon_queue_element(MODE_TEXT_PROGRESS, text); + + screen->icon_name = text; + screen->text = value; + screen->text_color = Color(r, g, b); + screen->default_font = default_font; + screen->mode = MODE_TEXT_PROGRESS; + screen->icon = value_color_as_progress; + screen->progress = (progress > 100) ? 100 : (progress < -100) ? -100 : progress; + screen->screen_time_ = screen_time * 1000.0; + screen->endtime = this->get_tick() + (lifetime > 0 ? lifetime * 60000.0 : screen->screen_time_); + for (auto *t : on_add_screen_triggers_) + { + t->process(screen->icon_name, (uint8_t)screen->mode); + } + ESP_LOGD(TAG, "text progress screen text: %s value: %s progress %d lifetime: %d screen_time: %d", text.c_str(), value.c_str(), progress, lifetime, screen_time); + screen->status(); + } + void EHMTX::icon_screen_progress(std::string iconname, std::string text, int progress, int lifetime, int screen_time, bool default_font, int r, int g, int b) { std::string ic = get_icon_name(iconname); @@ -1319,14 +1344,14 @@ 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) + void EHMTX::set_progressbar_color(std::string iconname, int mode, 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)); + EHMTX_queue *screen = this->find_mode_icon_queue_element(mode, 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); + ESP_LOGD(TAG, "progress screen mode: %d iconname: %s color progressbar: r: %d g: %d b: %d background: r: %d g: %d b: %d", mode, iconname.c_str(), r, g, b, bg_r, bg_g, bg_b); screen->status(); } @@ -2048,7 +2073,8 @@ namespace esphome } if (this->queue[this->screen_pointer]->mode != MODE_FULL_SCREEN && this->queue[this->screen_pointer]->mode != MODE_BITMAP_SCREEN && - this->queue[this->screen_pointer]->mode != MODE_ICON_PROGRESS) + this->queue[this->screen_pointer]->mode != MODE_ICON_PROGRESS && + this->queue[this->screen_pointer]->mode != MODE_TEXT_PROGRESS) { this->draw_gauge(); } diff --git a/components/ehmtxv2/EHMTX.h b/components/ehmtxv2/EHMTX.h index e8caa0b7..6f03ae33 100644 --- a/components/ehmtxv2/EHMTX.h +++ b/components/ehmtxv2/EHMTX.h @@ -54,7 +54,8 @@ enum show_mode : uint8_t MODE_RAINBOW_BITMAP_SMALL = 20, MODE_ICON_TEXT_SCREEN = 21, MODE_RAINBOW_ICON_TEXT_SCREEN = 22, - MODE_BITMAP_STACK_SCREEN = 23 + MODE_BITMAP_STACK_SCREEN = 23, + MODE_TEXT_PROGRESS = 24 }; namespace esphome @@ -209,8 +210,9 @@ namespace esphome void date_screen(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 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 text_screen_progress(std::string text, std::string value, int progress, int lifetime = D_LIFETIME, int screen_time = D_SCREEN_TIME, bool default_font = true, bool value_color_as_progress = false, 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 set_progressbar_color(std::string icon, int mode = MODE_ICON_PROGRESS, 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 icon_text_screen(std::string icon, std::string text, 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 rainbow_icon_text_screen(std::string icon, std::string text, int lifetime = D_LIFETIME, int screen_time = D_SCREEN_TIME, bool default_font = true); diff --git a/components/ehmtxv2/EHMTX_queue.cpp b/components/ehmtxv2/EHMTX_queue.cpp index 84ccd1a2..703df336 100644 --- a/components/ehmtxv2/EHMTX_queue.cpp +++ b/components/ehmtxv2/EHMTX_queue.cpp @@ -115,6 +115,9 @@ namespace esphome case MODE_ICON_PROGRESS: ESP_LOGD(TAG, "queue: icon progress: \"%s\" text: %s for: %.1f sec", this->icon_name.c_str(), this->text.c_str(), this->screen_time_ / 1000.0); break; + case MODE_TEXT_PROGRESS: + ESP_LOGD(TAG, "queue: text progress: \"%s\" text: %s for: %.1f sec", this->icon_name.c_str(), this->text.c_str(), this->screen_time_ / 1000.0); + break; case MODE_ICON_CLOCK: ESP_LOGD(TAG, "queue: icon clock: \"%s\" for: %.1f sec", this->icon_name.c_str(), this->screen_time_ / 1000.0); break; @@ -762,6 +765,32 @@ namespace esphome } break; + case MODE_TEXT_PROGRESS: + color_ = this->text_color; + + this->config_->display->print(0, yoffset, font, color_, esphome::display::TextAlign::BASELINE_LEFT, this->icon_name.c_str()); + + this->config_->display->line(0, 7, 31, 7, this->progressbar_back_color); + if (this->progress != 0) + { + 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(0, 7, abs(this->progress) * 31 / 100, 7, color_); + } + + if (this->icon == 0) + { + color_ = this->text_color; + } + this->config_->display->print(32, yoffset, font, color_, esphome::display::TextAlign::BASELINE_RIGHT, this->text.c_str()); + break; + case MODE_ICON_TEXT_SCREEN: case MODE_RAINBOW_ICON_TEXT_SCREEN: color_ = (this->mode == MODE_RAINBOW_TEXT) ? this->config_->rainbow_color : this->text_color; diff --git a/components/ehmtxv2/__init__.py b/components/ehmtxv2/__init__.py index 1dd18863..2a7719bb 100644 --- a/components/ehmtxv2/__init__.py +++ b/components/ehmtxv2/__init__.py @@ -252,7 +252,7 @@ def rgb565_888(v565): } ), cv.Optional(CONF_NIGHT_MODE_SCREENS, default=DEFAULT_NIGHT_MODE_SCREENS): cv.All( - cv.ensure_list(cv.one_of(1, 2, 3, 4, 5, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23)), cv.Length(min=1, max=5) + cv.ensure_list(cv.one_of(1, 2, 3, 4, 5, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24)), cv.Length(min=1, max=5) ), cv.Required(CONF_ICONS): cv.All( cv.ensure_list(