rainbow icon/text partily working

pull/2/head
LuBeDa 3 years ago
parent 2a8ad1e3f8
commit 0a8ea1388e

@ -14,7 +14,7 @@ namespace esphome
this->today_color = Color(C_RED, C_GREEN, C_BLUE);
this->weekday_color = Color(CD_RED, CD_GREEN, CD_BLUE);
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;
@ -186,6 +186,8 @@ namespace esphome
register_service(&EHMTX::clock_screen, "clock_screen", {"lifetime", "screen_time", "default_font", "r", "g", "b"});
register_service(&EHMTX::blank_screen, "blank_screen", {"lifetime", "screen_time"});
register_service(&EHMTX::date_screen, "date_screen", {"lifetime", "screen_time", "default_font", "r", "g", "b"});
register_service(&EHMTX::rainbow_icon_screen, "rainbow_icon_screen", {"icon_name", "text", "lifetime", "screen_time", "default_font"});
register_service(&EHMTX::rainbow_text_screen, "rainbow_text_screen", {"text", "lifetime", "screen_time", "default_font"});
register_service(&EHMTX::set_brightness, "brightness", {"value"});
@ -230,7 +232,7 @@ namespace esphome
if (this->queue[i]->mode == mode)
{
bool force = true;
if ((mode == MODE_ICONSCREEN)||(mode == MODE_FULLSCREEN))
if ((mode == MODE_ICONSCREEN) || (mode == MODE_FULLSCREEN) || (mode == MODE_RAINBOW_ICON))
{
if (strcmp(this->queue[i]->icon_name.c_str(), icon_name.c_str()) != 0)
{
@ -277,7 +279,7 @@ namespace esphome
if ((this->queue[i]->endtime > 0) && (this->queue[i]->endtime < ts))
{
this->queue[i]->endtime = 0;
if ((this->queue[i]->mode == MODE_ICONSCREEN) || (this->queue[i]->mode == MODE_FULLSCREEN))
if (this->queue[i]->mode != MODE_EMPTY)
{
ESP_LOGD(TAG, "remove_expired_queue_element: removed slot %d: icon_name: %s text: %s", i, this->queue[i]->icon_name.c_str(), this->queue[i]->text.c_str());
for (auto *t : on_expired_screen_triggers_)
@ -299,8 +301,10 @@ namespace esphome
infotext = "fullscreen " + this->queue[i]->icon_name;
break;
case MODE_ICONSCREEN:
case MODE_RAINBOW_ICON:
infotext = this->queue[i]->icon_name.c_str();
break;
case MODE_RAINBOW_TEXT:
case MODE_TEXT:
infotext = "TEXT";
break;
@ -328,7 +332,8 @@ namespace esphome
{
this->queue[this->screen_pointer]->reset_shiftx();
this->queue[this->screen_pointer]->last_time = ts + this->queue[this->screen_pointer]->screen_time;
if (this->queue[this->screen_pointer]->icon < this->icon_count) {
if (this->queue[this->screen_pointer]->icon < this->icon_count)
{
this->icons[this->queue[this->screen_pointer]->icon]->set_frame(0);
}
this->next_action_time = this->queue[this->screen_pointer]->last_time;
@ -357,9 +362,10 @@ namespace esphome
}
}
}
else {
else
{
uint8_t w = ((uint8_t)(32 / 14) * (this->boot_anim / 14)) % 32;
this->display->rectangle(0,1,w,6,Color(120,190,40));
this->display->rectangle(0, 2, w, 4, Color(120, 190, 40));
this->boot_anim++;
}
}
@ -452,7 +458,7 @@ namespace esphome
if (this->queue[i]->mode == mode)
{
bool force = true;
if ((mode == MODE_ICONSCREEN)||(mode == MODE_FULLSCREEN))
if ((mode == MODE_ICONSCREEN) || (mode == MODE_FULLSCREEN) || (mode == MODE_RAINBOW_ICON))
{
if (strcmp(this->queue[i]->icon_name.c_str(), icon_name.c_str()) != 0)
{
@ -464,7 +470,8 @@ namespace esphome
this->queue[i]->mode = MODE_EMPTY;
this->queue[i]->endtime = 0;
ESP_LOGW(TAG, "del_screen: icon %s in position: %d mode %d", icon_name.c_str(), i, mode);
if (i == this->screen_pointer){
if (i == this->screen_pointer)
{
this->next_action_time = this->clock->now().timestamp;
}
}
@ -501,9 +508,9 @@ namespace esphome
screen->status();
}
void EHMTX::timer_screen(std::string icon_name, int seconds, int lifetime, int screen_time, bool default_font, int r, int g, int b)
void EHMTX::rainbow_icon_screen(std::string iconname, std::string text, int lifetime, int screen_time, bool default_font)
{
uint8_t icon = this->find_icon(icon_name.c_str());
uint8_t icon = this->find_icon(iconname.c_str());
if (icon >= this->icon_count)
{
@ -512,15 +519,20 @@ namespace esphome
}
EHMTX_queue *screen = this->find_icon_queue_element(icon);
screen->text = "00:00";
screen->icon = icon;
screen->text_color = Color(r, g, b);
int x, y, w, h;
if (default_font)
{
this->display->get_text_bounds(0, 0, text.c_str(), this->default_font, display::TextAlign::LEFT, &x, &y, &w, &h);
}
else
{
this->display->get_text_bounds(0, 0, text.c_str(), this->special_font, display::TextAlign::LEFT, &x, &y, &w, &h);
}
screen->set_text(text, icon, w, lifetime, screen_time);
screen->default_font = default_font;
screen->mode = MODE_TIMER;
screen->icon_name = icon_name;
screen->screen_time = screen_time;
screen->endtime = this->clock->now().timestamp + lifetime * 60;
ESP_LOGD(TAG, "TIMER_screen icon: %d icon_ name: %s seconds: %d lifetime: %d screen_time: %d", icon, icon_name.c_str(), seconds, lifetime, screen_time);
screen->mode = MODE_RAINBOW_ICON;
screen->icon_name = iconname;
ESP_LOGD(TAG, "rainbow_icon_screen icon: %d iconname: %s text: %s lifetime: %d screen_time: %d", icon, iconname.c_str(), text.c_str(), lifetime, screen_time);
screen->status();
}
@ -558,6 +570,39 @@ namespace esphome
screen->status();
}
void EHMTX::rainbow_text_screen(std::string text, int lifetime, int screen_time, bool default_font)
{
EHMTX_queue *screen = this->find_free_queue_element();
int x, y, w, h;
if (default_font)
{
this->display->get_text_bounds(0, 0, text.c_str(), this->default_font, display::TextAlign::LEFT, &x, &y, &w, &h);
}
else
{
this->display->get_text_bounds(0, 0, text.c_str(), this->special_font, display::TextAlign::LEFT, &x, &y, &w, &h);
}
screen->text = text;
screen->pixels_ = w;
if (screen->pixels_ < 32)
{
screen->centerx_ = ceil((32 - screen->pixels_) / 2);
}
screen->shiftx_ = 0;
float display_duration = ceil((this->scroll_count * w * this->scroll_interval) / 1000);
screen->screen_time = (display_duration > screen_time) ? display_duration : screen_time;
ESP_LOGD(TAG, "text_screen text: text: %s pixels %d screen_time: %d lifetime: %d", text.c_str(), w, screen->screen_time, lifetime);
screen->endtime = this->clock->now().timestamp + lifetime * 60;
screen->default_font = default_font;
screen->mode = MODE_RAINBOW_TEXT;
screen->status();
}
void EHMTX::fullscreen(std::string iconname, int lifetime, int screen_time)
{
uint8_t icon = this->find_icon(iconname.c_str());

@ -23,7 +23,7 @@ const uint8_t TEXTSTARTOFFSET = (32 - 8);
const uint16_t TICKINTERVAL = 1000; // each 1000ms
static const char *const EHMTX_VERSION = "Version: 2023.5.0";
static const char *const TAG = "EHMTX";
enum show_mode : uint8_t { MODE_EMPTY = 0,MODE_BLANK = 1, MODE_CLOCK = 2, MODE_DATE = 3, MODE_FULLSCREEN = 4, MODE_ICONSCREEN = 5, MODE_TEXT = 6 , MODE_TIMER = 7,MODE_RAINBOW_TEXT = 8 };
enum show_mode : uint8_t { MODE_EMPTY = 0,MODE_BLANK = 1, MODE_CLOCK = 2, MODE_DATE = 3, MODE_FULLSCREEN = 4, MODE_ICONSCREEN = 5, MODE_TEXT = 6 , MODE_RAINBOW_ICON = 7,MODE_RAINBOW_TEXT = 8 };
namespace esphome
{
@ -135,11 +135,12 @@ namespace esphome
void fullscreen(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 timer_screen(std::string icon, int seconds, 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);
void clock_screen(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 date_screen(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 blank_screen(int lifetime=D_LIFETIME, int screen_time=D_SCREEN_TIME);
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);
void del_screen(std::string icon, int mode=MODE_ICONSCREEN);
@ -178,7 +179,6 @@ namespace esphome
void status();
void draw();
void draw_();
bool isfree();
void reset_shiftx();
bool update_slot(uint8_t _icon);

@ -42,8 +42,11 @@ namespace esphome
case MODE_TEXT:
ESP_LOGD(TAG, "queue: show text text: %s for %d sec", this->text.c_str(), this->screen_time);
break;
case MODE_TIMER:
ESP_LOGD(TAG, "queue: show timer text: %s for %d sec", this->text.c_str(), this->screen_time);
case MODE_RAINBOW_ICON:
ESP_LOGD(TAG, "queue: show rainbow icon: %s text: %s for %d sec",this->icon_name.c_str(), this->text.c_str(), this->screen_time);
break;
case MODE_RAINBOW_TEXT:
ESP_LOGD(TAG, "queue: show rainbow text: %s for %d sec", this->text.c_str(), this->screen_time);
break;
default:
ESP_LOGD(TAG, "queue: UPPS");
@ -81,7 +84,7 @@ namespace esphome
this->config_->rainbow_color = Color(uint8_t (255 * red),uint8_t (255 * green),uint8_t (255 * blue));
}
if (this->mode == MODE_ICONSCREEN)
if (this->mode == MODE_ICONSCREEN || this->mode == MODE_RAINBOW_ICON)
{
if (millis() - this->config_->last_scroll_time >= this->config_->scroll_interval && this->pixels_ > TEXTSTARTOFFSET)
{
@ -93,7 +96,7 @@ namespace esphome
this->config_->last_scroll_time = millis();
}
}
if (this->mode == MODE_TEXT)
if (this->mode == MODE_TEXT || this->mode == MODE_RAINBOW_TEXT)
{
if (millis() - this->config_->last_scroll_time >= this->config_->scroll_interval && this->pixels_ >= 32)
{
@ -114,16 +117,13 @@ namespace esphome
}
}
void EHMTX_queue::draw_()
{
}
void EHMTX_queue::draw()
{
display::Font *font = this->default_font ? this->config_->default_font : this->config_->special_font;
int8_t yoffset = this->default_font ? this->config_->default_xoffset : this->config_->special_xoffset;
int8_t xoffset = this->default_font ? this->config_->default_yoffset : this->config_->special_yoffset;
int8_t extraoffset = 0;
Color color_=Color(40,140,0);
switch (this->mode)
{
@ -168,7 +168,7 @@ namespace esphome
case MODE_FULLSCREEN:
this->config_->display->image(0, 0, this->config_->icons[this->icon]);
break;
case MODE_ICONSCREEN:
case MODE_ICONSCREEN: case MODE_RAINBOW_ICON:
{
if (this->pixels_ > TEXTSTARTOFFSET)
{
@ -179,7 +179,8 @@ namespace esphome
extraoffset += 2;
}
this->config_->display->print(this->centerx_ + TEXTSCROLLSTART - this->shiftx_ + extraoffset + xoffset, yoffset, font, this->text_color, esphome::display::TextAlign::BASELINE_LEFT,
color_ = (this->mode == MODE_RAINBOW_TEXT)?this->config_->rainbow_color:this->text_color;
this->config_->display->print(this->centerx_ + TEXTSCROLLSTART - this->shiftx_ + extraoffset + xoffset, yoffset, font, color_, esphome::display::TextAlign::BASELINE_LEFT,
this->text.c_str());
if (this->config_->display_alarm)
@ -202,7 +203,7 @@ namespace esphome
}
}
break;
case MODE_TEXT:
case MODE_TEXT: case MODE_RAINBOW_TEXT:
if (this->pixels_ > 32)
{
@ -212,13 +213,8 @@ namespace esphome
{
extraoffset += 2;
}
this->config_->display->print(this->centerx_ - this->shiftx_ + xoffset + extraoffset, yoffset, font, this->text_color, esphome::display::TextAlign::BASELINE_LEFT,
this->text.c_str());
break;
case MODE_TIMER:
this->config_->display->image(0, 0, this->config_->icons[this->icon]);
this->config_->display->print(9+xoffset, yoffset, font, this->config_->rainbow_color, esphome::display::TextAlign::BASELINE_LEFT,
color_ = (this->mode== MODE_RAINBOW_TEXT)?this->config_->rainbow_color:this->text_color;
this->config_->display->print(this->centerx_ - this->shiftx_ + xoffset + extraoffset, yoffset, font, color_, esphome::display::TextAlign::BASELINE_LEFT,
this->text.c_str());
break;
default:

@ -34,6 +34,10 @@ blueprint:
value: "4"
- label: MODE_TEXT
value: "6"
- label: MODE_RAINBOW_ICON
value: "7"
- label: MODE_RAINBOW_TEXT
value: "8"
default: "5"
icon_name:
name: the icon

Loading…
Cancel
Save