Skip to content

Commit b16f9c7

Browse files
authored
Merge pull request #45 from lubeda/develop
2023.6.5
2 parents 7e9ac97 + c8c586b commit b16f9c7

16 files changed

+279
-92
lines changed

8x32 iMAGE.xcf

442 Bytes
Binary file not shown.

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# Changelog
22

3-
## 2023.6.4
3+
## 2023.6.5
44

5-
- introduced `scroll_small_text`
6-
- introduced `allow_empty_screen`
5+
- introduced `blend_steps: 16`
6+
- introduced service color_gauge
7+
- fixed bitmap_small with gauge
8+
- fixed del_screen with "*"
9+
- improved blueprint selection @andrew-codechimp
710

811
## 2023.6.3
912

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,8 @@ ehmtxv2:
537537

538538
**show_dow** (optional, bool): draw the day of week rindicator on the bottom of the clock screen. Disable, e.g., if you want larger fonts, defaults to true.
539539

540+
**blend_steps** (optional, int): on screen transition you can blend in the new screen, a value of 16 works nice, defaults 0.
541+
540542
**time_component** (required, ID): ID of the time component. The display shows `!t!` until the time source is valid.
541543

542544
**default_font** (required, ID): ID of the default font
@@ -800,22 +802,22 @@ For example, if you have multiple icons named weather_sunny, weather_rain & weat
800802
*Parameters:*
801803

802804
- ```icon_name```: Icon `id` defined in the YAML (see installation)
803-
- ```mode```: The mode is for internal purposes use `5`  for icon_screen
805+
- ```mode```: The mode is a filter to select different screen types e. g. use `5`for icon_screen
804806

805807
##### modes
806808

807809
|mode|value|
808810
|----|----|
809811
|MODE_BLANK|1|
810812
|MODE_CLOCK | 2|
811-
| MODE_DATE | 3|
812-
| MODE_FULL_SCREEN | 4|
813-
|MODE_ICON_SCREEN | 5|
814-
|MODE_TEXT_SCREEN | 6|
815-
|MODE_RAINBOW_ICON | 7|
816-
|MODE_RAINBOW_TEXT |8|
817-
| MODE_RAINBOW_CLOCK | 9|
818-
| MODE_RAINBOW_DATE | 10|
813+
|MODE_DATE | 3|
814+
|MODE_FULL_SCREEN| 4|
815+
|MODE_ICON_SCREEN| 5|
816+
|MODE_TEXT_SCREEN| 6|
817+
|MODE_RAINBOW_ICON| 7|
818+
|MODE_RAINBOW_TEXT|8|
819+
|MODE_RAINBOW_CLOCK| 9|
820+
|MODE_RAINBOW_DATE| 10|
819821

820822
**(D)** Service **display_on** / **display_off**
821823

@@ -1107,7 +1109,7 @@ THE SOFTWARE IS PROVIDED “AS IS”, use at your own risk!
11071109
## Thanks
11081110

