clean up preparation for rtl

pull/16/head
LuBeDa 3 years ago
parent bdfac44765
commit 72077bc160

@ -219,7 +219,7 @@ namespace esphome
void EHMTX::blank_screen(int lifetime, int showtime)
{
auto scr = this->find_free_queue_element();
scr->screen_time = showtime;
scr->screen_time_ = showtime;
scr->mode = MODE_BLANK;
scr->endtime = this->clock->now().timestamp + lifetime * 60;
}
@ -259,7 +259,7 @@ namespace esphome
{
ESP_LOGD(TAG, "force_screen: found position: %d", i);
this->queue[i]->last_time = 0;
this->queue[i]->endtime += this->queue[i]->screen_time;
this->queue[i]->endtime += this->queue[i]->screen_time_;
this->next_action_time = this->clock->now().timestamp;
ESP_LOGW(TAG, "force_screen: icon %s in mode %d", icon_name.c_str(), mode);
}
@ -322,7 +322,7 @@ namespace esphome
this->queue[i]->endtime = 0;
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());
ESP_LOGD(TAG, "remove expired queue element: 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_)
{
infotext = "";
@ -384,7 +384,7 @@ namespace esphome
if (this->screen_pointer != MAXQUEUE)
{
this->queue[this->screen_pointer]->shiftx_ = 0;
this->queue[this->screen_pointer]->last_time = ts + this->queue[this->screen_pointer]->screen_time;
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)
{
this->icons[this->queue[this->screen_pointer]->icon]->set_frame(0);
@ -544,35 +544,14 @@ namespace esphome
}
EHMTX_queue *screen = this->find_icon_queue_element(icon);
int x, y, pixel, h;
if (default_font)
{
this->display->get_text_bounds(0, 0, text.c_str(), this->default_font, display::TextAlign::LEFT, &x, &y, &pixel, &h);
}
else
{
this->display->get_text_bounds(0, 0, text.c_str(), this->special_font, display::TextAlign::LEFT, &x, &y, &pixel, &h);
}
if (pixel < 23)
{
screen->centerx_ = ceil((22 - pixel) / 2);
screen->screen_time = screen_time;
}
else
{
screen->centerx_ = 0;
int display_duration = ceil((this->scroll_count * (TEXTSTARTOFFSET + pixel) * this->scroll_interval) / 1000);
screen->screen_time = (display_duration > screen_time) ? display_duration : screen_time;
}
screen->text = text;
screen->pixels_ = pixel;
screen->endtime = this->clock->now().timestamp + lifetime * 60;
screen->shiftx_ = 0;
screen->text_color = Color(r, g, b);
screen->default_font = default_font;
screen->mode = MODE_ICON_SCREEN;
screen->icon_name = iconname;
screen->icon = icon;
screen->calc_scroll_time(text,screen_time);
for (auto *t : on_add_screen_triggers_)
{
t->process(screen->icon_name, (uint8_t)screen->mode);
@ -596,34 +575,14 @@ namespace esphome
}
EHMTX_queue *screen = this->find_icon_queue_element(icon);
int x, y, pixel, h;
if (default_font)
{
this->display->get_text_bounds(0, 0, text.c_str(), this->default_font, display::TextAlign::LEFT, &x, &y, &pixel, &h);
}
else
{
this->display->get_text_bounds(0, 0, text.c_str(), this->special_font, display::TextAlign::LEFT, &x, &y, &pixel, &h);
}
if (pixel < 23)
{
screen->centerx_ = ceil((22 - pixel) / 2);
screen->screen_time = screen_time;
}
else
{
screen->centerx_ = 0;
int display_duration = ceil((this->scroll_count * (TEXTSTARTOFFSET + pixel) * this->scroll_interval) / 1000);
screen->screen_time = (display_duration > screen_time) ? display_duration : screen_time;
}
screen->text = text;
screen->pixels_ = pixel;
screen->endtime = this->clock->now().timestamp + lifetime * 60;
screen->shiftx_ = 0;
screen->default_font = default_font;
screen->mode = MODE_RAINBOW_ICON;
screen->icon_name = iconname;
screen->icon = icon;
screen->calc_scroll_time(text,screen_time);
for (auto *t : on_add_screen_triggers_)
{
t->process(screen->icon_name, (uint8_t)screen->mode);
@ -639,7 +598,7 @@ namespace esphome
ESP_LOGD(TAG, "rainbow_clock_screen lifetime: %d screen_time: %d", lifetime, screen_time);
screen->mode = MODE_RAINBOW_CLOCK;
screen->default_font = default_font;
screen->screen_time = (screen_time > this->clock_interval)?screen_time:this->clock_interval-1;
screen->screen_time_ = (screen_time > this->clock_interval)?screen_time:this->clock_interval-1;
screen->endtime = this->clock->now().timestamp + lifetime * 60;
screen->status();
}
@ -651,7 +610,7 @@ namespace esphome
ESP_LOGD(TAG, "rainbow_date_screen lifetime: %d screen_time: %d", lifetime, screen_time);
screen->mode = MODE_RAINBOW_DATE;
screen->default_font = default_font;
screen->screen_time = screen_time;
screen->screen_time_ = screen_time;
screen->endtime = this->clock->now().timestamp + lifetime * 60;
screen->status();
}
@ -662,24 +621,21 @@ namespace esphome
screen->text = text;
screen->endtime = this->clock->now().timestamp + lifetime * 60;
screen->screen_time = screen_time;
screen->default_font = default_font;
screen->text_color = Color(r, g, b);
screen->mode = MODE_TEXT_SCREEN;
screen->calc_scroll_time();
screen->calc_scroll_time(text,screen_time);
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();
screen->text = text;
screen->endtime = this->clock->now().timestamp + lifetime * 60;
screen->screen_time = screen_time;
screen->default_font = default_font;
screen->mode = MODE_RAINBOW_TEXT;
screen->calc_scroll_time();
screen->calc_scroll_time(text,screen_time);
screen->status();
}
@ -701,7 +657,7 @@ namespace esphome
screen->mode = MODE_FULL_SCREEN;
screen->icon = icon;
screen->icon_name = iconname;
screen->screen_time = screen_time;
screen->screen_time_ = screen_time;
screen->endtime = this->clock->now().timestamp + lifetime * 60;
for (auto *t : on_add_screen_triggers_)
{
@ -719,7 +675,7 @@ namespace esphome
ESP_LOGD(TAG, "clock_screen_color lifetime: %d screen_time: %d red: %d green: %d blue: %d", lifetime, screen_time, r, g, b);
screen->mode = MODE_CLOCK;
screen->default_font = default_font;
screen->screen_time = (screen_time > this->clock_interval)?screen_time:this->clock_interval-1;
screen->screen_time_ = (this->clock_interval > screen_time )?screen_time:this->clock_interval-1;
screen->endtime = this->clock->now().timestamp + lifetime * 60;
screen->status();
}
@ -731,7 +687,7 @@ namespace esphome
screen->text_color = Color(r, g, b);
ESP_LOGD(TAG, "date_screen lifetime: %d screen_time: %d red: %d green: %d blue: %d", lifetime, screen_time, r, g, b);
screen->mode = MODE_DATE;
screen->screen_time = screen_time;
screen->screen_time_ = screen_time;
screen->default_font = default_font;
screen->endtime = this->clock->now().timestamp + lifetime * 60;
screen->status();
@ -777,6 +733,15 @@ namespace esphome
}
}
void EHMTX::set_rtl(bool b)
{
this->rtl = b;
if (b)
{
ESP_LOGI(TAG, "show text right to left");
}
}
void EHMTX::set_show_seconds(bool b)
{
this->show_seconds = b;

@ -67,6 +67,7 @@ namespace esphome
bool display_gauge;
bool is_running=false;
bool show_date;
bool rtl;
uint8_t gauge_value;
uint16_t clock_time;
uint8_t scroll_count;
@ -113,6 +114,7 @@ namespace esphome
void set_show_day_of_week(bool b);
void set_show_seconds(bool b);
void set_show_date(bool b);
void set_rtl(bool b);
void set_font_offset(int8_t x, int8_t y);
void set_week_start(bool b);
void set_brightness(int b);
@ -175,7 +177,7 @@ namespace esphome
uint8_t centerx_;
uint16_t shiftx_;
uint16_t pixels_;
uint16_t screen_time;
uint16_t screen_time_;
bool default_font;
time_t endtime;
time_t last_time;
@ -194,7 +196,7 @@ namespace esphome
bool update_slot(uint8_t _icon);
void update_screen();
void hold_slot(uint8_t _sec);
void calc_scroll_time();
void calc_scroll_time(std::string,uint16_t );
};
class EHMTXNextScreenTrigger : public Trigger<std::string, std::string>

