From db9917d15cbf396209a68ba9ae9b1c563552cff3 Mon Sep 17 00:00:00 2001 From: LuBeDa Date: Mon, 15 May 2023 20:05:25 +0200 Subject: [PATCH] https://github.com/lubeda/EspHoMaTriXv2/issues/12 --- README.md | 12 ++++ components/ehmtxv2/EHMTX.cpp | 108 +++++++++++++++++++---------- components/ehmtxv2/EHMTX_queue.cpp | 2 +- 3 files changed, 85 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index ffc72db..ecbcba0 100644 --- a/README.md +++ b/README.md @@ -574,6 +574,18 @@ Numerous features are accessible with services from home assistant and lambdas y |`date_screen`|"lifetime", "screen_time", "default_font", "r", "g", "b"|show the date| |`brightness`|"value"|set the display brightness| +#### Parameter description + +"r", "g", "b": Color components for red, green and blue 0..255 +"size": The size of the indicator or alarm, 1-3 +"percent": values from 0..100 +"icon_name": the id of the icon to show, as defined in the YAML file +"text": a text message to display +"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) +"value": the brightness 0..255 + ### Local lambdas #### Add screen to your display queue diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index 4cf88eb..9df7e45 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -504,20 +504,35 @@ namespace esphome } EHMTX_queue *screen = this->find_icon_queue_element(icon); - int x, y, w, h; + int x, y, pixel, h; if (default_font) { - this->display->get_text_bounds(0, 0, text.c_str(), this->default_font, display::TextAlign::LEFT, &x, &y, &w, &h); + this->display->get_text_bounds(0, 0, text.c_str(), this->default_font, display::TextAlign::LEFT, &x, &y, &pixel, &h); } else { - this->display->get_text_bounds(0, 0, text.c_str(), this->special_font, display::TextAlign::LEFT, &x, &y, &w, &h); + this->display->get_text_bounds(0, 0, text.c_str(), this->special_font, display::TextAlign::LEFT, &x, &y, &pixel, &h); } - screen->set_text(text, icon, w, lifetime, screen_time); + if (pixel < 23) + { + screen->centerx_ = ceil((22 - pixel) / 2); + screen->screen_time = screen_time; + } + else + { + screen->centerx_ = 0; + int display_duration = ceil((this->scroll_count * (TEXTSTARTOFFSET + pixel) * this->scroll_interval) / 1000); + screen->screen_time = (display_duration > screen_time) ? display_duration : screen_time; + } + screen->text = text; + screen->pixels_ = pixel; + screen->endtime = this->clock->now().timestamp + lifetime * 60; + screen->shiftx_ = 0; screen->text_color = Color(r, g, b); screen->default_font = default_font; screen->mode = MODE_ICON_SCREEN; screen->icon_name = iconname; + screen->icon = icon; for (auto *t : on_add_screen_triggers_) { t->process(screen->icon_name,(uint8_t)screen->mode); @@ -526,6 +541,59 @@ namespace esphome screen->status(); } +void EHMTX::rainbow_icon_screen(std::string iconname, std::string text, int lifetime, int screen_time, bool default_font) + { + uint8_t icon = this->find_icon(iconname.c_str()); + + if (icon >= this->icon_count) + { + ESP_LOGW(TAG, "icon %d not found => default: 0", icon); + icon = 0; + for (auto *t : on_icon_error_triggers_) + { + t->process(iconname); + } + } + EHMTX_queue *screen = this->find_icon_queue_element(icon); + + int x, y, pixel, h; + if (default_font) + { + this->display->get_text_bounds(0, 0, text.c_str(), this->default_font, display::TextAlign::LEFT, &x, &y, &pixel, &h); + } + else + { + this->display->get_text_bounds(0, 0, text.c_str(), this->special_font, display::TextAlign::LEFT, &x, &y, &pixel, &h); + } + if (pixel < 23) + { + screen->centerx_ = ceil((22 - pixel) / 2); + screen->screen_time = screen_time; + } + else + { + screen->centerx_ = 0; + int display_duration = ceil((this->scroll_count * (TEXTSTARTOFFSET + pixel) * this->scroll_interval) / 1000); + screen->screen_time = (display_duration > screen_time) ? display_duration : screen_time; + } + screen->text = text; + screen->pixels_ = pixel; + screen->endtime = this->clock->now().timestamp + lifetime * 60; + screen->shiftx_ = 0; + screen->default_font = default_font; + screen->mode = MODE_RAINBOW_ICON; + screen->icon_name = iconname; + screen->icon = icon; + for (auto *t : on_add_screen_triggers_) + { + t->process(screen->icon_name,(uint8_t)screen->mode); + } + ESP_LOGD(TAG, "rainbow icon screen icon: %d iconname: %s text: %s lifetime: %d screen_time: %d", icon, iconname.c_str(), text.c_str(), lifetime, screen_time); + screen->status(); + } + + + void EHMTX::rainbow_clock_screen(int lifetime, int screen_time, bool default_font) { EHMTX_queue *screen = this->find_free_queue_element(); @@ -550,38 +618,6 @@ namespace esphome screen->status(); } - - - void EHMTX::rainbow_icon_screen(std::string iconname, std::string text, int lifetime, int screen_time, bool default_font) - { - uint8_t icon = this->find_icon(iconname.c_str()); - - if (icon >= this->icon_count) - { - ESP_LOGW(TAG, "icon %d not found => default: 0", icon); - icon = 0; - for (auto *t : on_icon_error_triggers_) - { - t->process(iconname); - } - } - EHMTX_queue *screen = this->find_icon_queue_element(icon); - screen->icon_name = iconname; - screen->icon = icon; - screen->text = text; - screen->endtime = this->clock->now().timestamp + lifetime * 60; - screen->screen_time = screen_time; - screen->default_font = default_font; - screen->mode = MODE_RAINBOW_ICON; - screen->calc_scroll_time(); - for (auto *t : on_add_screen_triggers_) - { - t->process(screen->icon_name,(uint8_t)screen->mode); - } - ESP_LOGD(TAG, "rainbow_icon_screen icon: %d iconname: %s text: %s lifetime: %d screen_time: %d", icon, iconname.c_str(), text.c_str(), lifetime, screen_time); - screen->status(); - } - void EHMTX::text_screen(std::string text, int lifetime, int screen_time, bool default_font, int r, int g, int b) { EHMTX_queue *screen = this->find_free_queue_element(); diff --git a/components/ehmtxv2/EHMTX_queue.cpp b/components/ehmtxv2/EHMTX_queue.cpp index ca39be3..327dd14 100644 --- a/components/ehmtxv2/EHMTX_queue.cpp +++ b/components/ehmtxv2/EHMTX_queue.cpp @@ -238,7 +238,7 @@ namespace esphome this->shiftx_ = 0; float display_duration = ceil((this->config_->scroll_count * (TEXTSTARTOFFSET + pixel) * this->config_->scroll_interval) / 1000); this->screen_time = (display_duration > screen_time) ? display_duration : screen_time; - ESP_LOGD(TAG, "display text: %s pixels %d calculated: %d screen_time: %d", text.c_str(), pixel, this->screen_time, screen_time); + ESP_LOGD(TAG, "display text: %s pixels %d display_duration %d calculated: %d screen_time: %d", text.c_str(), pixel,display_duration, this->screen_time, screen_time); this->endtime = this->config_->clock->now().timestamp + et * 60; this->icon = icon; }