11091111
- **[blakadder](https://github.com/blakadder)** for his contribution (cleanup README.md, fixed sample)
1110-
- **[andrew-codechimp](https://github.com/andrew-codechimp)** for his contribution (display on/off & del_screen "*" & show_clock with 0)
1112+
- **[andrew-codechimp](https://github.com/andrew-codechimp)** for his contribution (display on/off & del_screen "*" & show_clock with 0) and improved blueprint slelection
11111113
- **[jd1](https://github.com/jd1)** for his contributions
11121114
- **[aptonline](https://github.com/aptonline)** for his work on the Ulanzi hardware
11131115
- **[wsbtak](https://github.com/wsbtak)** for the work on the Ulanzi hardware

components/ehmtxv2/EHMTX.cpp

Lines changed: 90 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ namespace esphome
2020
this->clock_color = Color(C_RED, C_GREEN, C_BLUE);
2121
this->rainbow_color = Color(CA_RED, CA_GREEN, CA_BLUE);
2222
this->alarm_color = Color(CA_RED, CA_GREEN, CA_BLUE);
23-
this->gauge_color = Color(CD_RED, CD_GREEN, CD_BLUE);
24-
this->gauge_value = 0;
2523
this->next_action_time = 0;
2624
this->last_scroll_time = 0;
2725
this->screen_pointer = MAXQUEUE;
@@ -197,6 +195,7 @@ namespace esphome
197195
ESP_LOGW(TAG, "bitmap_screen is not available on ESP8266");
198196
}
199197
#endif
198+
200199
uint8_t EHMTX::find_icon(std::string name)
201200
{
202201
for (uint8_t i = 0; i < this->icon_count; i++)
@@ -232,6 +231,50 @@ namespace esphome
232231
ESP_LOGD(TAG, "hide gauge");
233232
}
234233

234+
#ifndef USE_ESP8266
235+
void EHMTX::color_gauge(std::string text)
236+
{
237+
ESP_LOGD(TAG, "color_gauge: %s", text.c_str());
238+
const size_t CAPACITY = JSON_ARRAY_SIZE(8);
239+
StaticJsonDocument<CAPACITY> doc;
240+
deserializeJson(doc, text);
241+
JsonArray array = doc.as<JsonArray>();
242+
uint8_t i = 0;
243+
for (JsonVariant v : array)
244+
{
245+
uint16_t buf = v.as<int>();
246+
247+
unsigned char b = (((buf)&0x001F) << 3);
248+
unsigned char g = (((buf)&0x07E0) >> 3); // Fixed: shift >> 5 and << 2
249+
unsigned char r = (((buf)&0xF800) >> 8); // shift >> 11 and << 3
250+
Color c = Color(r, g, b);
251+
this->cgauge[i++] = c;
252+
this->display_gauge = true;
253+
}
254+
}
255+
256+
void EHMTX::show_gauge(int percent, int r, int g, int b, int bg_r, int bg_g, int bg_b)
257+
{
258+
if (percent <= 100)
259+
{
260+
Color c = Color(r, g, b);
261+
Color bgc = Color(bg_r, bg_g, bg_b);
262+
for (uint8_t i = 0; i < 8; i++)
263+
{
264+
if (percent > i * 12.5)
265+
{
266+
this->cgauge[7 - i] = c;
267+
}
268+
else
269+
{
270+
this->cgauge[7 - i] = bgc;
271+
}
272+
}
273+
this->display_gauge = true;
274+
ESP_LOGD(TAG, "show_gauge 2 color %d", round(percent));
275+
}
276+
}
277+
#else
235278
void EHMTX::show_gauge(int percent, int r, int g, int b, int bg_r, int bg_g, int bg_b)
236279
{
237280
this->display_gauge = false;
@@ -242,8 +285,11 @@ namespace esphome
242285
this->display_gauge = true;
243286
this->gauge_value = (uint8_t)(100 - percent) * 7 / 100;
244287
}
288+
ESP_LOGD(TAG, "show_gauge 2 color %d", round(percent));
245289
}
290+
#endif
246291

292+
#ifdef USE_ESP8266
247293
void EHMTX::draw_gauge()
248294
{
249295
if (this->display_gauge)
@@ -253,6 +299,19 @@ namespace esphome
253299
this->display->line(0, 7, 0, this->gauge_value, this->gauge_color);
254300
}
255301
}
302+
#else
303+
void EHMTX::draw_gauge()
304+
{
305+
if (this->display_gauge)
306+
{
307+
for (uint8_t y = 0; y < 8; y++)
308+
{
309+
this->display->draw_pixel_at(0, y, this->cgauge[y]);
310+
}
311+
this->display->line(1, 7, 1, 0, esphome::display::COLOR_OFF);
312+
}
313+
}
314+
#endif
256315

257316
void EHMTX::setup()
258317
{
@@ -295,6 +354,7 @@ namespace esphome
295354

296355
register_service(&EHMTX::set_brightness, "brightness", {"value"});
297356
#ifndef USE_ESP8266
357+
register_service(&EHMTX::color_gauge, "color_gauge", {"colors"});
298358
register_service(&EHMTX::bitmap_screen, "bitmap_screen", {"icon", "lifetime", "screen_time"});
299359
register_service(&EHMTX::bitmap_small, "bitmap_small", {"icon", "text", "lifetime", "screen_time", "default_font", "r", "g", "b"});
300360
#endif
@@ -505,6 +565,7 @@ namespace esphome
505565
this->remove_expired_queue_element();
506566
this->screen_pointer = this->find_last_clock();
507567
this->scroll_step = 0;
568+
this->ticks_ = 0;
508569

509570
if (this->screen_pointer == MAXQUEUE)
510571
{
@@ -538,7 +599,7 @@ namespace esphome
538599
}
539600
else
540601
{
541-
if(!EHMTXv2_ALLOW_EMPTY_SCREEN)
602+
if (!EHMTXv2_ALLOW_EMPTY_SCREEN)
542603
{
543604
ESP_LOGW(TAG, "tick: nothing to do. Restarting clock display!");
544605
this->clock_screen(24 * 60, this->clock_time, false, C_RED, C_GREEN, C_BLUE);
@@ -547,6 +608,17 @@ namespace esphome
547608
}
548609
}
549610
}
611+
// blend handling
612+
613+
#ifdef EHMTXv2_BLEND_STEPS
614+
if (this->ticks_ <= EHMTXv2_BLEND_STEPS)
615+
{
616+
uint8_t b = this->brightness_;
617+
float br = lerp((float)this->ticks_ / EHMTXv2_BLEND_STEPS, 0, (float)b / 255);
618+
this->display->get_light()->set_correction(br, br, br);
619+
}
620+
#endif
621+
this->ticks_++;
550622
}
551623
else
552624
{
@@ -620,17 +692,26 @@ namespace esphome
620692
if (this->queue[i]->mode == mode)
621693
{
622694
bool force = true;
623-
ESP_LOGW(TAG, "del_screen: icon %s in position: %d mode %d", icon_name.c_str(), i, mode);
695+
ESP_LOGD(TAG, "del_screen: icon %s in position: %s mode %d", icon_name.c_str(), this->queue[i]->icon_name.c_str(), mode);
624696
if ((mode == MODE_ICON_SCREEN) || (mode == MODE_FULL_SCREEN) || (mode == MODE_RAINBOW_ICON))
625697
{
626-
if (strcmp(this->queue[i]->icon_name.c_str(), icon_name.c_str()) != 0)
698+
if (this->string_has_ending(icon_name, "*"))
699+
{
700+
std::string comparename = icon_name.substr(0, icon_name.length() - 1);
701+
702+
if (this->queue[i]->icon_name.rfind(comparename, 0) != 0)
703+
{
704+
force = false;
705+
}
706+
}
707+
else if(strcmp(this->queue[i]->icon_name.c_str(), icon_name.c_str()) != 0)
627708
{
628709
force = false;
629710
}
630711
}
631712
if (force)
632713
{
633-
ESP_LOGW(TAG, "del_screen: force");
714+
ESP_LOGW(TAG, "del_screen: slot %d deleted",i);
634715
this->queue[i]->mode = MODE_EMPTY;
635716
this->queue[i]->endtime = 0;
636717
if (i == this->screen_pointer)
@@ -964,9 +1045,9 @@ namespace esphome
9641045
{
9651046
ESP_LOGCONFIG(TAG, "show date");
9661047
}
967-
#ifdef EHMTXv2_USE_RTL
968-
ESP_LOGCONFIG(TAG, "RTL activated");
969-
#endif
1048+
#ifdef EHMTXv2_USE_RTL
1049+
ESP_LOGCONFIG(TAG, "RTL activated");
1050+
#endif
9701051
if (EHMTXv2_WEEK_START)
9711052
{
9721053
ESP_LOGCONFIG(TAG, "weekstart: monday");

components/ehmtxv2/EHMTX.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const uint8_t TEXTSCROLLSTART = 8;
2222
const uint8_t TEXTSTARTOFFSET = (32 - 8);
2323

2424
const uint16_t POLLINGINTERVAL = 250;
25-
static const char *const EHMTX_VERSION = "2023.6.4";
25+
static const char *const EHMTX_VERSION = "2023.6.5";
2626
static const char *const TAG = "EHMTXv2";
2727
#ifndef USE_ESP8266
2828
static const char *const EHMTX_LOGO = "[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,63519,63519,63519,63519,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,63519,0,0,0,0,2016,0,0,0,0,0,0,0,0,0,0,31,0,0,0,0,0,0,0,0,0,63488,0,63488,0,0,0,63519,0,0,0,0,2016,2016,0,0,0,65514,0,65514,0,0,0,31,0,0,0,64512,0,0,64512,0,63488,63488,0,63488,63488,0,0,63519,63519,63519,0,0,2016,0,2016,0,65514,0,65514,0,65514,0,31,31,31,0,0,0,64512,64512,0,0,63488,63488,63488,63488,63488,0,0,63519,0,0,0,0,2016,0,2016,0,65514,0,65514,0,65514,0,0,31,0,0,0,0,64512,64512,0,0,0,63488,63488,63488,0,0,0,63519,63519,63519,63519,0,2016,0,2016,0,65514,0,65514,0,65514,0,0,0,31,31,0,64512,0,0,64512,0,0,0,63488,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]";
@@ -79,15 +79,17 @@ namespace esphome
7979
uint16_t hue_ = 0;
8080
void dump_config();
8181
#ifdef USE_ESP32
82-
PROGMEM Color text_color, alarm_color, gauge_color, gauge_bgcolor, rindicator_color, lindicator_color,clock_color, today_color, weekday_color, rainbow_color;
82+
PROGMEM Color text_color, alarm_color, rindicator_color, lindicator_color,clock_color, today_color, weekday_color, rainbow_color;
8383
PROGMEM Color bitmap[256];
8484
PROGMEM Color sbitmap[64];
85+
PROGMEM Color cgauge[8];
8586
PROGMEM EHMTX_Icon *icons[MAXICONS];
8687
#endif
8788

8889
#ifdef USE_ESP8266
8990
Color text_color, alarm_color, gauge_color, gauge_bgcolor,rindicator_color,lindicator_color, clock_color, today_color, weekday_color, rainbow_color;
9091
EHMTX_Icon *icons[MAXICONS];
92+
uint8_t gauge_value;
9193
#endif
9294
display::Font *default_font;
9395
display::Font *special_font;
@@ -98,7 +100,7 @@ namespace esphome
98100
bool display_gauge;
99101
bool is_running = false;
100102
bool show_date;
101-
uint8_t gauge_value;
103+
102104
uint16_t clock_time;
103105
uint16_t scroll_step;
104106

@@ -165,6 +167,7 @@ namespace esphome
165167
void blank_screen(int lifetime = D_LIFETIME, int screen_time = D_SCREEN_TIME);
166168

167169
void bitmap_screen(std::string text, int lifetime = D_LIFETIME, int screen_time = D_SCREEN_TIME);
170+
void color_gauge(std::string text);
168171
void bitmap_small(std::string, std::string,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);
169172
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);
170173
void rainbow_text_screen(std::string text, int lifetime = D_LIFETIME, int screen_time = D_SCREEN_TIME, bool default_font = true);

0 commit comments

Comments
 (0)