Skip to content

Commit

Permalink
2023.9.1: Add Rainbow Alert Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjswan authored Dec 18, 2023
1 parent af019eb commit 063de74
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- 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. [Example](https://github.com/lubeda/EspHoMaTriXv2/pull/170#issuecomment-1836539171)
- Added `rainbow_alert_screen`, show the specified icon with text in rainbow color, screen forced and lifetime = screen_time

### EspHoMaTriX 2023.9.0
- Added the ability to display graph as defined in the YAML file
Expand Down Expand Up @@ -257,7 +258,7 @@ void rainbow_icon_screen(std::string icon, std::string text, int lifetime=D_LIFE
void alert_screen(std::string icon_name, std::string text, int screen_time, bool default_font, int r, int g, int b)
```

`icon_screen` and `rainbow_icon_screen` are in the queue for `lifetime` minutes. `alert_screen` is displayed once, imidiatly for at least `screentime` seconds for long text the dcreentime is calculated automagically.
`icon_screen` and `rainbow_icon_screen` are in the queue for `lifetime` minutes. `alert_screen` and `rainbow_alert_screen` is displayed once, imidiatly for at least `screentime` seconds for long text the dcreentime is calculated automagically.

##### full_screen

Expand Down Expand Up @@ -779,6 +780,7 @@ Numerous features are accessible with services from home assistant and lambdas t
|`date_screen`|"lifetime", "screen_time", "default_font", "r", "g", "b"|show the date|
|`brightness`|"value"|set the display brightness|
|`alert_screen`|"icon_name", "text", "screen_time", "default_font", "r", "g", "b"|show the specified icon with text, screen forced and lifetime = screen_time|
|`rainbow_alert_screen`|"icon_name", "text", "screen_time", "default_font"|show the specified icon with text in rainbow color, screen forced and lifetime = screen_time|
|`icon_screen_progress`|"icon_name", "text", "progress", "lifetime", "screen_time", "default_font", "r", "g", "b"|show the specified icon with text and with progress bar on bottom|
|`set_progressbar_color`|"icon_name", "mode", "r", "g", "b", "bg_r", "bg_g", "bg_b"|sets the specified by name and [mode](#modes) screen with progress bar, the specified color of the progress bar, and the background color of the progress bar. if you set the color to black, the color display will work according to the progress value|
|`icon_clock`|"icon_name", "lifetime", "screen_time", "default_font", "r", "g", "b"|show the specified icon with time, there is support for [displaying text on top of the icon](#icon_text)|
Expand Down Expand Up @@ -1095,6 +1097,7 @@ For example, if you have multiple icons named weather_sunny, weather_rain & weat
|MODE_BITMAP_STACK_SCREEN| 23|
|MODE_TEXT_PROGRESS| 24|
|MODE_PROGNOSIS_SCREEN| 25|
|MODE_RAINBOW_ALERT_SCREEN| 26|

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

Expand Down Expand Up @@ -1515,7 +1518,7 @@ THE SOFTWARE IS PROVIDED “AS IS”, use at your own risk!
- **[N3rdix](https://github.com/N3rdix)** PRs
- **[lukasleitsch](https://github.com/lukasleitsch)** PRs
- **[trvrnrth](https://github.com/trvrnrth)** PRs with fixing an error
- **[andrewjswan](https://github.com/andrewjswan)** Boot animation centered. `alert_screen` and [issue](https://github.com/lubeda/EspHoMaTriXv2/issues/84) and the additions to 2023.9.1
- **[andrewjswan](https://github.com/andrewjswan)** Boot animation centered. `alert_screen` and [issue](https://github.com/lubeda/EspHoMaTriXv2/issues?q=is%3Aissue+author%3Aandrewjswan) and the [additions](https://github.com/lubeda/EspHoMaTriXv2/pulls?q=is%3Apr+author%3Aandrewjswan) to 2023.9.1
- **Added by [andrewjswan](https://github.com/andrewjswan)** [![StandWithUkraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)
- **[malinovsku](https://github.com/malinovsku)** Issues and testing.
- **[chertvl](https://github.com/chertvl)** Issues and testing.
Expand Down
38 changes: 38 additions & 0 deletions components/ehmtxv2/EHMTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ namespace esphome
register_service(&EHMTX::full_screen, "full_screen", {"icon_name", "lifetime", "screen_time"});
register_service(&EHMTX::icon_screen, "icon_screen", {"icon_name", "text", "lifetime", "screen_time", "default_font", "r", "g", "b"});
register_service(&EHMTX::alert_screen, "alert_screen", {"icon_name","text", "screen_time", "default_font", "r", "g", "b"});
register_service(&EHMTX::rainbow_alert_screen, "rainbow_alert_screen", {"icon_name","text", "screen_time", "default_font"});
register_service(&EHMTX::icon_clock, "icon_clock", {"icon_name", "lifetime", "screen_time", "default_font", "r", "g", "b"});
register_service(&EHMTX::icon_date, "icon_date", {"icon_name", "lifetime", "screen_time", "default_font", "r", "g", "b"});
#ifdef USE_GRAPH
Expand Down Expand Up @@ -967,6 +968,7 @@ namespace esphome
infotext = this->queue[i]->icon_name.c_str();
break;
case MODE_ALERT_SCREEN:
case MODE_RAINBOW_ALERT_SCREEN:
infotext = ("alert: " + this->queue[i]->icon_name).c_str();
break;
case MODE_GRAPH_SCREEN:
Expand Down Expand Up @@ -1145,6 +1147,7 @@ namespace esphome
infotext = this->queue[this->screen_pointer]->icon_name.c_str();
break;
case MODE_ALERT_SCREEN:
case MODE_RAINBOW_ALERT_SCREEN:
infotext = ("alert: " + this->queue[this->screen_pointer]->icon_name).c_str();
break;
case MODE_GRAPH_SCREEN:
Expand Down Expand Up @@ -1410,6 +1413,41 @@ namespace esphome
force_screen(iconname, MODE_ALERT_SCREEN);
}

void EHMTX::rainbow_alert_screen(std::string iconname, std::string text, int screen_time, bool default_font)
{
uint8_t icon = this->find_icon(iconname.c_str());

if (icon == MAXICONS)
{
ESP_LOGW(TAG, "icon %d/%s not found => default: 0", icon, iconname.c_str());
icon = 0;
for (auto *t : on_icon_error_triggers_)
{
t->process(iconname);
}
}
EHMTX_queue *screen = this->find_mode_queue_element(MODE_RAINBOW_ALERT_SCREEN);

screen->text = text;

screen->text_color = Color(r, g, b);
screen->default_font = default_font;
screen->mode = MODE_RAINBOW_ALERT_SCREEN;
screen->icon_name = iconname;
screen->icon = icon;
screen->calc_scroll_time(text, screen_time);
// time needed for scrolling
screen->endtime = this->get_tick() + screen->screen_time_;
for (auto *t : on_add_screen_triggers_)
{
t->process(screen->icon_name, (uint8_t)screen->mode);
}
ESP_LOGD(TAG, "alert screen rainbow icon: %d iconname: %s text: %s screen_time: %d", icon, iconname.c_str(), text.c_str(), screen_time);
screen->status();

force_screen(iconname, MODE_RAINBOW_ALERT_SCREEN);
}

void EHMTX::icon_screen(std::string iconname, std::string text, int lifetime, int screen_time, bool default_font, int r, int g, int b)
{
std::string ic = get_icon_name(iconname);
Expand Down
4 changes: 3 additions & 1 deletion components/ehmtxv2/EHMTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ enum show_mode : uint8_t
MODE_RAINBOW_ICON_TEXT_SCREEN = 22,
MODE_BITMAP_STACK_SCREEN = 23,
MODE_TEXT_PROGRESS = 24,
MODE_PROGNOSIS_SCREEN = 25
MODE_PROGNOSIS_SCREEN = 25,
MODE_RAINBOW_ALERT_SCREEN = 26
};

namespace esphome
Expand Down Expand Up @@ -229,6 +230,7 @@ namespace esphome
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);
void alert_screen(std::string icon, std::string text, int screen_time = D_SCREEN_TIME, bool default_font = true, int r = CA_RED, int g = CA_GREEN, int b = CA_BLUE);
void rainbow_alert_screen(std::string icon, std::string text, int screen_time = D_SCREEN_TIME, bool default_font = true);
void icon_clock(std::string icon, 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 icon_date(std::string icon, 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 text_screen(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
10 changes: 8 additions & 2 deletions components/ehmtxv2/EHMTX_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ namespace esphome
ESP_LOGD(TAG, "queue: icon date: \"%s\" for: %.1f sec", this->icon_name.c_str(), this->screen_time_ / 1000.0);
break;
case MODE_ALERT_SCREEN:
ESP_LOGD(TAG, "queue: icon: \"%s\" for: %.1f sec", this->icon_name.c_str(), this->screen_time_ / 1000.0);
ESP_LOGD(TAG, "queue: alert icon: \"%s\" for: %.1f sec", this->icon_name.c_str(), this->screen_time_ / 1000.0);
break;
case MODE_RAINBOW_ALERT_SCREEN:
ESP_LOGD(TAG, "queue: rainbow alert icon: \"%s\" for: %.1f sec", this->icon_name.c_str(), this->screen_time_ / 1000.0);
break;
case MODE_TEXT_SCREEN:
ESP_LOGD(TAG, "queue: text text: \"%s\" for: %.1f sec", this->text.c_str(), this->screen_time_ / 1000.0);
Expand Down Expand Up @@ -190,6 +193,7 @@ namespace esphome
case MODE_ICON_CLOCK:
case MODE_ICON_DATE:
case MODE_ALERT_SCREEN:
case MODE_RAINBOW_ALERT_SCREEN:
case MODE_ICON_PROGRESS:
case MODE_PROGNOSIS_SCREEN:
startx = 8;
Expand Down Expand Up @@ -766,10 +770,11 @@ namespace esphome

case MODE_ICON_SCREEN:
case MODE_ALERT_SCREEN:
case MODE_RAINBOW_ALERT_SCREEN:
case MODE_RAINBOW_ICON:
case MODE_ICON_PROGRESS:
case MODE_PROGNOSIS_SCREEN:
color_ = (this->mode == MODE_RAINBOW_ICON) ? this->config_->rainbow_color : this->text_color;
color_ = (this->mode == MODE_RAINBOW_ICON || this->mode == MODE_RAINBOW_ALERT_SCREEN) ? this->config_->rainbow_color : this->text_color;
#ifdef EHMTXv2_USE_RTL
this->config_->display->print(this->xpos() + xoffset, this->ypos() + yoffset, font, color_, esphome::display::TextAlign::BASELINE_RIGHT,
this->text.c_str());
Expand Down Expand Up @@ -1060,6 +1065,7 @@ namespace esphome
case MODE_RAINBOW_BITMAP_SMALL:
case MODE_ICON_SCREEN:
case MODE_ALERT_SCREEN:
case MODE_RAINBOW_ALERT_SCREEN:
case MODE_ICON_PROGRESS:
case MODE_PROGNOSIS_SCREEN:
startx = 8;
Expand Down

0 comments on commit 063de74

Please sign in to comment.