diff --git a/README.md b/README.md index ffb4a5f..446e597 100644 --- a/README.md +++ b/README.md @@ -462,15 +462,16 @@ ehmtxv2: time_component: ehmtx_time icons2html: true default_font_id: default_font + default_font_yoffset: 6 special_font_id: special_font special_font_yoffset: 7 - default_font_yoffset: 6 brightness: 80 # percent time_format: "%H:%M" date_format: "%d.%m." week_start_monday: true # false equals sunday scroll_count: 2 # scroll long text at least two times scroll_interval: 80 # milliseconds + rainbow_interval: 32 # milliseconds frame_interval: 192 # milliseconds icons: ..... @@ -720,8 +721,8 @@ For example, if you have multiple icons named weather_sunny, weather_rain & weat |MODE_CLOCK | 2| | MODE_DATE | 3| | MODE_FULL_SCREEN | 4| -|MODE_ICONSCREEN | 5| -|MODE_TEXT | 6| +|MODE_ICON_SCREEN | 5| +|MODE_TEXT_SCREEN | 6| |MODE_RAINBOW_ICON | 7| |MODE_RAINBOW_TEXT |8| | MODE_RAINBOW_CLOCK | 9| diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index e6fa054..8ae8e08 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -2,7 +2,7 @@ namespace esphome { - EHMTX::EHMTX() : PollingComponent(TICKINTERVAL) + EHMTX::EHMTX() : PollingComponent(POLLINGINTERVAL) { this->show_display = true; this->display_gauge = false; @@ -176,13 +176,19 @@ namespace esphome register_service(&EHMTX::full_screen, "full_screen", {"icon_name", "lifetime", "screen_time"}); register_service(&EHMTX::icon_screen, "icon_screen", {"icon_name", "text", "lifetime", "screen_time", "default_font", "r", "g", "b"}); + register_service(&EHMTX::rainbow_icon_screen, "rainbow_icon_screen", {"icon_name", "text", "lifetime", "screen_time", "default_font"}); + register_service(&EHMTX::text_screen, "text_screen", {"text", "lifetime", "screen_time", "default_font", "r", "g", "b"}); + register_service(&EHMTX::rainbow_text_screen, "rainbow_text_screen", {"text", "lifetime", "screen_time", "default_font"}); + register_service(&EHMTX::clock_screen, "clock_screen", {"lifetime", "screen_time", "default_font", "r", "g", "b"}); register_service(&EHMTX::rainbow_clock_screen, "rainbow_clock_screen", {"lifetime", "screen_time", "default_font"}); - register_service(&EHMTX::blank_screen, "blank_screen", {"lifetime", "screen_time"}); + register_service(&EHMTX::date_screen, "date_screen", {"lifetime", "screen_time", "default_font", "r", "g", "b"}); - register_service(&EHMTX::rainbow_icon_screen, "rainbow_icon_screen", {"icon_name", "text", "lifetime", "screen_time", "default_font"}); - register_service(&EHMTX::rainbow_text_screen, "rainbow_text_screen", {"text", "lifetime", "screen_time", "default_font"}); + register_service(&EHMTX::rainbow_date_screen, "rainbow_date_screen", {"lifetime", "screen_time", "default_font"}); + + register_service(&EHMTX::blank_screen, "blank_screen", {"lifetime", "screen_time"}); + register_service(&EHMTX::set_brightness, "brightness", {"value"}); ESP_LOGD(TAG, "Setup and running!"); @@ -215,7 +221,7 @@ namespace esphome void EHMTX::update() // called from polling component { - if (! this->is_running){ + if (!this->is_running){ if (this->clock->now().timestamp > 6000) { ESP_LOGD(TAG, "time sync => starting"); this->is_running = true; @@ -236,7 +242,7 @@ namespace esphome if (this->queue[i]->mode == mode) { bool force = true; - if ((mode == MODE_ICONSCREEN) || (mode == MODE_FULL_SCREEN) || (mode == MODE_RAINBOW_ICON)) + if ((mode == MODE_ICON_SCREEN) || (mode == MODE_FULL_SCREEN) || (mode == MODE_RAINBOW_ICON)) { if (strcmp(this->queue[i]->icon_name.c_str(), icon_name.c_str()) != 0) { @@ -303,12 +309,12 @@ namespace esphome case MODE_FULL_SCREEN: infotext = "full screen " + this->queue[i]->icon_name; break; - case MODE_ICONSCREEN: + case MODE_ICON_SCREEN: case MODE_RAINBOW_ICON: infotext = this->queue[i]->icon_name.c_str(); break; case MODE_RAINBOW_TEXT: - case MODE_TEXT: + case MODE_TEXT_SCREEN: infotext = "TEXT"; break; default: @@ -461,7 +467,7 @@ namespace esphome { bool force = true; ESP_LOGW(TAG, "del_screen: icon %s in position: %d mode %d", icon_name.c_str(), i, mode); - if ((mode == MODE_ICONSCREEN) || (mode == MODE_FULL_SCREEN) || (mode == MODE_RAINBOW_ICON)) + if ((mode == MODE_ICON_SCREEN) || (mode == MODE_FULL_SCREEN) || (mode == MODE_RAINBOW_ICON)) { if (strcmp(this->queue[i]->icon_name.c_str(), icon_name.c_str()) != 0) { @@ -505,7 +511,7 @@ namespace esphome screen->set_text(text, icon, w, lifetime, screen_time); screen->text_color = Color(r, g, b); screen->default_font = default_font; - screen->mode = MODE_ICONSCREEN; + screen->mode = MODE_ICON_SCREEN; screen->icon_name = iconname; ESP_LOGD(TAG, "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(); @@ -523,6 +529,19 @@ namespace esphome screen->status(); } + void EHMTX::rainbow_date_screen(int lifetime, int screen_time, bool default_font) + { + EHMTX_queue *screen = this->find_free_queue_element(); + + ESP_LOGD(TAG, "rainbow_date_screen lifetime: %d screen_time: %d", lifetime, screen_time); + screen->mode = MODE_RAINBOW_DATE; + screen->default_font = default_font; + screen->screen_time = screen_time; + screen->endtime = this->clock->now().timestamp + lifetime * 60; + screen->status(); + } + + void EHMTX::rainbow_icon_screen(std::string iconname, std::string text, int lifetime, int screen_time, bool default_font) { @@ -534,22 +553,13 @@ namespace esphome icon = 0; } EHMTX_queue *screen = this->find_icon_queue_element(icon); - - int x, y, w, h; - if (default_font) - { - this->display->get_text_bounds(0, 0, text.c_str(), this->default_font, display::TextAlign::LEFT, &x, &y, &w, &h); - } - else - { - this->display->get_text_bounds(0, 0, text.c_str(), this->special_font, display::TextAlign::LEFT, &x, &y, &w, &h); - } - screen->set_text(text, icon, w, lifetime, screen_time); - screen->default_font = default_font; + screen->icon_name = iconname; screen->text = text; - screen->pixels_ = w; + screen->endtime = this->clock->now().timestamp + lifetime * 60; + screen->screen_time = screen_time; + screen->default_font = default_font; screen->mode = MODE_RAINBOW_ICON; - screen->icon_name = iconname; + screen->calc_scroll_time(); 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(); } @@ -558,33 +568,13 @@ namespace esphome { EHMTX_queue *screen = this->find_free_queue_element(); - int x, y, w, h; - if (default_font) - { - this->display->get_text_bounds(0, 0, text.c_str(), this->default_font, display::TextAlign::LEFT, &x, &y, &w, &h); - } - else - { - this->display->get_text_bounds(0, 0, text.c_str(), this->special_font, display::TextAlign::LEFT, &x, &y, &w, &h); - } - screen->text = text; - screen->pixels_ = w; - if (screen->pixels_ < 32) - { - screen->centerx_ = ceil((32 - screen->pixels_) / 2); - } - - screen->shiftx_ = 0; - float display_duration = ceil((this->scroll_count * w * this->scroll_interval) / 1000); - screen->screen_time = (display_duration > screen_time) ? display_duration : screen_time; - ESP_LOGD(TAG, "text_screen text: text: %s pixels %d screen_time: %d lifetime: %d", text.c_str(), w, screen->screen_time, lifetime); screen->endtime = this->clock->now().timestamp + lifetime * 60; - - screen->text_color = Color(r, g, b); + screen->screen_time = screen_time; screen->default_font = default_font; - screen->mode = MODE_TEXT; - + screen->text_color = Color(r, g, b); + screen->mode = MODE_TEXT_SCREEN; + screen->calc_scroll_time(); screen->status(); } @@ -592,32 +582,12 @@ namespace esphome { EHMTX_queue *screen = this->find_free_queue_element(); - int x, y, w, h; - if (default_font) - { - this->display->get_text_bounds(0, 0, text.c_str(), this->default_font, display::TextAlign::LEFT, &x, &y, &w, &h); - } - else - { - this->display->get_text_bounds(0, 0, text.c_str(), this->special_font, display::TextAlign::LEFT, &x, &y, &w, &h); - } - screen->text = text; - screen->pixels_ = w; - if (screen->pixels_ < 32) - { - screen->centerx_ = ceil((32 - screen->pixels_) / 2); - } - - screen->shiftx_ = 0; - float display_duration = ceil((this->scroll_count * w * this->scroll_interval) / 1000); - screen->screen_time = (display_duration > screen_time) ? display_duration : screen_time; - ESP_LOGD(TAG, "text_screen text: text: %s pixels %d screen_time: %d lifetime: %d", text.c_str(), w, screen->screen_time, lifetime); screen->endtime = this->clock->now().timestamp + lifetime * 60; - + screen->screen_time = screen_time; screen->default_font = default_font; screen->mode = MODE_RAINBOW_TEXT; - + screen->calc_scroll_time(); screen->status(); } @@ -671,7 +641,7 @@ namespace esphome { for (size_t i = 0; i < MAXQUEUE; i++) { - if ((this->queue[i]->mode == MODE_ICONSCREEN) && (this->queue[i]->icon == icon)) + if ((this->queue[i]->mode == MODE_ICON_SCREEN) && (this->queue[i]->icon == icon)) { ESP_LOGD(TAG, "free_screen: found by icon"); return this->queue[i]; diff --git a/components/ehmtxv2/EHMTX.h b/components/ehmtxv2/EHMTX.h index 8abf226..1da158b 100644 --- a/components/ehmtxv2/EHMTX.h +++ b/components/ehmtxv2/EHMTX.h @@ -20,10 +20,10 @@ const uint8_t MAXICONS = 90; const uint8_t TEXTSCROLLSTART = 8; const uint8_t TEXTSTARTOFFSET = (32 - 8); -const uint16_t TICKINTERVAL = 1000; // each 1000ms +const uint16_t POLLINGINTERVAL = 800; static const char *const EHMTX_VERSION = "Version: 2023.5.0 beta"; static const char *const TAG = "EHMTXv2"; -enum show_mode : uint8_t { MODE_EMPTY = 0,MODE_BLANK = 1, MODE_CLOCK = 2, MODE_DATE = 3, MODE_FULL_SCREEN = 4, MODE_ICONSCREEN = 5, MODE_TEXT = 6 , MODE_RAINBOW_ICON = 7,MODE_RAINBOW_TEXT = 8, MODE_RAINBOW_CLOCK = 9,MODE_RAINBOW_DATE=10 }; +enum show_mode : uint8_t { MODE_EMPTY = 0,MODE_BLANK = 1, MODE_CLOCK = 2, MODE_DATE = 3, MODE_FULL_SCREEN = 4, MODE_ICON_SCREEN = 5, MODE_TEXT_SCREEN = 6 , MODE_RAINBOW_ICON = 7,MODE_RAINBOW_TEXT = 8, MODE_RAINBOW_CLOCK = 9,MODE_RAINBOW_DATE=10 }; namespace esphome { @@ -69,7 +69,7 @@ namespace esphome void remove_expired_queue_element(); uint8_t find_oldest_queue_element(); uint8_t find_icon_in_queue(std::string); - void force_screen(std::string name,int mode=MODE_ICONSCREEN); + void force_screen(std::string name,int mode=MODE_ICON_SCREEN); EHMTX_Icon *icons[MAXICONS]; EHMTX_queue *queue[MAXQUEUE]; void add_icon(EHMTX_Icon *icon); @@ -142,7 +142,8 @@ namespace esphome void rainbow_icon_screen(std::string icon_name, std::string text, int lifetime=D_LIFETIME, int screen_time=D_SCREEN_TIME, bool default_font=true); void rainbow_text_screen(std::string text, int lifetime=D_LIFETIME, int screen_time=D_SCREEN_TIME, bool default_font=true); void rainbow_clock_screen(int lifetime=D_LIFETIME, int screen_time=D_SCREEN_TIME, bool default_font=true); - void del_screen(std::string icon, int mode=MODE_ICONSCREEN); + void rainbow_date_screen(int lifetime=D_LIFETIME, int screen_time=D_SCREEN_TIME, bool default_font=true); + void del_screen(std::string icon, int mode=MODE_ICON_SCREEN); void draw_gauge(); void draw_alarm(); @@ -186,6 +187,7 @@ namespace esphome void update_screen(); void hold_slot(uint8_t _sec); void set_text(std::string text, uint8_t icon, uint16_t pixel, uint16_t et, uint16_t st); + void calc_scroll_time(); }; class EHMTXNextScreenTrigger : public Trigger diff --git a/components/ehmtxv2/EHMTX_queue.cpp b/components/ehmtxv2/EHMTX_queue.cpp index c3eeec7..143c643 100644 --- a/components/ehmtxv2/EHMTX_queue.cpp +++ b/components/ehmtxv2/EHMTX_queue.cpp @@ -37,10 +37,10 @@ namespace esphome case MODE_FULL_SCREEN: ESP_LOGD(TAG, "queue: full screen: %s for %d sec", this->icon_name.c_str(), this->screen_time); break; - case MODE_ICONSCREEN: + case MODE_ICON_SCREEN: ESP_LOGD(TAG, "queue: icon screen: %s text: %s for %d sec", this->icon_name.c_str(), this->text.c_str(), this->screen_time); break; - case MODE_TEXT: + case MODE_TEXT_SCREEN: ESP_LOGD(TAG, "queue: text text: %s for %d sec", this->text.c_str(), this->screen_time); break; case MODE_RAINBOW_ICON: @@ -76,7 +76,7 @@ namespace esphome this->config_->last_rainbow_time = millis(); } - if ((this->mode == MODE_ICONSCREEN) || (this->mode == MODE_RAINBOW_ICON)) + if ((this->mode == MODE_ICON_SCREEN) || (this->mode == MODE_RAINBOW_ICON)) { if (millis() - this->config_->last_scroll_time >= this->config_->scroll_interval && this->pixels_ > TEXTSTARTOFFSET) { @@ -88,7 +88,7 @@ namespace esphome this->config_->last_scroll_time = millis(); } } - if ((this->mode == MODE_TEXT) || (this->mode == MODE_RAINBOW_TEXT)) + if ((this->mode == MODE_TEXT_SCREEN) || (this->mode == MODE_RAINBOW_TEXT)) { if (millis() - this->config_->last_scroll_time >= this->config_->scroll_interval && this->pixels_ >= 32) { @@ -154,7 +154,7 @@ namespace esphome this->config_->clock->now()); if ((this->config_->clock->now().second % 2 == 0) && this->config_->show_seconds) { - this->config_->display->draw_pixel_at(0, 0, this->config_->clock_color); + this->config_->display->draw_pixel_at(0, 0, color_); } if (this->mode != MODE_RAINBOW_DATE){ this->config_->draw_day_of_week(); @@ -168,7 +168,7 @@ namespace esphome case MODE_FULL_SCREEN: this->config_->display->image(0, 0, this->config_->icons[this->icon]); break; - case MODE_ICONSCREEN: + case MODE_ICON_SCREEN: case MODE_RAINBOW_ICON: { if (this->pixels_ > TEXTSTARTOFFSET) @@ -196,7 +196,7 @@ namespace esphome } } break; - case MODE_TEXT: + case MODE_TEXT_SCREEN: case MODE_RAINBOW_TEXT: if (this->pixels_ > 32) @@ -242,4 +242,48 @@ namespace esphome this->endtime = this->config_->clock->now().timestamp + et * 60; this->icon = icon; } + + void EHMTX_queue::calc_scroll_time() + { + int x, y, w, h; + float display_duration; + if (this->default_font) + { + this->config_->display->get_text_bounds(0, 0, text.c_str(), this->config_->default_font, display::TextAlign::LEFT, &x, &y, &w, &h); + } + else + { + this->config_->display->get_text_bounds(0, 0, text.c_str(), this->config_->special_font, display::TextAlign::LEFT, &x, &y, &w, &h); + } + + this->pixels_ = w; + this->shiftx_ = 0; + + switch (this->mode) + { + case MODE_RAINBOW_TEXT: + case MODE_TEXT_SCREEN: + display_duration = ceil((28+(this->config_->scroll_count * (32 + this->pixels_)) * this->config_->scroll_interval) / 1000); + this->screen_time = (display_duration > this->screen_time) ? display_duration : this->screen_time; + if (this->pixels_ < 32) + { + this->centerx_ = ceil((32 - this->pixels_) / 2); + } + break; + case MODE_RAINBOW_ICON: + case MODE_ICON_SCREEN: + display_duration = ceil(((28-TEXTSTARTOFFSET)+(this->config_->scroll_count * (TEXTSTARTOFFSET + this->pixels_)) * this->config_->scroll_interval) / 1000); + this->screen_time = (display_duration > this->screen_time) ? display_duration : this->screen_time; + if (this->pixels_ < 23) + { + this->centerx_ = ceil((23 - this->pixels_) / 2); + } + break; + default: + break; + } + + this->shiftx_ = 0; + ESP_LOGD(TAG, "display text: %s pixels %d calculated: %d", text.c_str(), this->pixels_, this->screen_time); + } } diff --git a/copy2esphome/EHMTX_easy_delete.yaml b/copy2esphome/EHMTX_easy_delete.yaml index e16d3e9..0fcdedf 100644 --- a/copy2esphome/EHMTX_easy_delete.yaml +++ b/copy2esphome/EHMTX_easy_delete.yaml @@ -22,7 +22,7 @@ blueprint: custom_value: true mode: dropdown options: - - label: MODE_ICONSCREEN + - label: MODE_ICON_SCREEN value: "5" - label: MODE_BLANK value: "1" @@ -32,7 +32,7 @@ blueprint: value: "3" - label: MODE_FULL_SCREEN value: "4" - - label: MODE_TEXT + - label: MODE_TEXT_SCREEN value: "6" - label: MODE_RAINBOW_ICON value: "7"