From d6127445260fa1f02a44e990544f42d41a7b05db Mon Sep 17 00:00:00 2001 From: "Andrew J.Swan" Date: Thu, 5 Oct 2023 12:04:22 +0300 Subject: [PATCH] 2023.9.1: Ability to change the direction of the progress color gradient Progress in MODE_ICON_PROGRESS screen: - 0 .. -100 - from Green to Red - 0 .. 100 - from Red to Green --- components/ehmtxv2/EHMTX.cpp | 2 +- components/ehmtxv2/EHMTX_queue.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index eb98b092..295fa7aa 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -894,7 +894,7 @@ namespace esphome screen->mode = MODE_ICON_PROGRESS; screen->icon_name = id; screen->icon = icon; - screen->progress = (progress > 100) ? 100 : progress; + screen->progress = (progress > 100) ? 100 : (progress < -100) ? -100 : progress; screen->calc_scroll_time(text, screen_time); for (auto *t : on_add_screen_triggers_) { diff --git a/components/ehmtxv2/EHMTX_queue.cpp b/components/ehmtxv2/EHMTX_queue.cpp index 528cf6e2..05097c37 100644 --- a/components/ehmtxv2/EHMTX_queue.cpp +++ b/components/ehmtxv2/EHMTX_queue.cpp @@ -414,13 +414,13 @@ namespace esphome #endif if (this->mode == MODE_ICON_PROGRESS) { - if (this->progress >= 0) - { - this->config_->display->line(8, 0, 8, 7, esphome::display::COLOR_OFF); - this->config_->display->image(0, 0, this->config_->icons[this->icon]); + this->config_->display->line(8, 0, 8, 7, esphome::display::COLOR_OFF); + this->config_->display->image(0, 0, this->config_->icons[this->icon]); - color_ = esphome::light::ESPHSVColor(this->progress * 120 / 100, 240, 240).to_rgb(); - this->config_->display->line(9, 7, 9 + this->progress * 22 / 100, 7, color_); + if (this->progress != 0) + { + color_ = esphome::light::ESPHSVColor(this->progress * 120 / 100 + (this->progress < 0 ? 120 : 0), 240, 240).to_rgb(); + this->config_->display->line(9, 7, 9 + abs(this->progress) * 22 / 100, 7, color_); } } else