diff --git a/README.md b/README.md index 4212fbb..10d9573 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,22 @@ full_screen => {"icon_name", "lifetime", "screen_time"} void full_screen(string iconname, int =D_LIFETIME, int screen_time=D_SCREEN_TIME); ``` +##### bitmap screen + +For 8x32 images as text. You can generate this images with e.g. [Pixel Bitmap Creator (8x32)](https://pixelit.bastelbunker.de/PixelCreator) + +###### service via API + +```c +bitmap_screen => {"[0,4523,0,2342,0,..... (256 values 16bit values rgb565)]", "lifetime", "screen_time"} +``` + +###### Lambda + +```c +void bitmap_screen(string text, int =D_LIFETIME, int screen_time=D_SCREEN_TIME); +``` + #### Display Elements ![elements](./images/elements.png) diff --git a/components/ehmtxv2/EHMTX.cpp b/components/ehmtxv2/EHMTX.cpp index badffce..eef20d9 100644 --- a/components/ehmtxv2/EHMTX.cpp +++ b/components/ehmtxv2/EHMTX.cpp @@ -9,7 +9,7 @@ namespace esphome this->display_indicator = 0; this->display_alarm = 0; this->clock_time = 10; - this->clock_intervall = 90; + this->clock_interval = 90; this->hold_time = 10; this->icon_count = 0; this->hue_ = 0; @@ -29,8 +29,6 @@ namespace esphome { this->queue[i] = new EHMTX_queue(this); } - this->clock_screen(14 * 24 * 60, this->clock_time, false, C_RED, C_GREEN, C_BLUE); - this->date_screen(14 * 24 * 60, (int)this->clock_time / 2, false, C_RED, C_GREEN, C_BLUE); } void EHMTX::set_time_format(std::string s) @@ -105,12 +103,38 @@ namespace esphome } } - void EHMTX::get_string(std::string text) + void EHMTX::bitmap_screen(std::string text, int lifetime, int screen_time) { - ESP_LOGD(TAG, "get_string: %s",text.c_str()); - json::parse_json(text,[](JsonObject root) { - ESP_LOGD(TAG, "string1: %s int1", root["string"],root["int"]); - }); + ESP_LOGD(TAG, "bitmap screen: lifetime: %d screen_time: %d", lifetime, screen_time); + const size_t CAPACITY = JSON_ARRAY_SIZE(256); + StaticJsonDocument doc; + deserializeJson(doc, text); + JsonArray array = doc.as(); + // extract the values + uint16_t i = 0; + for (JsonVariant v : array) + { + uint16_t buf = v.as(); + + unsigned char b = (((buf)&0x001F) << 3); + unsigned char g = (((buf)&0x07E0) >> 3); // Fixed: shift >> 5 and << 2 + unsigned char r = (((buf)&0xF800) >> 8); // shift >> 11 and << 3 + Color c = Color(r, g, b); + + this->bitmap[i++] = c; + } + + EHMTX_queue *screen = this->find_free_queue_element(); + + screen->text = ""; + screen->endtime = this->clock->now().timestamp + lifetime * 60; + screen->mode = MODE_BITMAP_SCREEN; + screen->screen_time_ = screen_time; + for (auto *t : on_add_screen_triggers_) + { + t->process("bitmap", (uint8_t)screen->mode); + } + screen->status(); } uint8_t EHMTX::find_icon(std::string name) @@ -198,6 +222,7 @@ namespace esphome register_service(&EHMTX::rainbow_text_screen, "rainbow_text_screen", {"text", "lifetime", "screen_time", "default_font"}); register_service(&EHMTX::clock_screen, "clock_screen", {"lifetime", "screen_time", "default_font", "r", "g", "b"}); + register_service(&EHMTX::bitmap_screen, "bitmap_screen", {"text", "lifetime", "screen_time"}); register_service(&EHMTX::rainbow_clock_screen, "rainbow_clock_screen", {"lifetime", "screen_time", "default_font"}); register_service(&EHMTX::date_screen, "date_screen", {"lifetime", "screen_time", "default_font", "r", "g", "b"}); @@ -244,6 +269,8 @@ namespace esphome if (this->clock->now().is_valid()) { ESP_LOGD(TAG, "time sync => start running"); + this->clock_screen(14 * 24 * 60, this->clock_time, false, C_RED, C_GREEN, C_BLUE); + this->date_screen(14 * 24 * 60, (int)this->clock_time / 2, false, C_RED, C_GREEN, C_BLUE); this->is_running = true; } } @@ -329,7 +356,7 @@ namespace esphome this->queue[i]->endtime = 0; if (this->queue[i]->mode != MODE_EMPTY) { - ESP_LOGD(TAG, "remove expired queue element: slot %d: icon_name: %s text: %s", i, this->queue[i]->icon_name.c_str(), this->queue[i]->text.c_str()); + ESP_LOGD(TAG, "remove expired queue element: slot %d: mode: %d icon_name: %s text: %s", i, this->queue[i]->mode, this->queue[i]->icon_name.c_str(), this->queue[i]->text.c_str()); for (auto *t : on_expired_screen_triggers_) { infotext = ""; @@ -704,7 +731,7 @@ 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_ = screen_time; + screen->screen_time_ = screen_time; screen->endtime = this->clock->now().timestamp + lifetime * 60; screen->status(); } @@ -912,6 +939,10 @@ namespace esphome { ESP_LOGCONFIG(TAG, "weekstart: sunday"); } + if (this->clock->now().is_valid()) + { + this->is_running = true; + } } void EHMTX::add_icon(EHMTX_Icon *icon) diff --git a/components/ehmtxv2/EHMTX.h b/components/ehmtxv2/EHMTX.h index 19fc05c..598ebc3 100644 --- a/components/ehmtxv2/EHMTX.h +++ b/components/ehmtxv2/EHMTX.h @@ -23,7 +23,7 @@ const uint8_t TEXTSTARTOFFSET = (32 - 8); 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 }; +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,MODE_BITMAP_SCREEN=11 }; namespace esphome { @@ -72,6 +72,7 @@ namespace esphome uint16_t clock_time; uint16_t scroll_step; uint8_t scroll_count; + Color bitmap[256]; void remove_expired_queue_element(); uint8_t find_oldest_queue_element(); uint8_t find_icon_in_queue(std::string); @@ -149,6 +150,7 @@ namespace esphome void clock_screen(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 date_screen(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 blank_screen(int lifetime=D_LIFETIME, int screen_time=D_SCREEN_TIME); + void bitmap_screen(std::string text,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); diff --git a/components/ehmtxv2/EHMTX_queue.cpp b/components/ehmtxv2/EHMTX_queue.cpp index 318c35c..a46935e 100644 --- a/components/ehmtxv2/EHMTX_queue.cpp +++ b/components/ehmtxv2/EHMTX_queue.cpp @@ -54,6 +54,9 @@ namespace esphome case MODE_RAINBOW_DATE: ESP_LOGD(TAG, "queue: date for: %d sec", this->screen_time_); break; + case MODE_BITMAP_SCREEN: + ESP_LOGD(TAG, "queue: bitmap for: %d sec", this->screen_time_); + break; default: ESP_LOGD(TAG, "queue: UPPS"); break; @@ -148,6 +151,15 @@ namespace esphome break; case MODE_BLANK: break; + case MODE_BITMAP_SCREEN: + for (uint8_t x = 0; x < 32; x++) + { + for (uint8_t y = 0; y < 8; y++) + { + this->config_->display->draw_pixel_at(x, y, this->config_->bitmap[x + y * 32]); + } + } + break; case MODE_RAINBOW_CLOCK: case MODE_CLOCK: if (this->config_->clock->now().is_valid()) // valid time