remove shiftx

pull/16/head
LuBeDa 3 years ago
parent 6c7015752f
commit 31024249c9

@ -4,7 +4,7 @@
## Important information ## Important information
If you like my work, please donate me a star on GitHub and consider sponsoring me!! If you like my work, please donate me a star on GitHub and consider [sponsoring](https://www.paypal.com/donate/?hosted_button_id=FZDKSLQ46HJTU) me!!
## Introduction ## Introduction

@ -354,6 +354,7 @@ namespace esphome
} }
} }
} }
void EHMTX::tick() void EHMTX::tick()
{ {
this->hue_++; this->hue_++;
@ -371,75 +372,62 @@ namespace esphome
{ {
if (ts > this->next_action_time) if (ts > this->next_action_time)
{ {
this->scroll_step++;
this->remove_expired_queue_element(); this->remove_expired_queue_element();
this->screen_pointer = this->find_last_clock(); this->screen_pointer = this->find_last_clock();
if (this->screen_pointer == MAXQUEUE) if (this->screen_pointer == MAXQUEUE)
{ {
this->screen_pointer = find_oldest_queue_element(); this->screen_pointer = find_oldest_queue_element();
} }
switch (this->queue[this->screen_pointer]->mode) if (millis() - this->last_scroll_time >= this->scroll_interval)
{ {
case MODE_ICON_SCREEN: this->scroll_step++;
case MODE_RAINBOW_ICON: this->last_scroll_time = millis();
if (this->scroll_step > this->queue[this->screen_pointer]->pixels_ + 8)
if (this->scroll_step > this->queue[this->screen_pointer]->pixels_ + 32)
{ {
this->scroll_step = 0; this->scroll_step = 0;
} }
break; if (this->screen_pointer != MAXQUEUE)
case MODE_RAINBOW_TEXT:
case MODE_TEXT_SCREEN:
if (this->scroll_step > this->queue[this->screen_pointer]->pixels_ + 31)
{ {
this->scroll_step = 0; this->scroll_step = 0;
} this->queue[this->screen_pointer]->last_time = ts + this->queue[this->screen_pointer]->screen_time_;
break; if (this->queue[this->screen_pointer]->icon < this->icon_count)
} {
ESP_LOGD(TAG, "tick action Pointer: %d",this->screen_pointer); this->icons[this->queue[this->screen_pointer]->icon]->set_frame(0);
}
if (this->screen_pointer != MAXQUEUE) this->next_action_time = this->queue[this->screen_pointer]->last_time;
{ // Todo switch for Triggers
this->queue[this->screen_pointer]->shiftx_ = 0; if (this->queue[this->screen_pointer]->mode == MODE_CLOCK)
this->scroll_step = 0;
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);
}
this->next_action_time = this->queue[this->screen_pointer]->last_time;
// Todo switch for Triggers
if (this->queue[this->screen_pointer]->mode == MODE_CLOCK)
{
for (auto *t : on_next_clock_triggers_)
{ {
t->process(); for (auto *t : on_next_clock_triggers_)
{
t->process();
}
}
else
{
for (auto *t : on_next_screen_triggers_)
{
t->process(this->queue[this->screen_pointer]->icon_name, this->queue[this->screen_pointer]->text);
}
} }
} }
else else
{ {
for (auto *t : on_next_screen_triggers_) ESP_LOGW(TAG, "tick: nothing to do. Restarting clock display!");
{ this->clock_screen(24 * 60, this->clock_time, false, C_RED, C_GREEN, C_BLUE);
t->process(this->queue[this->screen_pointer]->icon_name, this->queue[this->screen_pointer]->text); this->date_screen(24 * 60, (int)this->clock_time / 2, false, C_RED, C_GREEN, C_BLUE);
} this->next_action_time = ts + this->clock_time;
} }
} }
else
{
ESP_LOGW(TAG, "tick: nothing to do. Restarting clock display!");
this->clock_screen(24 * 60, this->clock_time, false, C_RED, C_GREEN, C_BLUE);
this->date_screen(24 * 60, (int)this->clock_time / 2, false, C_RED, C_GREEN, C_BLUE);
this->next_action_time = ts + this->clock_time;
}
} }
} }
else else
{ {
ESP_LOGD(TAG, "tick rectangle %d", this->is_running); uint8_t w = (1 + (uint8_t)(32 / 16) * (this->boot_anim / 16)) % 32;
uint8_t w = (1 + (uint8_t)(32 / 16) * (this->boot_anim / 16)) % 32; this->display->rectangle(0, 2, w, 4, this->rainbow_color); // Color(120, 190, 40));
this->display->rectangle(0, 2, w, 4, this->rainbow_color); // Color(120, 190, 40)); this->boot_anim++;
this->boot_anim++; }
}
} }
void EHMTX::skip_screen() void EHMTX::skip_screen()
@ -617,7 +605,14 @@ namespace esphome
ESP_LOGD(TAG, "rainbow_clock_screen lifetime: %d screen_time: %d", lifetime, screen_time); ESP_LOGD(TAG, "rainbow_clock_screen lifetime: %d screen_time: %d", lifetime, screen_time);
screen->mode = MODE_RAINBOW_CLOCK; screen->mode = MODE_RAINBOW_CLOCK;
screen->default_font = default_font; screen->default_font = default_font;
screen->screen_time_ = (screen_time > this->clock_interval) ? screen_time : this->clock_interval - 1; if (this->clock_interval == 0 || (this->clock_interval > screen_time))
{
screen->screen_time_ = screen_time;
}
else
{
screen->screen_time_ = this->clock_interval - 2;
}
screen->endtime = this->clock->now().timestamp + lifetime * 60; screen->endtime = this->clock->now().timestamp + lifetime * 60;
screen->status(); screen->status();
} }
@ -694,10 +689,13 @@ 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); 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->mode = MODE_CLOCK;
screen->default_font = default_font; screen->default_font = default_font;
if (this->clock_interval ==0 || (this->clock_interval > screen_time )) { if (this->clock_interval == 0 || (this->clock_interval > screen_time))
{
screen->screen_time_ = screen_time; screen->screen_time_ = screen_time;
} else { }
screen->screen_time_ = this->clock_interval-2; else
{
screen->screen_time_ = this->clock_interval - 2;
} }
screen->endtime = this->clock->now().timestamp + lifetime * 60; screen->endtime = this->clock->now().timestamp + lifetime * 60;
screen->status(); screen->status();