@ -10,7 +10,7 @@ namespace esphome
this->last_time = 0;
this->centerx_ = 0;
this->shiftx_ = 0;
this->screen_time = 0;
this->screen_time_ = 0;
this->mode = MODE_EMPTY;
this->icon_name = "";
this->icon = 0;
@ -23,37 +23,37 @@ namespace esphome
switch (this->mode)
{
case MODE_EMPTY:
ESP_LOGD(TAG, "queue: empty slot");
ESP_LOGD(TAG, " empty slot");
break;
case MODE_BLANK:
ESP_LOGD(TAG, "queue: blank screen for %d sec", this->screen_time);
ESP_LOGD(TAG, "queue: blank screen for %d sec", this->screen_time_);
break;
case MODE_CLOCK:
ESP_LOGD(TAG, "queue: clock for %d sec", this->screen_time);
ESP_LOGD(TAG, "queue: clock for: %d sec", this->screen_time_);
break;
case MODE_DATE:
ESP_LOGD(TAG, "queue: date for %d sec", this->screen_time);
ESP_LOGD(TAG, "queue: date for: %d sec", this->screen_time_);
break;
case MODE_FULL_SCREEN:
ESP_LOGD(TAG, "queue: full screen: %s for %d sec", this->icon_name.c_str(), this->screen_time);
ESP_LOGD(TAG, "queue: full screen: \"%s\" for: %d sec", this->icon_name.c_str(), this->screen_time_);
break;
case MODE_ICON_SCREEN:
ESP_LOGD(TAG, "queue: icon screen: %s text: %s for %d sec", this->icon_name.c_str(), this->text.c_str(), this->screen_time);
ESP_LOGD(TAG, "queue: icon screen: \"%s\" text: %s for: %d sec", this->icon_name.c_str(), this->text.c_str(), this->screen_time_);
break;
case MODE_TEXT_SCREEN:
ESP_LOGD(TAG, "queue: text text: %s for %d sec", this->text.c_str(), this->screen_time);
ESP_LOGD(TAG, "queue: text text: \"%s\" for: %d sec", this->text.c_str(), this->screen_time_);
break;
case MODE_RAINBOW_ICON:
ESP_LOGD(TAG, "queue: rainbow icon: %s text: %s for %d sec", this->icon_name.c_str(), this->text.c_str(), this->screen_time);
ESP_LOGD(TAG, "queue: 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: rainbow text: %s for %d sec", this->text.c_str(), this->screen_time);
ESP_LOGD(TAG, "queue: rainbow text: \"%s\" for: %d sec", this->text.c_str(), this->screen_time_);
break;
case MODE_RAINBOW_CLOCK:
ESP_LOGD(TAG, "queue: clock for %d sec", this->screen_time);
ESP_LOGD(TAG, "queue: clock for: %d sec", this->screen_time_);
break;
case MODE_RAINBOW_DATE:
ESP_LOGD(TAG, "queue: date for %d sec", this->screen_time);
ESP_LOGD(TAG, "queue: date for: %d sec", this->screen_time_);
break;
default:
ESP_LOGD(TAG, "queue: UPPS");
@ -135,7 +135,8 @@ namespace esphome
{
this->config_->display->draw_pixel_at(0, 0, color_);
}
if (this->mode != MODE_RAINBOW_CLOCK){
if (this->mode != MODE_RAINBOW_CLOCK)
{
this->config_->draw_day_of_week();
}
}
@ -156,7 +157,8 @@ namespace esphome
{
this->config_->display->draw_pixel_at(0, 0, color_);
}
if (this->mode != MODE_RAINBOW_DATE){
if (this->mode != MODE_RAINBOW_DATE)
{
this->config_->draw_day_of_week();
}
}
@ -226,7 +228,7 @@ namespace esphome
// TODO void EHMTX_queue::set_mode_icon()
void EHMTX_queue::calc_scroll_time()
void EHMTX_queue::calc_scroll_time(std::string text, uint16_t screen_time)
{
int x, y, w, h;
float display_duration;
@ -240,33 +242,41 @@ namespace esphome
}
this->pixels_ = w;
this->centerx_ = 0;
this->shiftx_ = 0;
switch (this->mode)
{
case MODE_RAINBOW_TEXT:
case MODE_TEXT_SCREEN:
display_duration = ceil((28+(this->config_->scroll_count * (32 + this->pixels_)) * this->config_->scroll_interval) / 1000);
this->screen_time = (display_duration > this->screen_time) ? display_duration : this->screen_time;
if (this->pixels_ < 32)
{
this->screen_time_ = screen_time;
this->centerx_ = ceil((32 - this->pixels_) / 2);
}
else
{
display_duration = ceil((28 + (this->config_->scroll_count * (32 + this->pixels_)) * this->config_->scroll_interval) / 1000);
this->screen_time_ = (display_duration > screen_time) ? display_duration : screen_time;
}
break;
case MODE_RAINBOW_ICON:
case MODE_ICON_SCREEN:
display_duration = ceil(((28-TEXTSTARTOFFSET)+(this->config_->scroll_count * (TEXTSTARTOFFSET + this->pixels_)) * this->config_->scroll_interval) / 1000);
this->screen_time = (display_duration > this->screen_time) ? display_duration : this->screen_time;
if (this->pixels_ < 23)
{
this->screen_time_ = screen_time;
this->centerx_ = ceil((23 - this->pixels_) / 2);
}
else
{
display_duration = ceil((this->config_->scroll_count * (TEXTSTARTOFFSET + this->pixels_) * this->config_->scroll_interval) / 1000);
this->screen_time_ = (display_duration > screen_time) ? display_duration : screen_time;
}
break;
default:
break;
}
this->shiftx_ = 0;
ESP_LOGD(TAG, "display text: %s pixels %d calculated: %d", text.c_str(), this->pixels_, this->screen_time);
ESP_LOGD(TAG, "calc_scroll_time: mode: %d text: \"%s\" pixels %d calculated: %d defined: %d", this->mode, text.c_str(), this->pixels_, this->screen_time_, screen_time);
}
}

