From adc4d327093fb25f4e77dc2b8553060fad0a3d20 Mon Sep 17 00:00:00 2001 From: "Andrew J.Swan" Date: Thu, 12 Oct 2023 09:57:58 +0300 Subject: [PATCH 1/3] 2023.9.1-90: Add Graph with icon https://github.com/lubeda/EspHoMaTriXv2/issues/90#issuecomment-1737217802 --- components/ehmtxv2/EHMTX.cpp | 40 ++++++++++++++++++++++++++++++ components/ehmtxv2/EHMTX.h | 3 ++- components/ehmtxv2/EHMTX_queue.cpp | 10 +++++++- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index 8250a2b3..c1e6e022 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -410,6 +410,7 @@ namespace esphome register_service(&EHMTX::icon_date, "icon_date", {"icon_name", "lifetime", "screen_time", "default_font", "r", "g", "b"}); #ifdef USE_GRAPH register_service(&EHMTX::graph_screen, "graph_screen", {"lifetime", "screen_time"}); + register_service(&EHMTX::icon_graph_screen, "icon_graph_screen", {"licon_name, ifetime", "screen_time"}); #endif register_service(&EHMTX::rainbow_icon_screen, "rainbow_icon_screen", {"icon_name", "text", "lifetime", "screen_time", "default_font"}); @@ -1425,11 +1426,50 @@ namespace esphome screen->endtime = this->clock->now().timestamp + lifetime * 60; screen->mode = MODE_GRAPH_SCREEN; + screen->icon = MAXICONS; screen->screen_time_ = screen_time; + + this->graph->set_height(8); + this->graph->set_width(32); + + for (auto *t : on_add_screen_triggers_) + { + t->process("graph", (uint8_t)screen->mode); + } + screen->status(); + } + + void EHMTX::icon_graph_screen(std::string iconname, int lifetime, int screen_time) + { + uint8_t icon = this->find_icon(iconname.c_str()); + + if (icon >= this->icon_count) + { + ESP_LOGW(TAG, "graph screen with icon: icon %d not found => default: 0", icon); + for (auto *t : on_icon_error_triggers_) + { + t->process(iconname); + } + graph_screen(lifetime, screen_time); + return; + } + + EHMTX_queue *screen = this->find_mode_queue_element(MODE_GRAPH_SCREEN); + + screen->endtime = this->clock->now().timestamp + lifetime * 60; + screen->mode = MODE_GRAPH_SCREEN; + screen->icon = icon; + screen->icon_name = iconname; + screen->screen_time_ = screen_time; + + this->graph->set_height(8); + this->graph->set_width(24); + for (auto *t : on_add_screen_triggers_) { t->process("graph", (uint8_t)screen->mode); } + ESP_LOGD(TAG, "graph screen with icon: icon: %d iconname: %s lifetime: %d screen_time:%d ", icon, iconname.c_str(), lifetime, screen_time); screen->status(); } diff --git a/components/ehmtxv2/EHMTX.h b/components/ehmtxv2/EHMTX.h index b65e695d..866393b1 100644 --- a/components/ehmtxv2/EHMTX.h +++ b/components/ehmtxv2/EHMTX.h @@ -128,7 +128,8 @@ namespace esphome addressable_light::AddressableLightDisplay *display; esphome::time::RealTimeClock *clock; #ifdef USE_GRAPH - void graph_screen(int lifetime = 2 , int screen_time = 20); + void graph_screen(int lifetime = D_LIFETIME, int screen_time = D_SCREEN_TIME); + void icon_graph_screen(std::string icon, int lifetime = D_LIFETIME, int screen_time = D_SCREEN_TIME); graph::Graph *graph; #endif diff --git a/components/ehmtxv2/EHMTX_queue.cpp b/components/ehmtxv2/EHMTX_queue.cpp index cc06e61a..6953f400 100644 --- a/components/ehmtxv2/EHMTX_queue.cpp +++ b/components/ehmtxv2/EHMTX_queue.cpp @@ -270,7 +270,15 @@ namespace esphome #ifdef USE_GRAPH case MODE_GRAPH_SCREEN: - this->config_->display->graph(0,0, this->config_->graph); + if (this->icon == MAXICONS) + { + this->config_->display->graph(0, 0, this->config_->graph); + } + else + { + this->config_->display->graph(8, 0, this->config_->graph); + this->config_->display->image(0, 0, this->config_->icons[this->icon]); + } break; #endif From 1b1463967e170e18a1161225435736bef5e33554 Mon Sep 17 00:00:00 2001 From: "Andrew J.Swan" Date: Thu, 12 Oct 2023 09:59:51 +0300 Subject: [PATCH 2/3] 2023.9.1-90: Graph with icon --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d3c825a..8d7292a8 100644 --- a/README.md +++ b/README.md @@ -757,7 +757,8 @@ Numerous features are accessible with services from home assistant and lambdas t |`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| |`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| +|`graph_screen`|"lifetime", "screen_time"|show graph as defined in the YAML file| +|`icon_graph_screen`|"icon_name", "lifetime", "screen_time"|show the specified icon with graph as defined in the YAML file| |`set_infotext_color`|"left_r", "left_g", "left_b", "right_r", "right_g", "right_b","default_font","y_offset"|set the special color for left and right char on info text| #### Parameter description From cf1a34d0727f3b710bc3c4750763f3306f7d3ccf Mon Sep 17 00:00:00 2001 From: "Andrew J.Swan" Date: Thu, 12 Oct 2023 12:54:21 +0300 Subject: [PATCH 3/3] 2023.9.1-90: Fix typo --- components/ehmtxv2/EHMTX.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index c1e6e022..a22a3149 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -410,7 +410,7 @@ namespace esphome register_service(&EHMTX::icon_date, "icon_date", {"icon_name", "lifetime", "screen_time", "default_font", "r", "g", "b"}); #ifdef USE_GRAPH register_service(&EHMTX::graph_screen, "graph_screen", {"lifetime", "screen_time"}); - register_service(&EHMTX::icon_graph_screen, "icon_graph_screen", {"licon_name, ifetime", "screen_time"}); + register_service(&EHMTX::icon_graph_screen, "icon_graph_screen", {"icon_name", "lifetime", "screen_time"}); #endif register_service(&EHMTX::rainbow_icon_screen, "rainbow_icon_screen", {"icon_name", "text", "lifetime", "screen_time", "default_font"});