Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2023.9.1: Icon indicator #24

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
- Added `set_weekday_accent_on` and `set_weekday_accent_off` Turn on / off small days (accent) of the week when brightness is insufficient.
- Added `icon_prognosis_screen` and `icon_prognosis_screen_rgb` Displays an icon, text, and a prognosis bar consisting of 24 dots of specified colors. https://github.com/lubeda/EspHoMaTriXv2/issues/149
- Added `vertical_scroll` to ehmtxv2 config.
- Added Advanced clock mode `advanced_clock`, [More info](https://github.com/lubeda/EspHoMaTriXv2/issues/164)
- Added `icon_indicator`, Shows the indicator in the Icons area on the specified screens, in the specified color and at the specified vertical position.

### EspHoMaTriX 2023.9.0
- Added the ability to display graph as defined in the YAML file
Expand Down Expand Up @@ -622,6 +624,7 @@ This component is highly customizable.
ehmtxv2:
  id: rgb8x32
  show_seconds: true
advanced_clock: false
  matrix_component: ehmtx_display
  time_component: ehmtx_time
  icons2html: true
Expand Down Expand Up @@ -652,6 +655,10 @@ ehmtxv2:

**time_format** (optional, string): formats the date display with [strftime syntax](https://esphome.io/components/time.html?highlight=strftime), defaults `"%H:%M"` (use `"%I:%M%p"` for the US)

**time_format_big** (optional, string): formats the date display with [strftime syntax](https://esphome.io/components/time.html?highlight=strftime), defaults `"%H:%M:%S"`, work only in **advanced_clock** mode and sets the time format for a screen with a clock without an icon

**advanced_clock** (optional, boolean): Enables or disables advanced clock mode. (default: false) [More info](https://github.com/lubeda/EspHoMaTriXv2/issues/164)

**default_font_yoffset** (optional, pixel): yoffset the text is aligned BASELINE_LEFT, the baseline defaults to `6`

**default_font_xoffset** (optional, pixel): xoffset the text is aligned BASELINE_LEFT, the left defaults to `1`
Expand Down Expand Up @@ -693,6 +700,8 @@ Example:

**night_mode_screens** (optional, screen array, default [2, 3, 16]): List of screens displayed in [night mode](#night-mode).

**icon_indicator_screens** (optional, screen array, default [15, 18]): List of screens on which the [icon indicator](#icon-indicator) will be displayed.

**boot_logo** (optional, string , only on ESP32): Display a fullscreen logo defined as rgb565 array.

```yaml
Expand Down Expand Up @@ -783,6 +792,10 @@ Numerous features are accessible with services from home assistant and lambdas t
|`text_screen_progress`|"text", "value", "progress", "lifetime", "screen_time", "default_font", "value_color_as_progress", "r", "g", "b"|show the specified short text with value and with progress bar on bottom|
|`icon_prognosis_screen`|"icon_name", "text", "prognosis", "lifetime", "screen_time", "default_font"|show an icon, text, and a prognosis bar consisting of 24 dots of specified colors|
|`icon_prognosis_screen_rgb`|"icon_name", "text", "prognosis", "lifetime", "screen_time", "default_font", "r", "g", "b"|show an icon, text, and a prognosis bar consisting of 24 dots of specified colors|
|`set_adv_clock_color`|"hr", "hg", "hb", "mr", "mg", "mb", "sr", "sg", "sb"|available only in **advanced clock mode** `advanced_clock: true`, allows you to set the color for the Hours (hr, hg, hb), Minutes (mr, mg, mb) and Spacer (sr, sg, sb), color is set by analogy with `r,g,b`. If the color is set as `black`, the standard color is used (see `set_clock_color`).|
|`set_clock_infotext_color`|"left_r", "left_g", "left_b", "right_r", "right_g", "right_b","default_font","y_offset"|set the special color for left and right char on info text on `icon clock` screen, work only in **advanced clock mode**|
|`show_icon_indicator`|"r", "g", "b", "size", "pos"|shows the line indicator in the Icons area on the specified screens, in the specified color and at the specified vertical position|
|`hide_icon_indicator`|none|hides the icon indicator|

#### Parameter description

Expand All @@ -804,6 +817,29 @@ Numerous features are accessible with services from home assistant and lambdas t

When night mode is enabled, only the screens specified in `night_mode_screens` are displayed (**default:** 2, 3, 16) the other screens can be added, deleted, and will follow their life cycle but will not be displayed. Screen numbers in the table [mode](#modes).

### Icon Iindicator

Shows the line indicator in the Icons area on the specified screens, in the specified color and at the specified vertical position.

```yaml
ehmtxv2:
...
icon_indicator_screens:
- 15
```

Home assistant service call:

```yaml
service: esphome.ulanzi_show_icon_indicator
data:
r: 240
g: 240
b: 240
size: 6
pos: 7
```

### Local lambdas

#### Add screen to your display queue
Expand Down
146 changes: 144 additions & 2 deletions components/ehmtxv2/EHMTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <vector>
#include <algorithm>
#include <string>
#include <regex>

namespace esphome
{
Expand All @@ -13,6 +14,8 @@ namespace esphome
this->display_gauge = false;
this->display_rindicator = 0;
this->display_lindicator = 0;
this->display_icon_indicator = 0;
this->icon_indicator_y_pos = 7;
this->display_alarm = 0;
this->clock_time = 10;
this->icon_count = 0;
Expand All @@ -32,6 +35,14 @@ namespace esphome
this->vertical_scroll = false;
#endif

#ifdef EHMTXv2_ADV_CLOCK
this->info_clock_lcolor = Color(CG_GREY, CG_GREY, CG_GREY);
this->info_clock_rcolor = Color(CG_GREY * 2, CG_GREY * 2, CG_GREY * 2);

this->set_clock_color();
this->set_adv_clock_color();
#endif

for (uint8_t i = 0; i < MAXQUEUE; i++)
{
this->queue[i] = new EHMTX_queue(this);
Expand All @@ -43,7 +54,7 @@ namespace esphome
{
if (size > 0)
{
this->rindicator_color = Color((uint8_t)r , (uint8_t)g , (uint8_t)b );
this->rindicator_color = Color((uint8_t)r , (uint8_t)g , (uint8_t)b);
this->display_rindicator = size & 3;
ESP_LOGD(TAG, "show rindicator size: %d r: %d g: %d b: %d", size, r, g, b);
}
Expand All @@ -57,7 +68,7 @@ namespace esphome
{
if (size > 0)
{
this->lindicator_color = Color((uint8_t)r , (uint8_t)g , (uint8_t)b );
this->lindicator_color = Color((uint8_t)r , (uint8_t)g , (uint8_t)b);
this->display_lindicator = size & 3;
ESP_LOGD(TAG, "show lindicator size: %d r: %d g: %d b: %d", size, r, g, b);
}
Expand All @@ -67,6 +78,21 @@ namespace esphome
}
}

void EHMTX::show_icon_indicator(int r, int g, int b, int size, int pos)
{
if (size > 0)
{
this->icon_indicator_color = Color((uint8_t)r , (uint8_t)g , (uint8_t)b);
this->display_icon_indicator = size;
this->icon_indicator_y_pos = pos;
ESP_LOGD(TAG, "show icon_indicator size: %d r: %d g: %d b: %d pos:", size, r, g, b, pos);
}
else
{
this->hide_icon_indicator();
}
}

void EHMTX::hide_rindicator()
{
this->display_rindicator = 0;
Expand All @@ -79,6 +105,12 @@ namespace esphome
ESP_LOGD(TAG, "hide lindicator");
}

void EHMTX::hide_icon_indicator()
{
this->display_icon_indicator = 0;
ESP_LOGD(TAG, "hide icon indicator");
}

void EHMTX::set_display_off()
{
this->show_display = false;
Expand Down Expand Up @@ -660,10 +692,18 @@ namespace esphome
register_service(&EHMTX::bitmap_stack, "bitmap_stack", {"icons", "lifetime", "screen_time"});
#endif

register_service(&EHMTX::show_icon_indicator, "show_icon_indicator", {"r", "g", "b", "size", "pos"});
register_service(&EHMTX::hide_icon_indicator, "hide_icon_indicator");

#ifdef USE_Fireplugin
register_service(&EHMTX::fire_screen, "fire_screen", {"lifetime", "screen_time"});
#endif

#ifdef EHMTXv2_ADV_CLOCK
register_service(&EHMTX::set_clock_infotext_color, "set_clock_infotext_color", {"left_r", "left_g", "left_b", "right_r", "right_g", "right_b", "default_font", "y_offset"});
register_service(&EHMTX::set_adv_clock_color, "set_adv_clock_color", {"hr", "hg", "hb", "mr", "mg", "mb", "sr", "sg", "sb"});
#endif

register_service(&EHMTX::text_screen_progress, "text_screen_progress", {"text", "value", "progress", "lifetime", "screen_time", "default_font", "value_color_as_progress", "r", "g", "b"});
register_service(&EHMTX::icon_screen_progress, "icon_screen_progress", {"icon_name", "text", "progress", "lifetime", "screen_time", "default_font", "r", "g", "b"});
register_service(&EHMTX::set_progressbar_color, "set_progressbar_color", {"icon_name", "mode", "r", "g", "b", "bg_r", "bg_g", "bg_b"});
Expand Down Expand Up @@ -2070,6 +2110,89 @@ namespace esphome
}
}

#ifdef EHMTXv2_ADV_CLOCK
void EHMTX::set_clock_infotext_color(int lr, int lg, int lb, int rr, int rg, int rb, bool df, int y_offset)
{
this->info_clock_lcolor = Color((uint8_t)lr, (uint8_t)lg, (uint8_t)lb);
this->info_clock_rcolor = Color((uint8_t)rr, (uint8_t)rg, (uint8_t)rb);
this->info_clock_font = df;
this->info_clock_y_offset = y_offset;
ESP_LOGD(TAG, "info clock text color left: r: %d g: %d b: %d right: r: %d g: %d b: %d y_offset %d", lr, lg, lb, rr, rg, rb, y_offset);
}

void EHMTX::set_adv_clock_color(int hr, int hg, int hb, int mr, int mg, int mb, int sr, int sg, int sb)
{
this->hour_color = Color((uint8_t)hr, (uint8_t)hg, (uint8_t)hb);
this->minutes_color = Color((uint8_t)mr, (uint8_t)mg, (uint8_t)mb);
this->spacer_color = Color((uint8_t)sr, (uint8_t)sg, (uint8_t)sb);
ESP_LOGD(TAG, "advanced clock color hour: r: %d g: %d b: %d minutes: r: %d g: %d b: %d spacer: r: %d g: %d b: %d", hr, hg, hb, mr, mg, mb, sr, sg, sb);
}

bool EHMTX::draw_clock(std::string format, esphome::display::BaseFont *font, Color color, int xpos, int ypos)
{
std::regex rgx {"^(%[HI])(.)(%M)(.)?(%S|%p)?$"};
std::smatch match;
if (!std::regex_search(format, match, rgx))
return false;

std::vector<std::string> parts;
std::vector<uint8_t> len;
std::string sep = "";

uint8_t full_length = 0;

for (int i = 1; i < match.length(); i++)
{
std::string output = match[i].str();

if (output.length() > 0)
{
if (output.find("%") != std::string::npos)
{
if (output == "%p" && this->replace_time_date_active) // check for replace active
{
output = this->clock->now().strftime(output);
output = this->replace_time_date(output);
}
else
{
output = this->clock->now().strftime(output);
}
}
else if (sep == "")
{
sep = output;
}

parts.push_back(output);
len.push_back(output.length() > 0 ? this->GetTextWidth(font, "%s", output.c_str()) : 0);
full_length += len.back();
}
}

uint8_t x = xpos - full_length / 2;
for (int i = 0; i < parts.size(); i++)
{
if (parts.at(i).length() > 0)
{
if (!(this->show_seconds && parts.at(i) == sep && (this->clock->now().second % 2 == 1)))
{
Color c_ = i == 0 ? this->hour_color : i == 2 ? this->minutes_color : parts.at(i) == sep ? this->spacer_color : color;
if (c_.r + c_.g + c_.b == C_BLACK)
{
c_ = color;
}

this->display->printf(x, ypos, font, c_, display::TextAlign::BASELINE_LEFT, "%s", parts.at(i).c_str());
}
x += len.at(i);
}
}

return true;
}
#endif

void EHMTX::set_weekday_char_count(uint8_t i)
{
this->weekday_char_count = i;
Expand Down Expand Up @@ -2259,6 +2382,23 @@ namespace esphome
}
}

void EHMTX::draw_icon_indicator()
{
if (this->display_icon_indicator > 0)
{
for (auto id : EHMTXv2_CONF_ICON_INDICATOR_SCREENS)
{
if (this->queue[this->screen_pointer]->mode == id)
{
this->display->line(4 - display_icon_indicator / 2, this->icon_indicator_y_pos,
3 + display_icon_indicator / 2, this->icon_indicator_y_pos,
this->icon_indicator_color);
break;
}
}
}
}

void HOT EHMTX::draw()
{
if ((this->is_running) && (this->show_display) )
Expand Down Expand Up @@ -2295,6 +2435,8 @@ namespace esphome
}
}
#endif

this->draw_icon_indicator();
this->draw_alarm();
}
}
Expand Down
26 changes: 23 additions & 3 deletions components/ehmtxv2/EHMTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,34 @@ namespace esphome
void dump_config();
bool info_font = true;
int8_t info_y_offset = 0;
int8_t icon_indicator_y_pos = 7;
#ifdef EHMTXv2_ADV_CLOCK
bool info_clock_font = true;
int8_t info_clock_y_offset = 0;
#endif
#ifdef USE_ESP32
PROGMEM Color text_color, alarm_color, rindicator_color, lindicator_color, today_color, weekday_color, rainbow_color, clock_color, info_lcolor, info_rcolor;
PROGMEM Color text_color, alarm_color, rindicator_color, lindicator_color, today_color, weekday_color, rainbow_color, clock_color, info_lcolor, info_rcolor, icon_indicator_color;
PROGMEM Color bitmap[256];
PROGMEM Color cgauge[8];
PROGMEM EHMTX_Icon *icons[MAXICONS];
#ifdef EHMTXv2_ADV_CLOCK
PROGMEM Color hour_color, minutes_color, spacer_color, info_clock_lcolor, info_clock_rcolor;
#endif
#endif

#ifdef USE_ESP8266
Color text_color, alarm_color, gauge_color, gauge_bgcolor,rindicator_color,lindicator_color, today_color, weekday_color, rainbow_color, clock_color, info_lcolor, info_rcolor;
Color text_color, alarm_color, gauge_color, gauge_bgcolor, rindicator_color, lindicator_color, today_color, weekday_color, rainbow_color, clock_color, info_lcolor, info_rcolor, icon_indicator_color;
EHMTX_Icon *icons[MAXICONS];
uint8_t gauge_value;
#ifdef EHMTXv2_ADV_CLOCK
Color hour_color, minutes_color, spacer_color, info_clock_lcolor, info_clock_rcolor;
#endif
#endif
display::BaseFont *default_font;
display::BaseFont *special_font;
int display_rindicator;
int display_lindicator;
int display_icon_indicator;
int display_alarm;
uint8_t ticks_per_second=62;
bool display_gauge;
Expand Down Expand Up @@ -166,7 +178,7 @@ namespace esphome
uint8_t find_icon(std::string name);
uint8_t find_last_clock();
bool string_has_ending(std::string const &fullString, std::string const &ending);
void draw_day_of_week(int ypos = 0, bool small=false);
void draw_day_of_week(int ypos = 0, bool small = false);
void show_all_icons();
float get_tick();
void tick();
Expand Down Expand Up @@ -195,17 +207,24 @@ namespace esphome

void show_rindicator(int r = C_RED, int g = C_GREEN, int b = C_BLUE, int s = 3);
void show_lindicator(int r = C_RED, int g = C_GREEN, int b = C_BLUE, int s = 3);
void show_icon_indicator(int r = C_RED, int g = C_GREEN, int b = C_BLUE, int s = 6, int pos = 7);
void set_text_color(int r = C_RED, int g = C_GREEN, int b = C_BLUE);
void set_today_color(int r = C_RED, int g = C_GREEN, int b = C_BLUE);
void set_weekday_color(int r = CD_RED, int g = CD_GREEN, int b = CD_BLUE);
void set_clock_color(int r = C_RED, int g = C_GREEN, int b = C_BLUE);
void set_infotext_color(int lr = CG_GREY, int lg = CG_GREY, int lb = CG_GREY, int rr = CG_GREY, int rg = CG_GREY, int rb = CG_GREY, bool info_font = true, int y_offset = 0);
#ifdef EHMTXv2_ADV_CLOCK
void set_clock_infotext_color(int lr = CG_GREY, int lg = CG_GREY, int lb = CG_GREY, int rr = CG_GREY, int rg = CG_GREY, int rb = CG_GREY, bool info_font = true, int y_offset = 0);
void set_adv_clock_color(int hr = C_BLACK, int hg = C_BLACK, int hb = C_BLACK, int mr = C_BLACK, int mg = C_BLACK, int mb = C_BLACK, int sr = C_BLACK, int sg = C_BLACK, int sb = C_BLACK);
bool draw_clock(std::string format, esphome::display::BaseFont *font, Color color, int xpos = 0, int ypos = 0);
#endif

void show_alarm(int r = CA_RED, int g = CA_GREEN, int b = CA_BLUE, int s = 2);
void show_gauge(int v, int r = C_RED, int g = C_GREEN, int b = C_BLUE,int bgr = CG_GREY, int bgg = CG_GREY, int bgb = CG_GREY); // int because of register_service
void hide_gauge();
void hide_rindicator();
void hide_lindicator();
void hide_icon_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);
Expand Down Expand Up @@ -243,6 +262,7 @@ namespace esphome
void draw_alarm();
void draw_rindicator();
void draw_lindicator();
void draw_icon_indicator();

void set_replace_time_date_active(bool b=false);
void set_weekday_char_count(uint8_t i);
Expand Down
Loading