@ -66,6 +66,7 @@ CONF_LIFETIME = "lifetime"
CONF_ICONS = "icons"
CONF_SHOWDOW = "show_dow"
CONF_SHOWDATE = "show_date"
CONF_RTL = "rtl"
CONF_FRAMEDURATION = "frame_duration"
CONF_SCROLLCOUNT = "scroll_count"
CONF_MATRIXCOMPONENT = "matrix_component"
@ -105,6 +106,9 @@ EHMTX_SCHEMA = cv.Schema({
): cv.templatable(cv.positive_int),
cv.Optional(
CONF_HTML, default=False
): cv.boolean,
cv.Optional(
CONF_RTL, default=False
): cv.boolean,
cv.Optional(
CONF_SHOW_SECONDS, default=False
@ -362,6 +366,7 @@ async def to_code(config):
cg.add(var.set_brightness(config[CONF_BRIGHTNESS]))
cg.add(var.set_scroll_interval(config[CONF_SCROLLINTERVAL]))
cg.add(var.set_rainbow_interval(config[CONF_SCROLLINTERVAL]))
cg.add(var.set_rtl(config[CONF_RTL]))
cg.add(var.set_scroll_count(config[CONF_SCROLLCOUNT]))
cg.add(var.set_frame_interval(config[CONF_FRAMEINTERVAL]))
cg.add(var.set_week_start(config[CONF_WEEK_START_MONDAY]))

@ -117,6 +117,7 @@ ehmtxv2:
time_format: "%H:%M"
date_format: "%d.%m."
show_seconds: false
clock_interval: 90
default_font_id: default_font
special_font_id: default_font
icons:

Loading…
Cancel
Save