From cb7cdd4341ae46d1e7b7afd415884be728560401 Mon Sep 17 00:00:00 2001 From: LuBeDa Date: Sat, 20 May 2023 16:38:03 +0200 Subject: [PATCH 1/6] Revert "remove shiftx_" This reverts commit 4720583311f6700e10589a130d65c697cfbf5af1. --- components/ehmtxv2/EHMTX.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index 45c3945..e142ff2 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -228,7 +228,7 @@ namespace esphome { if (!this->is_running) { - if (this->clock->now().timestamp > 15) + if (this->clock->is_valid()) { ESP_LOGD(TAG, "time sync => starting"); this->is_running = true; @@ -238,12 +238,6 @@ namespace esphome void EHMTX::force_screen(std::string icon_name, int mode) { - // if (this->string_has_ending(icon_name, "*")) - // { - // // remove the * - // icon_name = icon_name.substr(0, icon_name.length() - 1); - // } - for (uint8_t i = 0; i < MAXQUEUE; i++) { if (this->queue[i]->mode == mode) From e86227304d262813cfbd384169eb6a6f0927f28d Mon Sep 17 00:00:00 2001 From: LuBeDa Date: Sat, 20 May 2023 19:20:34 +0200 Subject: [PATCH 2/6] 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; From 6c7015752f6b09ba318aba19a11671956845bfcf Mon Sep 17 00:00:00 2001 From: LuBeDa Date: Sat, 20 May 2023 19:50:44 +0200 Subject: [PATCH 3/6] ulanzi problems --- README.md | 6 ++++-- components/ehmtxv2/EHMTX.cpp | 3 +-- components/ehmtxv2/EHMTX.h | 2 +- copy2esphome/ulanzi-easy.yaml | 18 ------------------ tests/ulanzi-easy.yaml | 18 ------------------ 5 files changed, 6 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index d2598c3..e9d4352 100644 --- a/README.md +++ b/README.md @@ -1032,7 +1032,9 @@ sensor: ## Breaking changes -### **nothing yet, since it is new** +### 2023.5.0 + +- removed the rtttl buzzer from the ulanzi easy template, because it often caused reboots! ## EspHoMaTriX in the media @@ -1065,7 +1067,7 @@ THE SOFTWARE IS PROVIDED "AS IS", use at your own risk! - **[aptonline](https://github.com/aptonline)** for his work on the ulanzi hardware - **[wsbtak](https://github.com/wsbtak)** for the work on the ulanzi hardware - **[ofirsnb](https://github.com/ofirsnb)** for his contributions -- **[darkpoet78](https://github.com/darkpoet78/MatrixClockFonts)** for his work on optimized fonts +- **[darkpoet78](https://github.com/darkpoet78/MatrixClockFonts)** for his work on optimized fonts and user support - **[pplucky](https://user-images.githubusercontent.com/16407309/224850723-634c9b2d-55d9-44f2-9f93-765c0485b090.GIF)** for his 8x32 GIF animation - **[dennisse](https://github.com/dennisse)** Auto brightness for the Ulanzi - **[geekofweek](https://github.com/geekofweek)** fixed sample YAML diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index 4b9d43a..dd6803e 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -20,6 +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->next_action_time = 0; this->screen_pointer = MAXQUEUE; for (uint8_t i = 0; i < MAXQUEUE; i++) @@ -194,7 +195,6 @@ 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) @@ -906,7 +906,6 @@ 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 252c832..0a0e993 100644 --- a/components/ehmtxv2/EHMTX.h +++ b/components/ehmtxv2/EHMTX.h @@ -37,7 +37,7 @@ namespace esphome class EHMTX : public PollingComponent, public api::CustomAPIDevice { protected: - float get_setup_priority() const override { return esphome::setup_priority::BEFORE_CONNECTION; } + float get_setup_priority() const override { return esphome::setup_priority::WIFI; } uint8_t brightness_; uint32_t boot_anim=0; uint8_t screen_pointer; diff --git a/copy2esphome/ulanzi-easy.yaml b/copy2esphome/ulanzi-easy.yaml index 1a2a49f..e42d99f 100644 --- a/copy2esphome/ulanzi-easy.yaml +++ b/copy2esphome/ulanzi-easy.yaml @@ -1,7 +1,5 @@ substitutions: devicename: ulanzi - ledpin: GPIO32 - buzzerpin: GPIO15 friendly_name: LED Matrix board: esp32dev # Pin definition from https://github.com/aptonline/PixelIt_Ulanzi @@ -11,7 +9,6 @@ substitutions: left_button_pin: GPIO26 mid_button_pin: GPIO27 right_button_pin: GPIO14 - buzzer_pin: GPIO15 scl_pin: GPIO22 sda_pin: GPIO21 @@ -99,13 +96,6 @@ logger: level: WARN api: - services: - - service: tune - variables: - tune: string - then: - - rtttl.play: - rtttl: !lambda 'return tune;' sensor: - platform: sht3xd @@ -168,14 +158,6 @@ wifi: web_server: -output: - - platform: ledc - pin: $buzzerpin - id: rtttl_out - -rtttl: - output: rtttl_out - i2c: sda: $sda_pin scl: $scl_pin diff --git a/tests/ulanzi-easy.yaml b/tests/ulanzi-easy.yaml index 1a2a49f..e42d99f 100644 --- a/tests/ulanzi-easy.yaml +++ b/tests/ulanzi-easy.yaml @@ -1,7 +1,5 @@ substitutions: devicename: ulanzi - ledpin: GPIO32 - buzzerpin: GPIO15 friendly_name: LED Matrix board: esp32dev # Pin definition from https://github.com/aptonline/PixelIt_Ulanzi @@ -11,7 +9,6 @@ substitutions: left_button_pin: GPIO26 mid_button_pin: GPIO27 right_button_pin: GPIO14 - buzzer_pin: GPIO15 scl_pin: GPIO22 sda_pin: GPIO21 @@ -99,13 +96,6 @@ logger: level: WARN api: - services: - - service: tune - variables: - tune: string - then: - - rtttl.play: - rtttl: !lambda 'return tune;' sensor: - platform: sht3xd @@ -168,14 +158,6 @@ wifi: web_server: -output: - - platform: ledc - pin: $buzzerpin - id: rtttl_out - -rtttl: - output: rtttl_out - i2c: sda: $sda_pin scl: $scl_pin From 31024249c917d1adb38bc8b4a2b3a0fcc8e6b267 Mon Sep 17 00:00:00 2001 From: LuBeDa Date: Sat, 20 May 2023 20:24:11 +0200 Subject: [PATCH 4/6] remove shiftx --- README.md | 2 +- components/ehmtxv2/EHMTX.cpp | 100 ++++++++++++++--------------- components/ehmtxv2/EHMTX.h | 5 +- components/ehmtxv2/EHMTX_queue.cpp | 48 ++++---------- 4 files changed, 63 insertions(+), 92 deletions(-) diff --git a/README.md b/README.md index e9d4352..fae1834 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ## Important information -If you like my work, please donate me a star on GitHub and consider sponsoring me!! +If you like my work, please donate me a star on GitHub and consider [sponsoring](https://www.paypal.com/donate/?hosted_button_id=FZDKSLQ46HJTU) me!! ## Introduction diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index dd6803e..941ad6a 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -354,6 +354,7 @@ namespace esphome } } } + void EHMTX::tick() { this->hue_++; @@ -371,75 +372,62 @@ 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) + if (millis() - this->last_scroll_time >= this->scroll_interval) { - case MODE_ICON_SCREEN: - case MODE_RAINBOW_ICON: - if (this->scroll_step > this->queue[this->screen_pointer]->pixels_ + 8) + this->scroll_step++; + this->last_scroll_time = millis(); + + if (this->scroll_step > this->queue[this->screen_pointer]->pixels_ + 32) { this->scroll_step = 0; } - break; - case MODE_RAINBOW_TEXT: - case MODE_TEXT_SCREEN: - if (this->scroll_step > this->queue[this->screen_pointer]->pixels_ + 31) + if (this->screen_pointer != MAXQUEUE) { 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->queue[this->screen_pointer]->last_time = ts + this->queue[this->screen_pointer]->screen_time_; - if (this->queue[this->screen_pointer]->icon < this->icon_count) - { - this->icons[this->queue[this->screen_pointer]->icon]->set_frame(0); - } - this->next_action_time = this->queue[this->screen_pointer]->last_time; - // Todo switch for Triggers - if (this->queue[this->screen_pointer]->mode == MODE_CLOCK) - { - for (auto *t : on_next_clock_triggers_) + 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) + { + this->icons[this->queue[this->screen_pointer]->icon]->set_frame(0); + } + this->next_action_time = this->queue[this->screen_pointer]->last_time; + // Todo switch for Triggers + if (this->queue[this->screen_pointer]->mode == MODE_CLOCK) + { + for (auto *t : on_next_clock_triggers_) + { + t->process(); + } + } + else { - t->process(); + for (auto *t : on_next_screen_triggers_) + { + t->process(this->queue[this->screen_pointer]->icon_name, this->queue[this->screen_pointer]->text); + } } } else { - for (auto *t : on_next_screen_triggers_) - { - t->process(this->queue[this->screen_pointer]->icon_name, this->queue[this->screen_pointer]->text); - } + ESP_LOGW(TAG, "tick: nothing to do. Restarting clock display!"); + this->clock_screen(24 * 60, this->clock_time, false, C_RED, C_GREEN, C_BLUE); + this->date_screen(24 * 60, (int)this->clock_time / 2, false, C_RED, C_GREEN, C_BLUE); + this->next_action_time = ts + this->clock_time; } } - else - { - ESP_LOGW(TAG, "tick: nothing to do. Restarting clock display!"); - this->clock_screen(24 * 60, this->clock_time, false, C_RED, C_GREEN, C_BLUE); - this->date_screen(24 * 60, (int)this->clock_time / 2, false, C_RED, C_GREEN, C_BLUE); - this->next_action_time = ts + this->clock_time; - } } } 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++; - } + { + 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++; + } } void EHMTX::skip_screen() @@ -617,7 +605,14 @@ 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; + 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(); } @@ -694,10 +689,13 @@ 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; - if (this->clock_interval ==0 || (this->clock_interval > screen_time )) { + if (this->clock_interval == 0 || (this->clock_interval > screen_time)) + { screen->screen_time_ = screen_time; - } else { - screen->screen_time_ = this->clock_interval-2; + } + else + { + screen->screen_time_ = this->clock_interval - 2; } screen->endtime = this->clock->now().timestamp + lifetime * 60; screen->status(); diff --git a/components/ehmtxv2/EHMTX.h b/components/ehmtxv2/EHMTX.h index 0a0e993..c475da7 100644 --- a/components/ehmtxv2/EHMTX.h +++ b/components/ehmtxv2/EHMTX.h @@ -37,7 +37,7 @@ namespace esphome class EHMTX : public PollingComponent, public api::CustomAPIDevice { protected: - float get_setup_priority() const override { return esphome::setup_priority::WIFI; } + float get_setup_priority() const override { return esphome::setup_priority::BEFORE_CONNECTION; } uint8_t brightness_; uint32_t boot_anim=0; uint8_t screen_pointer; @@ -109,7 +109,7 @@ namespace esphome void skip_screen(); void hold_screen(int t=30); void set_display(addressable_light::AddressableLightDisplay *disp); - void set_clock_interval(uint16_t t=60); + void set_clock_interval(uint16_t t=90); void set_hold_time(uint16_t t=30); void set_clock_time(uint16_t t=10); void set_show_day_of_week(bool b); @@ -176,7 +176,6 @@ namespace esphome public: uint8_t centerx_; - uint16_t shiftx_; uint16_t pixels_; uint16_t screen_time_; bool default_font; diff --git a/components/ehmtxv2/EHMTX_queue.cpp b/components/ehmtxv2/EHMTX_queue.cpp index 0afdc59..a7124ab 100644 --- a/components/ehmtxv2/EHMTX_queue.cpp +++ b/components/ehmtxv2/EHMTX_queue.cpp @@ -9,7 +9,6 @@ namespace esphome this->endtime = 0; this->last_time = 0; this->centerx_ = 0; - this->shiftx_ = 0; this->screen_time_ = 0; this->mode = MODE_EMPTY; this->icon_name = ""; @@ -76,7 +75,7 @@ namespace esphome // no correction break; } - + if (this->config_->display_gauge) { startx += 2; @@ -91,7 +90,7 @@ namespace esphome } else { - return startx + this->shiftx_; + return startx + this->config_->scroll_step; } } else @@ -102,7 +101,7 @@ namespace esphome } else { - return startx - this->shiftx_ + width; + return startx - this->config_->scroll_step + width; } } } @@ -122,32 +121,6 @@ namespace esphome this->config_->last_rainbow_time = millis(); } - if ((this->mode == MODE_ICON_SCREEN) || (this->mode == MODE_RAINBOW_ICON)) - { - if (millis() - this->config_->last_scroll_time >= this->config_->scroll_interval && this->pixels_ > TEXTSTARTOFFSET) - { - this->shiftx_++; - if (this->shiftx_ > this->pixels_ + TEXTSTARTOFFSET) - { - this->shiftx_ = 0; - } - this->config_->last_scroll_time = millis(); - } - } - if ((this->mode == MODE_TEXT_SCREEN) || (this->mode == MODE_RAINBOW_TEXT)) - { - if (millis() - this->config_->last_scroll_time >= this->config_->scroll_interval && this->pixels_ >= 32) - { - this->shiftx_++; - if (this->shiftx_ > this->pixels_ + 32) - { - this->shiftx_ = 0; - - } - this->config_->last_scroll_time = millis(); - } - } - if (millis() - this->config_->last_anim_time >= this->config_->icons[this->icon]->frame_duration) { this->config_->icons[this->icon]->next_frame(); @@ -194,7 +167,7 @@ namespace esphome break; case MODE_RAINBOW_DATE: case MODE_DATE: - if (this->config_->clock->now().is_valid()) + 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; @@ -230,13 +203,15 @@ namespace esphome } color_ = (this->mode == MODE_RAINBOW_ICON) ? this->config_->rainbow_color : this->text_color; - if (this->config_->rtl) { + if (this->config_->rtl) + { this->config_->display->print(this->xpos() + xoffset, yoffset, font, color_, esphome::display::TextAlign::BASELINE_RIGHT, - this->text.c_str()); + this->text.c_str()); } - else { + else + { this->config_->display->print(this->xpos() + xoffset, yoffset, font, color_, esphome::display::TextAlign::BASELINE_LEFT, - this->text.c_str()); + this->text.c_str()); } if (this->config_->display_gauge) { @@ -295,12 +270,11 @@ namespace esphome this->pixels_ = w; this->centerx_ = 0; - this->shiftx_ = 0; switch (this->mode) { case MODE_RAINBOW_TEXT: - case MODE_TEXT_SCREEN: + case MODE_TEXT_SCREEN: if (this->pixels_ < 32) { this->screen_time_ = screen_time; From 67699e952eda9dd77d1e9cd1cf4d5c2f4ca7b358 Mon Sep 17 00:00:00 2001 From: LuBeDa Date: Sat, 20 May 2023 21:31:39 +0200 Subject: [PATCH 5/6] removed shiftx --- TODO.md | 11 +++-- components/ehmtxv2/EHMTX.cpp | 76 ++++++++++++++++-------------- components/ehmtxv2/EHMTX.h | 3 +- components/ehmtxv2/EHMTX_queue.cpp | 28 +++++++---- 4 files changed, 68 insertions(+), 50 deletions(-) diff --git a/TODO.md b/TODO.md index e990520..25e8427 100644 --- a/TODO.md +++ b/TODO.md @@ -2,17 +2,18 @@ ## function +- [ ] screen_time on ms sec base +- [ ] scroll left to right +- [ ] seconds point moveable - [x] alarm on all screens but full screen - [x] indicator on all screens but full screen and clock - [x] refreshing an icon screen should extend the display time -- [ ] scroll left to right - [x] size of indicator and alarm - [x] center text - [x] alarm independent of screen - [x] del_screen with * and filter by type, do delete all clocks etc. - [x] force_screen with * and filter by type, do delete all clocks etc. - [x] gauge with color and del_gaugeall clocks etc. -- [ ] seconds point moveable - [x] seconds point to clock screen only - [x] rainbow icon and text - [x] del_slot still active? @@ -22,16 +23,16 @@ ## user experience - [ ] blueprints -- [x] Color in blueprints -- [ ] all modes in one blueprint - [ ] external HTML with more blueprint helpers (icons and modes) +- [ ] ~~all modes in one blueprint~~ +- [x] Color in blueprints - [x] default values for all functions - [x] provide sample font from [url](https://www.pentacom.jp/pentacom/bitfontmaker2/) - [x] start animation ## style -- [ ] in screen rename text_color to color +- [x] ~~in screen rename text_color to color~~ - [x] default_font before alarm parameter - [x] screen_time instead of showtime - [x] lifetime instead of durations diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index 941ad6a..e11d3b2 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -21,6 +21,7 @@ namespace esphome this->gauge_color = Color(CD_RED, CD_GREEN, CD_BLUE); this->gauge_value = 0; this->next_action_time = 0; + this->last_scroll_time = 0; this->screen_pointer = MAXQUEUE; for (uint8_t i = 0; i < MAXQUEUE; i++) @@ -370,64 +371,67 @@ namespace esphome if (this->is_running) { + if (millis() - this->last_scroll_time >= this->scroll_interval) + { + this->scroll_step++; + this->last_scroll_time = millis(); + if (this->scroll_step > this->queue[this->screen_pointer]->scroll_reset) + { + ESP_LOGD(TAG, "end scroll at: %d",this->scroll_step); + this->scroll_step = 0; + } + } + if (ts > this->next_action_time) { this->remove_expired_queue_element(); this->screen_pointer = this->find_last_clock(); + this->scroll_step = 0; + if (this->screen_pointer == MAXQUEUE) { this->screen_pointer = find_oldest_queue_element(); } - if (millis() - this->last_scroll_time >= this->scroll_interval) - { - this->scroll_step++; - this->last_scroll_time = millis(); - if (this->scroll_step > this->queue[this->screen_pointer]->pixels_ + 32) + if (this->screen_pointer != MAXQUEUE) + { + 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) { - this->scroll_step = 0; + this->icons[this->queue[this->screen_pointer]->icon]->set_frame(0); } - if (this->screen_pointer != MAXQUEUE) + this->next_action_time = this->queue[this->screen_pointer]->last_time; + // Todo switch for Triggers + if (this->queue[this->screen_pointer]->mode == MODE_CLOCK) { - 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) + for (auto *t : on_next_clock_triggers_) { - this->icons[this->queue[this->screen_pointer]->icon]->set_frame(0); - } - this->next_action_time = this->queue[this->screen_pointer]->last_time; - // Todo switch for Triggers - if (this->queue[this->screen_pointer]->mode == MODE_CLOCK) - { - for (auto *t : on_next_clock_triggers_) - { - t->process(); - } - } - else - { - for (auto *t : on_next_screen_triggers_) - { - t->process(this->queue[this->screen_pointer]->icon_name, this->queue[this->screen_pointer]->text); - } + t->process(); } } else { - ESP_LOGW(TAG, "tick: nothing to do. Restarting clock display!"); - this->clock_screen(24 * 60, this->clock_time, false, C_RED, C_GREEN, C_BLUE); - this->date_screen(24 * 60, (int)this->clock_time / 2, false, C_RED, C_GREEN, C_BLUE); - this->next_action_time = ts + this->clock_time; + for (auto *t : on_next_screen_triggers_) + { + t->process(this->queue[this->screen_pointer]->icon_name, this->queue[this->screen_pointer]->text); + } } } + else + { + ESP_LOGW(TAG, "tick: nothing to do. Restarting clock display!"); + this->clock_screen(24 * 60, this->clock_time, false, C_RED, C_GREEN, C_BLUE); + this->date_screen(24 * 60, (int)this->clock_time / 2, false, C_RED, C_GREEN, C_BLUE); + this->next_action_time = ts + this->clock_time; + } } } else - { - 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++; - } + { + 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++; + } } void EHMTX::skip_screen() diff --git a/components/ehmtxv2/EHMTX.h b/components/ehmtxv2/EHMTX.h index c475da7..037aa98 100644 --- a/components/ehmtxv2/EHMTX.h +++ b/components/ehmtxv2/EHMTX.h @@ -95,6 +95,7 @@ namespace esphome uint16_t frame_interval; // ms to next_frame() uint16_t clock_interval; uint16_t hold_time; // seconds display of screen_time to extend + uint8_t icon_count; // max iconnumber -1 unsigned long last_scroll_time; unsigned long last_rainbow_time; @@ -141,7 +142,6 @@ namespace esphome void hide_gauge(); void hide_indicator(); void hide_alarm(); - void full_screen(std::string icon, int lifetime=D_LIFETIME, int screen_time=D_SCREEN_TIME); void icon_screen(std::string icon, std::string text, int lifetime=D_LIFETIME, int screen_time=D_SCREEN_TIME,bool default_font=true,int r=C_RED, int g=C_GREEN, int b=C_BLUE); void text_screen(std::string text, int lifetime=D_LIFETIME, int screen_time=D_SCREEN_TIME, bool default_font=true, int r=C_RED, int g=C_GREEN, int b=C_BLUE); @@ -182,6 +182,7 @@ namespace esphome time_t endtime; time_t last_time; uint8_t icon; + uint16_t scroll_reset; Color text_color; show_mode mode; diff --git a/components/ehmtxv2/EHMTX_queue.cpp b/components/ehmtxv2/EHMTX_queue.cpp index a7124ab..34422c9 100644 --- a/components/ehmtxv2/EHMTX_queue.cpp +++ b/components/ehmtxv2/EHMTX_queue.cpp @@ -64,6 +64,7 @@ namespace esphome { uint8_t width = 32; uint8_t startx = 0; + int result = 0; switch (this->mode) { case MODE_RAINBOW_ICON: @@ -86,26 +87,27 @@ namespace esphome { if (this->pixels_ < width) { - return 32 - ceil((width - this->pixels_) / 2); + result = 32 - ceil((width - this->pixels_) / 2); } else { - return startx + this->config_->scroll_step; + result = startx + this->config_->scroll_step; } } else { if (this->pixels_ < width) { - return startx + ceil((width - this->pixels_) / 2); + result = startx + ceil((width - this->pixels_) / 2); } else { - return startx - this->config_->scroll_step + width; + result = startx - this->config_->scroll_step + width; } } + return result; } - + void EHMTX_queue::update_screen() { if (millis() - this->config_->last_rainbow_time >= this->config_->rainbow_interval) @@ -259,6 +261,11 @@ namespace esphome { int x, y, w, h; float display_duration; + + uint8_t width = 32; + uint8_t startx = 0; + uint16_t max_steps = 0; + if (this->default_font) { this->config_->display->get_text_bounds(0, 0, text.c_str(), this->config_->default_font, display::TextAlign::LEFT, &x, &y, &w, &h); @@ -282,12 +289,14 @@ namespace esphome } else { - display_duration = ceil((28 + (this->config_->scroll_count * (32 + this->pixels_)) * this->config_->scroll_interval) / 1000); + max_steps = (this->config_->scroll_count + 1) * (width - startx) + this->config_->scroll_count * this->pixels_; + display_duration = ceil((max_steps * this->config_->scroll_interval) / 1000); this->screen_time_ = (display_duration > screen_time) ? display_duration : screen_time; } break; case MODE_RAINBOW_ICON: case MODE_ICON_SCREEN: + startx = 8; if (this->pixels_ < 23) { this->screen_time_ = screen_time; @@ -295,7 +304,8 @@ namespace esphome } else { - display_duration = ceil((this->config_->scroll_count * (TEXTSTARTOFFSET + this->pixels_) * this->config_->scroll_interval) / 1000); + max_steps = (this->config_->scroll_count + 1) * (width - startx) + this->config_->scroll_count * this->pixels_; + display_duration = ceil((max_steps * this->config_->scroll_interval) / 1000); this->screen_time_ = (display_duration > screen_time) ? display_duration : screen_time; } break; @@ -303,6 +313,8 @@ namespace esphome break; } - ESP_LOGD(TAG, "calc_scroll_time: mode: %d text: \"%s\" pixels %d calculated: %d defined: %d", this->mode, text.c_str(), this->pixels_, this->screen_time_, screen_time); + this->scroll_reset = (width - startx) + this->pixels_;; + + ESP_LOGD(TAG, "calc_scroll_time: mode: %d text: \"%s\" pixels %d calculated: %d defined: %d max_steps: %d", this->mode, text.c_str(), this->pixels_, this->screen_time_, screen_time, this->scroll_reset); } } From c853c636ba7b098511ce3091f871ee7cfcc94851 Mon Sep 17 00:00:00 2001 From: LuBeDa Date: Sat, 20 May 2023 21:37:29 +0200 Subject: [PATCH 6/6] rtl for text --- components/ehmtxv2/EHMTX_queue.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/components/ehmtxv2/EHMTX_queue.cpp b/components/ehmtxv2/EHMTX_queue.cpp index 34422c9..646b1e3 100644 --- a/components/ehmtxv2/EHMTX_queue.cpp +++ b/components/ehmtxv2/EHMTX_queue.cpp @@ -98,16 +98,16 @@ namespace esphome { if (this->pixels_ < width) { - result = startx + ceil((width - this->pixels_) / 2); + result = startx + ceil((width - this->pixels_) / 2); } else { - result = startx - this->config_->scroll_step + width; + result = startx - this->config_->scroll_step + width; } } return result; } - + void EHMTX_queue::update_screen() { if (millis() - this->config_->last_rainbow_time >= this->config_->rainbow_interval) @@ -239,8 +239,16 @@ namespace esphome extraoffset += 2; } color_ = (this->mode == MODE_RAINBOW_TEXT) ? this->config_->rainbow_color : this->text_color; - this->config_->display->print(this->xpos() + xoffset, yoffset, font, color_, esphome::display::TextAlign::BASELINE_LEFT, - this->text.c_str()); + if (this->config_->rtl) + { + this->config_->display->print(this->xpos() + xoffset, yoffset, font, color_, esphome::display::TextAlign::BASELINE_RIGHT, + this->text.c_str()); + } + else + { + this->config_->display->print(this->xpos() + xoffset, yoffset, font, color_, esphome::display::TextAlign::BASELINE_LEFT, + this->text.c_str()); + } break; default: break; @@ -261,7 +269,7 @@ namespace esphome { int x, y, w, h; float display_duration; - + uint8_t width = 32; uint8_t startx = 0; uint16_t max_steps = 0; @@ -313,7 +321,8 @@ namespace esphome break; } - this->scroll_reset = (width - startx) + this->pixels_;; + this->scroll_reset = (width - startx) + this->pixels_; + ; ESP_LOGD(TAG, "calc_scroll_time: mode: %d text: \"%s\" pixels %d calculated: %d defined: %d max_steps: %d", this->mode, text.c_str(), this->pixels_, this->screen_time_, screen_time, this->scroll_reset); }