diff --git a/README.md b/README.md index a16fd0e0..e0e90ed1 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ - `icon_screen_progress(iconname, text, progress, lifetime, screen_time, default_font, r, g, b)` - Added `replace_time_date_to:` and `replace_time_date_from:` which allow replacing the system date & time text (anything!) - Added `bitmap_small` and `rainbow_bitmap_small` screen. +- Added a pseudo-icon `blank` - empty icon, no display. ### EspHoMaTriX 2023.9.0 - Added the ability to display graph as defined in the YAML file @@ -770,7 +771,7 @@ Numerous features are accessible with services from home assistant and lambdas t - **r, g, b**: Color components for red, green, and blue 0..255 - **size**: The size of the rindicator or alarm, 1-3 - **percent**: values from 0..100 -- **icon_name**: the id of the icon to show, as defined in the YAML file, it is also possible to set the arbitrary [screen identifier](#screen_id), for example `icon_name|screen_id` +- **icon_name**: the id of the icon to show, as defined in the YAML file (or pseudo-icon `blank` - empty icon), it is also possible to set the arbitrary [screen identifier](#screen_id), for example `icon_name|screen_id` - **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. diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index 0745f432..8147ee4d 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -341,6 +341,11 @@ namespace esphome uint8_t EHMTX::find_icon(std::string name) { + if (name == "blank") + { + return BLANKICON; + } + for (uint8_t i = 0; i < this->icon_count; i++) { if (strcmp(this->icons[i]->name.c_str(), name.c_str()) == 0) @@ -1011,9 +1016,9 @@ namespace esphome { uint8_t icon = this->find_icon(iconname.c_str()); - if (icon >= this->icon_count) + if (icon == MAXICONS) { - ESP_LOGW(TAG, "icon %d not found => default: 0", icon); + ESP_LOGW(TAG, "icon %d/%s not found => default: 0", icon, iconname.c_str()); icon = 0; for (auto *t : on_icon_error_triggers_) { @@ -1049,9 +1054,9 @@ namespace esphome uint8_t icon = this->find_icon(ic.c_str()); - if (icon >= this->icon_count) + if (icon == MAXICONS) { - ESP_LOGW(TAG, "icon %d not found => default: 0", icon); + ESP_LOGW(TAG, "icon %d/%s not found => default: 0", icon, ic.c_str()); icon = 0; for (auto *t : on_icon_error_triggers_) { @@ -1083,9 +1088,9 @@ namespace esphome uint8_t icon = this->find_icon(ic.c_str()); - if (icon >= this->icon_count) + if (icon == MAXICONS) { - ESP_LOGW(TAG, "icon %d not found => default: 0", icon); + ESP_LOGW(TAG, "icon %d/%s not found => default: 0", icon, ic.c_str()); icon = 0; for (auto *t : on_icon_error_triggers_) { @@ -1129,9 +1134,9 @@ namespace esphome uint8_t icon = this->find_icon(ic.c_str()); - if (icon >= this->icon_count) + if (icon == MAXICONS) { - ESP_LOGW(TAG, "icon %d not found => default: 0", icon); + ESP_LOGW(TAG, "icon %d/%s not found => default: 0", icon, ic.c_str()); icon = 0; for (auto *t : on_icon_error_triggers_) { @@ -1162,9 +1167,9 @@ namespace esphome uint8_t icon = this->find_icon(ic.c_str()); - if (icon >= this->icon_count) + if (icon == MAXICONS) { - ESP_LOGW(TAG, "icon %d not found => default: 0", icon); + ESP_LOGW(TAG, "icon %d/%s not found => default: 0", icon, ic.c_str()); icon = 0; for (auto *t : on_icon_error_triggers_) { @@ -1195,9 +1200,9 @@ namespace esphome uint8_t icon = this->find_icon(ic.c_str()); - if (icon >= this->icon_count) + if (icon == MAXICONS) { - ESP_LOGW(TAG, "icon %d not found => default: 0", icon); + ESP_LOGW(TAG, "icon %d/%s not found => default: 0", icon, ic.c_str()); icon = 0; for (auto *t : on_icon_error_triggers_) { @@ -1323,7 +1328,7 @@ namespace esphome { uint8_t icon = this->find_icon(iconname.c_str()); - if (icon >= this->icon_count) + if (icon == MAXICONS) { ESP_LOGW(TAG, "full screen: icon %d not found => default: 0", icon); for (auto *t : on_icon_error_triggers_) @@ -1503,7 +1508,7 @@ namespace esphome { uint8_t icon = this->find_icon(iconname.c_str()); - if (icon >= this->icon_count) + if (icon == MAXICONS) { ESP_LOGW(TAG, "graph screen with icon: icon %d not found => default: 0", icon); for (auto *t : on_icon_error_triggers_) diff --git a/components/ehmtxv2/EHMTX.h b/components/ehmtxv2/EHMTX.h index e64e93f0..005d2ede 100644 --- a/components/ehmtxv2/EHMTX.h +++ b/components/ehmtxv2/EHMTX.h @@ -21,6 +21,7 @@ const uint8_t D_LIFETIME = 5; const uint8_t D_SCREEN_TIME = 10; const uint8_t MAXICONS = 90; +const uint8_t BLANKICON = MAXICONS + 1; const uint8_t TEXTSCROLLSTART = 8; const uint8_t TEXTSTARTOFFSET = (32 - 8); diff --git a/components/ehmtxv2/EHMTX_queue.cpp b/components/ehmtxv2/EHMTX_queue.cpp index 9e4ff6aa..b4858311 100644 --- a/components/ehmtxv2/EHMTX_queue.cpp +++ b/components/ehmtxv2/EHMTX_queue.cpp @@ -233,10 +233,13 @@ namespace esphome this->config_->last_rainbow_time = millis(); } - if (millis() - this->config_->last_anim_time >= this->config_->icons[this->icon]->frame_duration) + if (this->icon < this->config_->icon_count) { - this->config_->icons[this->icon]->next_frame(); - this->config_->last_anim_time = millis(); + if (millis() - this->config_->last_anim_time >= this->config_->icons[this->icon]->frame_duration) + { + this->config_->icons[this->icon]->next_frame(); + this->config_->last_anim_time = millis(); + } } } @@ -283,7 +286,10 @@ namespace esphome else { this->config_->display->graph(8, 0, this->config_->graph); - this->config_->display->image(0, 0, this->config_->icons[this->icon]); + if (this->icon != BLANKICON) + { + this->config_->display->image(0, 0, this->config_->icons[this->icon]); + } } break; #endif @@ -418,7 +424,10 @@ namespace esphome this->config_->clock->now()); } } - this->config_->display->image(0, 0, this->config_->icons[this->icon]); + if (this->icon != BLANKICON) + { + this->config_->display->image(0, 0, this->config_->icons[this->icon]); + } this->config_->draw_day_of_week(true); if (this->icon_name.find("day") != std::string::npos || this->icon_name.find("weekday") != std::string::npos) @@ -548,7 +557,10 @@ namespace esphome if (this->mode == MODE_ICON_PROGRESS) { this->config_->display->line(8, 0, 8, 7, esphome::display::COLOR_OFF); - this->config_->display->image(0, 0, this->config_->icons[this->icon]); + if (this->icon != BLANKICON) + { + this->config_->display->image(0, 0, this->config_->icons[this->icon]); + } if (this->progress != 0) { @@ -568,13 +580,19 @@ namespace esphome { if (this->config_->display_gauge) { - this->config_->display->image(2, 0, this->config_->icons[this->icon]); + if (this->icon != BLANKICON) + { + this->config_->display->image(2, 0, this->config_->icons[this->icon]); + } this->config_->display->line(10, 0, 10, 7, esphome::display::COLOR_OFF); } else { this->config_->display->line(8, 0, 8, 7, esphome::display::COLOR_OFF); - this->config_->display->image(0, 0, this->config_->icons[this->icon]); + if (this->icon != BLANKICON) + { + this->config_->display->image(0, 0, this->config_->icons[this->icon]); + } } } break;