From e86227304d262813cfbd384169eb6a6f0927f28d Mon Sep 17 00:00:00 2001 From: LuBeDa Date: Sat, 20 May 2023 19:20:34 +0200 Subject: [PATCH] slightky working --- components/ehmtxv2/EHMTX.cpp | 80 ++++++++++++++++++------------ components/ehmtxv2/EHMTX.h | 6 +-- components/ehmtxv2/EHMTX_queue.cpp | 4 +- 3 files changed, 52 insertions(+), 38 deletions(-) diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index e142ff2..4b9d43a 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -20,7 +20,7 @@ namespace esphome this->alarm_color = Color(CA_RED, CA_GREEN, CA_BLUE); this->gauge_color = Color(CD_RED, CD_GREEN, CD_BLUE); this->gauge_value = 0; - this->screen_pointer = 0; + this->screen_pointer = MAXQUEUE; for (uint8_t i = 0; i < MAXQUEUE; i++) { @@ -194,6 +194,7 @@ namespace esphome register_service(&EHMTX::set_brightness, "brightness", {"value"}); ESP_LOGD(TAG, "Setup and running!"); + this->is_running = true; } void EHMTX::show_alarm(int r, int g, int b, int size) @@ -228,9 +229,9 @@ namespace esphome { if (!this->is_running) { - if (this->clock->is_valid()) + if (this->clock->now().is_valid()) { - ESP_LOGD(TAG, "time sync => starting"); + ESP_LOGD(TAG, "time sync => start running"); this->is_running = true; } } @@ -288,9 +289,9 @@ namespace esphome time_t ts = this->clock->now().timestamp; for (size_t i = 0; i < MAXQUEUE; i++) { - if ((this->queue[i]->mode == MODE_CLOCK)||(this->queue[i]->mode == MODE_RAINBOW_CLOCK)) + if ((this->queue[i]->mode == MODE_CLOCK) || (this->queue[i]->mode == MODE_RAINBOW_CLOCK)) { - if (ts > (this->queue[i]->last_time + this->clock_interval)) + if (ts > (this->queue[i]->last_time + this->clock_interval)) { hit = i; } @@ -355,7 +356,7 @@ namespace esphome } void EHMTX::tick() { - this->hue_++; + this->hue_++; if (this->hue_ == 360) { this->hue_ = 0; @@ -363,24 +364,6 @@ namespace esphome float red, green, blue; esphome::hsv_to_rgb(this->hue_, 0.8, 0.8, red, green, blue); this->rainbow_color = Color(uint8_t(255 * red), uint8_t(255 * green), uint8_t(255 * blue)); - - this->scroll_step++; - - switch (this->queue[this->screen_pointer]->mode) - { - case MODE_ICON_SCREEN: - case MODE_RAINBOW_ICON: - if (this->scroll_step > this->queue[this->screen_pointer]->pixels_ + 8) { - this->scroll_step = 0; - } - break; - case MODE_RAINBOW_TEXT: - case MODE_TEXT_SCREEN: - if (this->scroll_step > this->queue[this->screen_pointer]->pixels_ + 31) { - this->scroll_step = 0; - } - break; - } time_t ts = this->clock->now().timestamp; @@ -388,16 +371,37 @@ namespace esphome { if (ts > this->next_action_time) { + this->scroll_step++; + this->remove_expired_queue_element(); this->screen_pointer = this->find_last_clock(); if (this->screen_pointer == MAXQUEUE) { this->screen_pointer = find_oldest_queue_element(); } + switch (this->queue[this->screen_pointer]->mode) + { + case MODE_ICON_SCREEN: + case MODE_RAINBOW_ICON: + if (this->scroll_step > this->queue[this->screen_pointer]->pixels_ + 8) + { + this->scroll_step = 0; + } + break; + case MODE_RAINBOW_TEXT: + case MODE_TEXT_SCREEN: + if (this->scroll_step > this->queue[this->screen_pointer]->pixels_ + 31) + { + this->scroll_step = 0; + } + break; + } + ESP_LOGD(TAG, "tick action Pointer: %d",this->screen_pointer); + if (this->screen_pointer != MAXQUEUE) { this->queue[this->screen_pointer]->shiftx_ = 0; - this->scroll_step=0; + this->scroll_step = 0; this->queue[this->screen_pointer]->last_time = ts + this->queue[this->screen_pointer]->screen_time_; if (this->queue[this->screen_pointer]->icon < this->icon_count) { @@ -431,6 +435,7 @@ namespace esphome } else { + ESP_LOGD(TAG, "tick rectangle %d", this->is_running); uint8_t w = (1 + (uint8_t)(32 / 16) * (this->boot_anim / 16)) % 32; this->display->rectangle(0, 2, w, 4, this->rainbow_color); // Color(120, 190, 40)); this->boot_anim++; @@ -565,7 +570,7 @@ namespace esphome screen->mode = MODE_ICON_SCREEN; screen->icon_name = iconname; screen->icon = icon; - screen->calc_scroll_time(text,screen_time); + screen->calc_scroll_time(text, screen_time); for (auto *t : on_add_screen_triggers_) { t->process(screen->icon_name, (uint8_t)screen->mode); @@ -588,15 +593,15 @@ namespace esphome } } EHMTX_queue *screen = this->find_icon_queue_element(icon); - + screen->text = text; - + screen->endtime = this->clock->now().timestamp + lifetime * 60; screen->default_font = default_font; screen->mode = MODE_RAINBOW_ICON; screen->icon_name = iconname; screen->icon = icon; - screen->calc_scroll_time(text,screen_time); + screen->calc_scroll_time(text, screen_time); for (auto *t : on_add_screen_triggers_) { t->process(screen->icon_name, (uint8_t)screen->mode); @@ -612,7 +617,7 @@ namespace esphome ESP_LOGD(TAG, "rainbow_clock_screen lifetime: %d screen_time: %d", lifetime, screen_time); screen->mode = MODE_RAINBOW_CLOCK; screen->default_font = default_font; - screen->screen_time_ = (screen_time > this->clock_interval)?screen_time:this->clock_interval-1; + screen->screen_time_ = (screen_time > this->clock_interval) ? screen_time : this->clock_interval - 1; screen->endtime = this->clock->now().timestamp + lifetime * 60; screen->status(); } @@ -638,7 +643,7 @@ namespace esphome screen->default_font = default_font; screen->text_color = Color(r, g, b); screen->mode = MODE_TEXT_SCREEN; - screen->calc_scroll_time(text,screen_time); + screen->calc_scroll_time(text, screen_time); screen->status(); } @@ -649,7 +654,7 @@ namespace esphome screen->endtime = this->clock->now().timestamp + lifetime * 60; screen->default_font = default_font; screen->mode = MODE_RAINBOW_TEXT; - screen->calc_scroll_time(text,screen_time); + screen->calc_scroll_time(text, screen_time); screen->status(); } @@ -689,7 +694,11 @@ namespace esphome ESP_LOGD(TAG, "clock_screen_color lifetime: %d screen_time: %d red: %d green: %d blue: %d", lifetime, screen_time, r, g, b); screen->mode = MODE_CLOCK; screen->default_font = default_font; - screen->screen_time_ = (this->clock_interval > screen_time )?screen_time:this->clock_interval-1; + if (this->clock_interval ==0 || (this->clock_interval > screen_time )) { + screen->screen_time_ = screen_time; + } else { + screen->screen_time_ = this->clock_interval-2; + } screen->endtime = this->clock->now().timestamp + lifetime * 60; screen->status(); } @@ -885,6 +894,10 @@ namespace esphome { ESP_LOGCONFIG(TAG, "show date"); } + if (this->rtl) + { + ESP_LOGCONFIG(TAG, "RTL activated"); + } if (this->week_starts_monday) { ESP_LOGCONFIG(TAG, "weekstart: monday"); @@ -893,6 +906,7 @@ namespace esphome { ESP_LOGCONFIG(TAG, "weekstart: sunday"); } + this->is_running = true; } void EHMTX::add_icon(EHMTX_Icon *icon) diff --git a/components/ehmtxv2/EHMTX.h b/components/ehmtxv2/EHMTX.h index f01855b..252c832 100644 --- a/components/ehmtxv2/EHMTX.h +++ b/components/ehmtxv2/EHMTX.h @@ -20,7 +20,7 @@ const uint8_t MAXICONS = 90; const uint8_t TEXTSCROLLSTART = 8; const uint8_t TEXTSTARTOFFSET = (32 - 8); -const uint16_t POLLINGINTERVAL = 800; +const uint16_t POLLINGINTERVAL = 1000; 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_ICON_SCREEN = 5, MODE_TEXT_SCREEN = 6 , MODE_RAINBOW_ICON = 7,MODE_RAINBOW_TEXT = 8, MODE_RAINBOW_CLOCK = 9,MODE_RAINBOW_DATE=10 }; @@ -37,7 +37,7 @@ namespace esphome class EHMTX : public PollingComponent, public api::CustomAPIDevice { protected: - float get_setup_priority() const override { return esphome::setup_priority::PROCESSOR; } + float get_setup_priority() const override { return esphome::setup_priority::BEFORE_CONNECTION; } uint8_t brightness_; uint32_t boot_anim=0; uint8_t screen_pointer; @@ -57,7 +57,7 @@ namespace esphome EHMTX(); Color text_color, alarm_color, gauge_color,indicator_color,clock_color; Color today_color,weekday_color,rainbow_color; - int hue_; + uint16_t hue_=0; void dump_config(); std::string time_fmt; std::string date_fmt; diff --git a/components/ehmtxv2/EHMTX_queue.cpp b/components/ehmtxv2/EHMTX_queue.cpp index 0b0fdc6..0afdc59 100644 --- a/components/ehmtxv2/EHMTX_queue.cpp +++ b/components/ehmtxv2/EHMTX_queue.cpp @@ -172,7 +172,7 @@ namespace esphome break; case MODE_RAINBOW_CLOCK: case MODE_CLOCK: - if (this->config_->clock->now().timestamp > 6000) // valid time + if (this->config_->clock->now().is_valid()) // valid time { color_ = (this->mode == MODE_RAINBOW_CLOCK) ? this->config_->rainbow_color : this->config_->clock_color; time_t ts = this->config_->clock->now().timestamp; @@ -194,7 +194,7 @@ namespace esphome break; case MODE_RAINBOW_DATE: case MODE_DATE: - if (this->config_->clock->now().timestamp > 6000) // valid time + if (this->config_->clock->now().is_valid()) { color_ = (this->mode == MODE_RAINBOW_DATE) ? this->config_->rainbow_color : this->config_->clock_color; time_t ts = this->config_->clock->now().timestamp;