Skip to content

Commit

Permalink
2023.9.1: Advanced Clock
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjswan committed Nov 26, 2023
1 parent 0157aba commit bfd3d19
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 23 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ 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`
Expand Down Expand Up @@ -787,7 +789,8 @@ 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"|available only in **advanced clock mode** `advanced_clock: true`, allows you to set the color for the Hours (hr, hg, hb) and Minutes (mr, mg, mb), color is set by analogy with `r,g,b`|
|`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**|

#### Parameter description

Expand Down
28 changes: 21 additions & 7 deletions components/ehmtxv2/EHMTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ namespace esphome
#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
Expand Down Expand Up @@ -671,7 +674,8 @@ namespace esphome
#endif

#ifdef EHMTXv2_ADV_CLOCK
register_service(&EHMTX::set_adv_clock_color, "set_adv_clock_color", {"hr", "hg", "hb", "mr", "mg", "mb"});
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"});
Expand Down Expand Up @@ -2081,18 +2085,28 @@ namespace esphome
}

#ifdef EHMTXv2_ADV_CLOCK
void EHMTX::set_adv_clock_color(int hr, int hg, int hb, int mr, int mg, int mb)
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);
ESP_LOGD(TAG, "advanced clock color hour: r: %d g: %d b: %d minutes: r: %d g: %d b: %d", hr, hg, hb, mr, mg, 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(esphome::display::BaseFont *font, Color color, int xpos, int ypos)
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::cmatch match;
if (!std::regex_search(EHMTXv2_TIME_FORMAT, match, rgx))
std::smatch match;
if (!std::regex_search(format, match, rgx))
return false;

std::vector<std::string> parts;
Expand Down Expand Up @@ -2137,7 +2151,7 @@ namespace esphome
{
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 : color;
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;
Expand Down
13 changes: 9 additions & 4 deletions components/ehmtxv2/EHMTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,17 @@ namespace esphome
void dump_config();
bool info_font = true;
int8_t info_y_offset = 0;
#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 bitmap[256];
PROGMEM Color cgauge[8];
PROGMEM EHMTX_Icon *icons[MAXICONS];
#ifdef EHMTXv2_ADV_CLOCK
PROGMEM Color hour_color, minutes_color;
PROGMEM Color hour_color, minutes_color, spacer_color, info_clock_lcolor, info_clock_rcolor;
#endif
#endif

Expand All @@ -123,7 +127,7 @@ namespace esphome
EHMTX_Icon *icons[MAXICONS];
uint8_t gauge_value;
#ifdef EHMTXv2_ADV_CLOCK
Color hour_color, minutes_color;
Color hour_color, minutes_color, spacer_color, info_clock_lcolor, info_clock_rcolor;
#endif
#endif
display::BaseFont *default_font;
Expand Down Expand Up @@ -207,8 +211,9 @@ namespace esphome
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_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);
bool draw_clock(esphome::display::BaseFont *font, Color color, int xpos = 0, int ypos = 0);
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);
Expand Down
31 changes: 23 additions & 8 deletions components/ehmtxv2/EHMTX_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ namespace esphome
color_ = (this->mode == MODE_RAINBOW_CLOCK) ? this->config_->rainbow_color : this->text_color;
time_t ts = this->config_->clock->now().timestamp;
#ifdef EHMTXv2_ADV_CLOCK
if (!this->config_->draw_clock(font, color_, xoffset + 15, this->ypos() + yoffset))
if (!this->config_->draw_clock(EHMTXv2_TIME_FORMAT_BIG, font, color_, xoffset + 15, this->ypos() + yoffset))
{
#endif
if (this->config_->replace_time_date_active) // check for replace active
Expand Down Expand Up @@ -596,10 +596,11 @@ namespace esphome
{
color_ = this->text_color;
time_t ts = this->config_->clock->now().timestamp;

if (this->mode == MODE_ICON_CLOCK)
{
#ifdef EHMTXv2_ADV_CLOCK
if (!this->config_->draw_clock(font, color_, xoffset + 19, this->ypos() + yoffset))
if (!this->config_->draw_clock(EHMTXv2_TIME_FORMAT, font, color_, xoffset + 19, this->ypos() + yoffset))
{
#endif
if (this->config_->replace_time_date_active) // check for replace active
Expand Down Expand Up @@ -639,6 +640,20 @@ namespace esphome

if (this->icon_name.find("day") != std::string::npos || this->icon_name.find("weekday") != std::string::npos)
{
int8_t i_y_offset = this->config_->info_y_offset;
Color i_lcolor = this->config_->info_rcolor;
Color i_rcolor = this->config_->info_rcolor;

#ifdef EHMTXv2_ADV_CLOCK
if (this->mode == MODE_ICON_CLOCK)
{
i_y_offset = this->config_->info_clock_y_offset;
i_lcolor = this->config_->info_clock_rcolor;
i_rcolor = this->config_->info_clock_rcolor;
info_font = this->config_->info_clock_font ? this->config_->default_font : this->config_->special_font;
}
#endif

int mode = 0;
std::size_t pos = icon_name.find("#");
if (pos != std::string::npos)
Expand Down Expand Up @@ -686,12 +701,12 @@ namespace esphome
if (mode == 5 && (d < 10))
{
x_right = 4 - (r_width - 1) / 2;
this->config_->display->printf(x_right, this->ypos() + yoffset + this->config_->info_y_offset, info_font, this->config_->info_rcolor, display::TextAlign::BASELINE_LEFT, "%d", d % 10);
this->config_->display->printf(x_right, this->ypos() + yoffset + i_y_offset, info_font, i_rcolor, display::TextAlign::BASELINE_LEFT, "%d", d % 10);
}
else
{
this->config_->display->printf(x_left, this->ypos() + yoffset + this->config_->info_y_offset - (mode != 3 ? 0 : 1), info_font, this->config_->info_lcolor, display::TextAlign::BASELINE_LEFT, "%d", d / 10 % 10);
this->config_->display->printf(x_right, this->ypos() + yoffset + this->config_->info_y_offset - (mode != 4 ? 0 : 1), info_font, this->config_->info_rcolor, display::TextAlign::BASELINE_LEFT, "%d", d % 10);
this->config_->display->printf(x_left, this->ypos() + yoffset + i_y_offset - (mode != 3 ? 0 : 1), info_font, i_lcolor, display::TextAlign::BASELINE_LEFT, "%d", d / 10 % 10);
this->config_->display->printf(x_right, this->ypos() + yoffset + i_y_offset - (mode != 4 ? 0 : 1), info_font, i_rcolor, display::TextAlign::BASELINE_LEFT, "%d", d % 10);
}
}
else // if (this->icon_name.rfind("weekday", 0) == 0)
Expand Down Expand Up @@ -728,8 +743,8 @@ namespace esphome
x_right = x_right - r_width;
break;
}
this->config_->display->printf(x_left, this->ypos() + yoffset + this->config_->info_y_offset - (mode != 3 ? 0 : 1), info_font, this->config_->info_lcolor, display::TextAlign::BASELINE_LEFT, "%s", left.c_str());
this->config_->display->printf(x_right, this->ypos() + yoffset + this->config_->info_y_offset - (mode != 4 ? 0 : 1), info_font, this->config_->info_rcolor, display::TextAlign::BASELINE_LEFT, "%s", right.c_str());
this->config_->display->printf(x_left, this->ypos() + yoffset + i_y_offset - (mode != 3 ? 0 : 1), info_font, i_lcolor, display::TextAlign::BASELINE_LEFT, "%s", left.c_str());
this->config_->display->printf(x_right, this->ypos() + yoffset + i_y_offset - (mode != 4 ? 0 : 1), info_font, i_rcolor, display::TextAlign::BASELINE_LEFT, "%s", right.c_str());
}
else
{
Expand All @@ -738,7 +753,7 @@ namespace esphome
// The symbol consists of a visible part, and an empty area to the right with a width of one point.
uint8_t c_width = this->config_->GetTextWidth(info_font, "%s", weekday.c_str());
x_left = 4 - (c_width - 1) / 2;
this->config_->display->printf(x_left, this->ypos() + yoffset + this->config_->info_y_offset, info_font, this->config_->info_lcolor, display::TextAlign::BASELINE_LEFT, "%s", weekday.c_str());
this->config_->display->printf(x_left, this->ypos() + yoffset + i_y_offset, info_font, i_lcolor, display::TextAlign::BASELINE_LEFT, "%s", weekday.c_str());
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions components/ehmtxv2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def rgb565_888(v565):
CONF_SPECIAL_FONT_YOFFSET = "special_font_yoffset"
CONF_PINGPONG = "pingpong"
CONF_TIME_FORMAT = "time_format"
CONF_TIME_FORMAT_BIG = "time_format_big"
CONF_DATE_FORMAT = "date_format"
CONF_ON_START_RUNNING = "on_start_running"
CONF_ON_EMPTY_QUEUE = "on_empty_queue"
Expand Down Expand Up @@ -170,6 +171,9 @@ def rgb565_888(v565):
cv.Optional(
CONF_TIME_FORMAT, default="%H:%M"
): cv.string,
cv.Optional(
CONF_TIME_FORMAT_BIG, default="%H:%M:%S"
): cv.string,
cv.Optional(
CONF_WEEKDAYTEXT, default="SOMODIMIDOFRSA"
): cv.string,
Expand Down Expand Up @@ -260,7 +264,7 @@ def rgb565_888(v565):
}
),
cv.Optional(CONF_NIGHT_MODE_SCREENS, default=DEFAULT_NIGHT_MODE_SCREENS): cv.All(
cv.ensure_list(cv.one_of(1, 2, 3, 4, 5, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25)), cv.Length(min=1, max=5)
cv.ensure_list(cv.one_of(1, 2, 3, 4, 5, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25)), cv.Length(min=1, max=5)
),
cv.Required(CONF_ICONS): cv.All(
cv.ensure_list(
Expand Down Expand Up @@ -510,8 +514,9 @@ def thumbnails(frames):
cg.add_define("EHMTXv2_DEFAULT_FONT_OFFSET_Y",config[CONF_DEFAULT_FONT_YOFFSET])
cg.add_define("EHMTXv2_SPECIAL_FONT_OFFSET_X",config[CONF_SPECIAL_FONT_XOFFSET])
cg.add_define("EHMTXv2_SPECIAL_FONT_OFFSET_Y",config[CONF_SPECIAL_FONT_YOFFSET])
cg.add_define("EHMTXv2_DATE_FORMAT",config[CONF_DATE_FORMAT])
cg.add_define("EHMTXv2_TIME_FORMAT",config[CONF_TIME_FORMAT])
cg.add_define("EHMTXv2_DATE_FORMAT",config[CONF_DATE_FORMAT])
cg.add_define("EHMTXv2_TIME_FORMAT",config[CONF_TIME_FORMAT])
cg.add_define("EHMTXv2_TIME_FORMAT_BIG",config[CONF_TIME_FORMAT_BIG])

if config[CONF_SCROLL_SMALL_TEXT]:
cg.add_define("EHMTXv2_SCROLL_SMALL_TEXT")
Expand Down

0 comments on commit bfd3d19

Please sign in to comment.