diff --git a/README.md b/README.md index 73d890e..64bff6e 100644 --- a/README.md +++ b/README.md @@ -464,7 +464,7 @@ This component is highly customizable. ***Example*** ```yaml -ehmtx: +ehmtxv2: id: rgb8x32 clock_time: 7 screen_time: 9 @@ -484,7 +484,7 @@ ehmtx: scroll_interval: 80 # milliseconds frame_interval: 192 # milliseconds icons: - ..... + ..... ``` ***Parameters*** @@ -618,7 +618,7 @@ See the examples: ##### Write information to esphome log ```yaml -ehmtx: +ehmtxv2: .... on_next_screen: lambda: |- @@ -631,7 +631,7 @@ ehmtx: To send data back to home assistant you can use events. ```yaml -ehmtx: +ehmtxv2: .... on_next_screen: - homeassistant.event: @@ -653,7 +653,7 @@ See the examples: ##### Change something for each clock circle ```yaml -ehmtx: +ehmtxv2: .... on_next_clock: lambda: |- diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index 951e731..81545c8 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -171,6 +171,7 @@ namespace esphome register_service(&EHMTX::icon_screen, "icon_screen", {"icon_name", "text", "lifetime", "screen_time", "default_font", "r", "g", "b"}); register_service(&EHMTX::text_screen, "text_screen", {"text", "lifetime", "screen_time", "default_font", "r", "g", "b"}); register_service(&EHMTX::clock_screen, "clock_screen", {"lifetime", "screen_time", "default_font", "r", "g", "b"}); + register_service(&EHMTX::rainbow_clock_screen, "rainbow_clock_screen", {"lifetime", "screen_time", "default_font"}); register_service(&EHMTX::blank_screen, "blank_screen", {"lifetime", "screen_time"}); register_service(&EHMTX::date_screen, "date_screen", {"lifetime", "screen_time", "default_font", "r", "g", "b"}); register_service(&EHMTX::rainbow_icon_screen, "rainbow_icon_screen", {"icon_name", "text", "lifetime", "screen_time", "default_font"}); @@ -497,6 +498,19 @@ namespace esphome screen->status(); } + void EHMTX::rainbow_clock_screen(int lifetime, int screen_time, bool default_font) + { + EHMTX_queue *screen = this->find_free_queue_element(); + + 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; + screen->endtime = this->clock->now().timestamp + lifetime * 60; + screen->status(); + } + + void EHMTX::rainbow_icon_screen(std::string iconname, std::string text, int lifetime, int screen_time, bool default_font) { uint8_t icon = this->find_icon(iconname.c_str()); diff --git a/components/ehmtxv2/EHMTX.h b/components/ehmtxv2/EHMTX.h index e1f897b..09793d5 100644 --- a/components/ehmtxv2/EHMTX.h +++ b/components/ehmtxv2/EHMTX.h @@ -22,8 +22,8 @@ const uint8_t TEXTSTARTOFFSET = (32 - 8); const uint16_t TICKINTERVAL = 1000; // each 1000ms static const char *const EHMTX_VERSION = "Version: 2023.5.0"; -static const char *const TAG = "EHMTX"; -enum show_mode : uint8_t { MODE_EMPTY = 0,MODE_BLANK = 1, MODE_CLOCK = 2, MODE_DATE = 3, MODE_FULL_SCREEN = 4, MODE_ICONSCREEN = 5, MODE_TEXT = 6 , MODE_RAINBOW_ICON = 7,MODE_RAINBOW_TEXT = 8 }; +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_ICONSCREEN = 5, MODE_TEXT = 6 , MODE_RAINBOW_ICON = 7,MODE_RAINBOW_TEXT = 8, MODE_RAINBOW_CLOCK = 9 }; namespace esphome { @@ -141,7 +141,7 @@ namespace esphome void blank_screen(int lifetime=D_LIFETIME, int screen_time=D_SCREEN_TIME); void rainbow_icon_screen(std::string icon_name, std::string text, int lifetime=D_LIFETIME, int screen_time=D_SCREEN_TIME, bool default_font=true); void rainbow_text_screen(std::string text, int lifetime=D_LIFETIME, int screen_time=D_SCREEN_TIME, bool default_font=true); - + void rainbow_clock_screen(int lifetime=D_LIFETIME, int screen_time=D_SCREEN_TIME, bool default_font=true); void del_screen(std::string icon, int mode=MODE_ICONSCREEN); void draw_gauge(); diff --git a/components/ehmtxv2/EHMTX_queue.cpp b/components/ehmtxv2/EHMTX_queue.cpp index 3865798..f25eae9 100644 --- a/components/ehmtxv2/EHMTX_queue.cpp +++ b/components/ehmtxv2/EHMTX_queue.cpp @@ -49,6 +49,9 @@ namespace esphome case MODE_RAINBOW_TEXT: ESP_LOGD(TAG, "queue: rainbow text: %s for %d sec", this->text.c_str(), this->screen_time); break; + case MODE_RAINBOW_CLOCK: + ESP_LOGD(TAG, "queue: clock for %d sec", this->screen_time); + break; default: ESP_LOGD(TAG, "queue: UPPS"); break; @@ -133,17 +136,21 @@ namespace esphome break; case MODE_BLANK: break; + case MODE_RAINBOW_CLOCK: case MODE_CLOCK: if (this->config_->clock->now().timestamp > 6000) // valid time { + color_ = (this->mode == MODE_RAINBOW_CLOCK) ? this->config_->rainbow_color : this->text_color; time_t ts = this->config_->clock->now().timestamp; - this->config_->display->strftime(xoffset + 15, yoffset, font, this->text_color, display::TextAlign::BASELINE_CENTER, this->config_->time_fmt.c_str(), + this->config_->display->strftime(xoffset + 15, yoffset, font, color_, display::TextAlign::BASELINE_CENTER, this->config_->time_fmt.c_str(), this->config_->clock->now()); if ((this->config_->clock->now().second % 2 == 0) && this->config_->show_seconds) { - this->config_->display->draw_pixel_at(0, 0, this->config_->clock_color); + this->config_->display->draw_pixel_at(0, 0, color_); + } + if (this->mode != MODE_RAINBOW_CLOCK){ + this->config_->draw_day_of_week(); } - this->config_->draw_day_of_week(); } else { diff --git a/components/ehmtxv2/__init__.py b/components/ehmtxv2/__init__.py index b6c5faf..cad5d90 100644 --- a/components/ehmtxv2/__init__.py +++ b/components/ehmtxv2/__init__.py @@ -286,13 +286,11 @@ async def to_code(config): image = Image.open(io.BytesIO(r.content)) width, height = image.size - logging.info(f"org width: {width} height: {height }") if CONF_RESIZE in conf: new_width_max, new_height_max = conf[CONF_RESIZE] ratio = min(new_width_max / width, new_height_max / height) width, height = int(width * ratio), int(height * ratio) - logging.info(f"==> width: {width} height: {height }") if hasattr(image, 'n_frames'): frames = min(image.n_frames, MAXFRAMES) @@ -322,7 +320,7 @@ async def to_code(config): frame = image.convert("RGB") if CONF_RESIZE in conf: frame = frame.resize([width, height]) - logging.info(f"dupti org width: {width} height: {height }") + pixels = list(frame.getdata())