From 421a8badf8ddf4853d0dc85360fa3a15f35df42d Mon Sep 17 00:00:00 2001 From: "Andrew J.Swan" Date: Mon, 23 Oct 2023 12:50:50 +0300 Subject: [PATCH] 2023.9.1-117: Add a pseudo-icon - blank --- README.md | 1 + components/ehmtxv2/EHMTX.cpp | 28 ++++++++++++++-------------- components/ehmtxv2/EHMTX.h | 6 +++--- components/ehmtxv2/EHMTX_queue.cpp | 19 +++++++++++-------- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index a16fd0e0..751b3499 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 diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index 067c5f1b..8147ee4d 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -1016,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_) { @@ -1054,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_) { @@ -1088,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_) { @@ -1134,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_) { @@ -1167,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_) { @@ -1200,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_) { @@ -1328,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_) @@ -1508,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 c85f3a0c..005d2ede 100644 --- a/components/ehmtxv2/EHMTX.h +++ b/components/ehmtxv2/EHMTX.h @@ -20,8 +20,8 @@ const uint8_t C_BLACK = 0; const uint8_t D_LIFETIME = 5; const uint8_t D_SCREEN_TIME = 10; -const uint8_t BLANKICON = -1; -const uint8_t MAXICONS = 90; // Max 127 icon due int8_t +const uint8_t MAXICONS = 90; +const uint8_t BLANKICON = MAXICONS + 1; const uint8_t TEXTSCROLLSTART = 8; const uint8_t TEXTSTARTOFFSET = (32 - 8); @@ -261,7 +261,7 @@ namespace esphome bool default_font; time_t endtime; time_t last_time; - int8_t icon; + uint8_t icon; uint16_t scroll_reset; show_mode mode; int8_t progress; diff --git a/components/ehmtxv2/EHMTX_queue.cpp b/components/ehmtxv2/EHMTX_queue.cpp index 69e5b9cb..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,7 @@ namespace esphome else { this->config_->display->graph(8, 0, this->config_->graph); - if (this->icon > BLANKICON) + if (this->icon != BLANKICON) { this->config_->display->image(0, 0, this->config_->icons[this->icon]); } @@ -421,7 +424,7 @@ namespace esphome this->config_->clock->now()); } } - if (this->icon > BLANKICON) + if (this->icon != BLANKICON) { this->config_->display->image(0, 0, this->config_->icons[this->icon]); } @@ -554,7 +557,7 @@ namespace esphome if (this->mode == MODE_ICON_PROGRESS) { this->config_->display->line(8, 0, 8, 7, esphome::display::COLOR_OFF); - if (this->icon > BLANKICON) + if (this->icon != BLANKICON) { this->config_->display->image(0, 0, this->config_->icons[this->icon]); } @@ -577,7 +580,7 @@ namespace esphome { if (this->config_->display_gauge) { - if (this->icon > BLANKICON) + if (this->icon != BLANKICON) { this->config_->display->image(2, 0, this->config_->icons[this->icon]); } @@ -586,7 +589,7 @@ namespace esphome else { this->config_->display->line(8, 0, 8, 7, esphome::display::COLOR_OFF); - if (this->icon > BLANKICON) + if (this->icon != BLANKICON) { this->config_->display->image(0, 0, this->config_->icons[this->icon]); }