@ -37,7 +37,7 @@ namespace esphome
class EHMTX : public PollingComponent, public api::CustomAPIDevice { class EHMTX : public PollingComponent, public api::CustomAPIDevice {
protected: protected:
float get_setup_priority() const override { return esphome::setup_priority::WIFI; } float get_setup_priority() const override { return esphome::setup_priority::BEFORE_CONNECTION; }
uint8_t brightness_; uint8_t brightness_;
uint32_t boot_anim=0; uint32_t boot_anim=0;
uint8_t screen_pointer; uint8_t screen_pointer;
@ -109,7 +109,7 @@ namespace esphome
void skip_screen(); void skip_screen();
void hold_screen(int t=30); void hold_screen(int t=30);
void set_display(addressable_light::AddressableLightDisplay *disp); void set_display(addressable_light::AddressableLightDisplay *disp);
void set_clock_interval(uint16_t t=60); void set_clock_interval(uint16_t t=90);
void set_hold_time(uint16_t t=30); void set_hold_time(uint16_t t=30);
void set_clock_time(uint16_t t=10); void set_clock_time(uint16_t t=10);
void set_show_day_of_week(bool b); void set_show_day_of_week(bool b);
@ -176,7 +176,6 @@ namespace esphome
public: public:
uint8_t centerx_; uint8_t centerx_;
uint16_t shiftx_;
uint16_t pixels_; uint16_t pixels_;
uint16_t screen_time_; uint16_t screen_time_;
bool default_font; bool default_font;

@ -9,7 +9,6 @@ namespace esphome
this->endtime = 0; this->endtime = 0;
this->last_time = 0; this->last_time = 0;
this->centerx_ = 0; this->centerx_ = 0;
this->shiftx_ = 0;
this->screen_time_ = 0; this->screen_time_ = 0;
this->mode = MODE_EMPTY; this->mode = MODE_EMPTY;
this->icon_name = ""; this->icon_name = "";
@ -91,7 +90,7 @@ namespace esphome
} }
else else
{ {
return startx + this->shiftx_; return startx + this->config_->scroll_step;
} }
} }
else else
@ -102,7 +101,7 @@ namespace esphome
} }
else else
{ {
return startx - this->shiftx_ + width; return startx - this->config_->scroll_step + width;
} }
} }
} }
@ -122,32 +121,6 @@ namespace esphome
this->config_->last_rainbow_time = millis(); this->config_->last_rainbow_time = millis();
} }
if ((this->mode == MODE_ICON_SCREEN) || (this->mode == MODE_RAINBOW_ICON))
{
if (millis() - this->config_->last_scroll_time >= this->config_->scroll_interval && this->pixels_ > TEXTSTARTOFFSET)
{
this->shiftx_++;
if (this->shiftx_ > this->pixels_ + TEXTSTARTOFFSET)
{
this->shiftx_ = 0;
}
this->config_->last_scroll_time = millis();
}
}
if ((this->mode == MODE_TEXT_SCREEN) || (this->mode == MODE_RAINBOW_TEXT))
{
if (millis() - this->config_->last_scroll_time >= this->config_->scroll_interval && this->pixels_ >= 32)
{
this->shiftx_++;
if (this->shiftx_ > this->pixels_ + 32)
{
this->shiftx_ = 0;
}
this->config_->last_scroll_time = millis();
}
}
if (millis() - this->config_->last_anim_time >= this->config_->icons[this->icon]->frame_duration) if (millis() - this->config_->last_anim_time >= this->config_->icons[this->icon]->frame_duration)
{ {
this->config_->icons[this->icon]->next_frame(); this->config_->icons[this->icon]->next_frame();
@ -230,13 +203,15 @@ namespace esphome
} }
color_ = (this->mode == MODE_RAINBOW_ICON) ? this->config_->rainbow_color : this->text_color; color_ = (this->mode == MODE_RAINBOW_ICON) ? this->config_->rainbow_color : this->text_color;
if (this->config_->rtl) { if (this->config_->rtl)
{
this->config_->display->print(this->xpos() + xoffset, yoffset, font, color_, esphome::display::TextAlign::BASELINE_RIGHT, this->config_->display->print(this->xpos() + xoffset, yoffset, font, color_, esphome::display::TextAlign::BASELINE_RIGHT,
this->text.c_str()); this->text.c_str());
} }
else { else
{
this->config_->display->print(this->xpos() + xoffset, yoffset, font, color_, esphome::display::TextAlign::BASELINE_LEFT, this->config_->display->print(this->xpos() + xoffset, yoffset, font, color_, esphome::display::TextAlign::BASELINE_LEFT,
this->text.c_str()); this->text.c_str());
} }
if (this->config_->display_gauge) if (this->config_->display_gauge)
{ {
@ -295,7 +270,6 @@ namespace esphome
this->pixels_ = w; this->pixels_ = w;
this->centerx_ = 0; this->centerx_ = 0;
this->shiftx_ = 0;
switch (this->mode) switch (this->mode)
{ {

Loading…
Cancel
Save