Skip to content

Commit

Permalink
Merge pull request #45 from lubeda/develop
Browse files Browse the repository at this point in the history
2023.6.5
  • Loading branch information
lubeda authored Jun 17, 2023
2 parents 7e9ac97 + c8c586b commit b16f9c7
Show file tree
Hide file tree
Showing 16 changed files with 279 additions and 92 deletions.
Binary file modified 8x32 iMAGE.xcf
Binary file not shown.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Changelog

## 2023.6.4
## 2023.6.5

- introduced `scroll_small_text`
- introduced `allow_empty_screen`
- introduced `blend_steps: 16`
- introduced service color_gauge
- fixed bitmap_small with gauge
- fixed del_screen with "*"
- improved blueprint selection @andrew-codechimp

## 2023.6.3

Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ ehmtxv2:

**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.

**blend_steps** (optional, int): on screen transition you can blend in the new screen, a value of 16 works nice, defaults 0.

**time_component** (required, ID): ID of the time component. The display shows `!t!` until the time source is valid.

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

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

##### modes

|mode|value|
|----|----|
|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_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|

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

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

- **[blakadder](https://github.com/blakadder)** for his contribution (cleanup README.md, fixed sample)
- **[andrew-codechimp](https://github.com/andrew-codechimp)** for his contribution (display on/off & del_screen "*" & show_clock with 0)
- **[andrew-codechimp](https://github.com/andrew-codechimp)** for his contribution (display on/off & del_screen "*" & show_clock with 0) and improved blueprint slelection
- **[jd1](https://github.com/jd1)** for his contributions
- **[aptonline](https://github.com/aptonline)** for his work on the Ulanzi hardware
- **[wsbtak](https://github.com/wsbtak)** for the work on the Ulanzi hardware
Expand Down
99 changes: 90 additions & 9 deletions components/ehmtxv2/EHMTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ namespace esphome
this->clock_color = Color(C_RED, C_GREEN, C_BLUE);
this->rainbow_color = Color(CA_RED, CA_GREEN, CA_BLUE);
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->last_scroll_time = 0;
this->screen_pointer = MAXQUEUE;
Expand Down Expand Up @@ -197,6 +195,7 @@ namespace esphome
ESP_LOGW(TAG, "bitmap_screen is not available on ESP8266");
}
#endif

uint8_t EHMTX::find_icon(std::string name)
{
for (uint8_t i = 0; i < this->icon_count; i++)
Expand Down Expand Up @@ -232,6 +231,50 @@ namespace esphome
ESP_LOGD(TAG, "hide gauge");
}

#ifndef USE_ESP8266
void EHMTX::color_gauge(std::string text)
{
ESP_LOGD(TAG, "color_gauge: %s", text.c_str());
const size_t CAPACITY = JSON_ARRAY_SIZE(8);
StaticJsonDocument<CAPACITY> doc;
deserializeJson(doc, text);
JsonArray array = doc.as<JsonArray>();
uint8_t i = 0;
for (JsonVariant v : array)
{
uint16_t buf = v.as<int>();

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->cgauge[i++] = c;
this->display_gauge = true;
}
}

void EHMTX::show_gauge(int percent, int r, int g, int b, int bg_r, int bg_g, int bg_b)
{
if (percent <= 100)
{
Color c = Color(r, g, b);
Color bgc = Color(bg_r, bg_g, bg_b);
for (uint8_t i = 0; i < 8; i++)
{
if (percent > i * 12.5)
{
this->cgauge[7 - i] = c;
}
else
{
this->cgauge[7 - i] = bgc;
}
}
this->display_gauge = true;
ESP_LOGD(TAG, "show_gauge 2 color %d", round(percent));
}
}
#else
void EHMTX::show_gauge(int percent, int r, int g, int b, int bg_r, int bg_g, int bg_b)
{
this->display_gauge = false;
Expand All @@ -242,8 +285,11 @@ namespace esphome
this->display_gauge = true;
this->gauge_value = (uint8_t)(100 - percent) * 7 / 100;
}
ESP_LOGD(TAG, "show_gauge 2 color %d", round(percent));
}
#endif

#ifdef USE_ESP8266
void EHMTX::draw_gauge()
{
if (this->display_gauge)
Expand All @@ -253,6 +299,19 @@ namespace esphome
this->display->line(0, 7, 0, this->gauge_value, this->gauge_color);
}
}
#else
void EHMTX::draw_gauge()
{
if (this->display_gauge)
{
for (uint8_t y = 0; y < 8; y++)
{
this->display->draw_pixel_at(0, y, this->cgauge[y]);
}
this->display->line(1, 7, 1, 0, esphome::display::COLOR_OFF);
}
}
#endif

void EHMTX::setup()
{
Expand Down Expand Up @@ -295,6 +354,7 @@ namespace esphome

register_service(&EHMTX::set_brightness, "brightness", {"value"});
#ifndef USE_ESP8266
register_service(&EHMTX::color_gauge, "color_gauge", {"colors"});
register_service(&EHMTX::bitmap_screen, "bitmap_screen", {"icon", "lifetime", "screen_time"});
register_service(&EHMTX::bitmap_small, "bitmap_small", {"icon", "text", "lifetime", "screen_time", "default_font", "r", "g", "b"});
#endif
Expand Down Expand Up @@ -505,6 +565,7 @@ namespace esphome
this->remove_expired_queue_element();
this->screen_pointer = this->find_last_clock();
this->scroll_step = 0;
this->ticks_ = 0;

if (this->screen_pointer == MAXQUEUE)
{
Expand Down Expand Up @@ -538,7 +599,7 @@ namespace esphome
}
else
{
if(!EHMTXv2_ALLOW_EMPTY_SCREEN)
if (!EHMTXv2_ALLOW_EMPTY_SCREEN)
{
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);
Expand All @@ -547,6 +608,17 @@ namespace esphome
}
}
}
// blend handling

#ifdef EHMTXv2_BLEND_STEPS
if (this->ticks_ <= EHMTXv2_BLEND_STEPS)
{
uint8_t b = this->brightness_;
float br = lerp((float)this->ticks_ / EHMTXv2_BLEND_STEPS, 0, (float)b / 255);
this->display->get_light()->set_correction(br, br, br);
}
#endif
this->ticks_++;
}
else
{
Expand Down Expand Up @@ -620,17 +692,26 @@ namespace esphome
if (this->queue[i]->mode == mode)
{
bool force = true;
ESP_LOGW(TAG, "del_screen: icon %s in position: %d mode %d", icon_name.c_str(), i, mode);
ESP_LOGD(TAG, "del_screen: icon %s in position: %s mode %d", icon_name.c_str(), this->queue[i]->icon_name.c_str(), mode);
if ((mode == MODE_ICON_SCREEN) || (mode == MODE_FULL_SCREEN) || (mode == MODE_RAINBOW_ICON))
{
if (strcmp(this->queue[i]->icon_name.c_str(), icon_name.c_str()) != 0)
if (this->string_has_ending(icon_name, "*"))
{
std::string comparename = icon_name.substr(0, icon_name.length() - 1);

if (this->queue[i]->icon_name.rfind(comparename, 0) != 0)
{
force = false;
}
}
else if(strcmp(this->queue[i]->icon_name.c_str(), icon_name.c_str()) != 0)
{
force = false;
}
}
if (force)
{
ESP_LOGW(TAG, "del_screen: force");
ESP_LOGW(TAG, "del_screen: slot %d deleted",i);
this->queue[i]->mode = MODE_EMPTY;
this->queue[i]->endtime = 0;
if (i == this->screen_pointer)
Expand Down Expand Up @@ -964,9 +1045,9 @@ namespace esphome
{
ESP_LOGCONFIG(TAG, "show date");
}
#ifdef EHMTXv2_USE_RTL
ESP_LOGCONFIG(TAG, "RTL activated");
#endif
#ifdef EHMTXv2_USE_RTL
ESP_LOGCONFIG(TAG, "RTL activated");
#endif
if (EHMTXv2_WEEK_START)
{
ESP_LOGCONFIG(TAG, "weekstart: monday");
Expand Down
9 changes: 6 additions & 3 deletions components/ehmtxv2/EHMTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const uint8_t TEXTSCROLLSTART = 8;
const uint8_t TEXTSTARTOFFSET = (32 - 8);

const uint16_t POLLINGINTERVAL = 250;
static const char *const EHMTX_VERSION = "2023.6.4";
static const char *const EHMTX_VERSION = "2023.6.5";
static const char *const TAG = "EHMTXv2";
#ifndef USE_ESP8266
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]";
Expand Down Expand Up @@ -79,15 +79,17 @@ namespace esphome
uint16_t hue_ = 0;
void dump_config();
#ifdef USE_ESP32
PROGMEM Color text_color, alarm_color, gauge_color, gauge_bgcolor, rindicator_color, lindicator_color,clock_color, today_color, weekday_color, rainbow_color;
PROGMEM Color text_color, alarm_color, rindicator_color, lindicator_color,clock_color, today_color, weekday_color, rainbow_color;
PROGMEM Color bitmap[256];
PROGMEM Color sbitmap[64];
PROGMEM Color cgauge[8];
PROGMEM EHMTX_Icon *icons[MAXICONS];
#endif

#ifdef USE_ESP8266
Color text_color, alarm_color, gauge_color, gauge_bgcolor,rindicator_color,lindicator_color, clock_color, today_color, weekday_color, rainbow_color;
EHMTX_Icon *icons[MAXICONS];
uint8_t gauge_value;
#endif
display::Font *default_font;
display::Font *special_font;
Expand All @@ -98,7 +100,7 @@ namespace esphome
bool display_gauge;
bool is_running = false;
bool show_date;
uint8_t gauge_value;

uint16_t clock_time;
uint16_t scroll_step;

Expand Down Expand Up @@ -165,6 +167,7 @@ namespace esphome
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 color_gauge(std::string text);
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);
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);
Expand Down
Loading

0 comments on commit b16f9c7

Please sign in to comment.