remove shiftx

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

@ -4,7 +4,7 @@
## 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

@ -354,6 +354,7 @@ namespace esphome
}
}
}
void EHMTX::tick()
{
this->hue_++;
@ -371,75 +372,62 @@ namespace esphome
{
if (ts > this->next_action_time)
{
this->scroll_step++;
this->remove_expired_queue_element();
this->screen_pointer = this->find_last_clock();
if (this->screen_pointer == MAXQUEUE)
{
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:
case MODE_RAINBOW_ICON:
if (this->scroll_step > this->queue[this->screen_pointer]->pixels_ + 8)
this->scroll_step++;
this->last_scroll_time = millis();
if (this->scroll_step > this->queue[this->screen_pointer]->pixels_ + 32)
{
this->scroll_step = 0;
}
break;
case MODE_RAINBOW_TEXT:
case MODE_TEXT_SCREEN:
if (this->scroll_step > this->queue[this->screen_pointer]->pixels_ + 31)
if (this->screen_pointer != MAXQUEUE)
{
this->scroll_step = 0;
}
break;
}
ESP_LOGD(TAG, "tick action Pointer: %d",this->screen_pointer);
if (this->screen_pointer != MAXQUEUE)
{
this->queue[this->screen_pointer]->shiftx_ = 0;
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_)
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();
}
}
else
{
t->process();
for (auto *t : on_next_screen_triggers_)
{
t->process(this->queue[this->screen_pointer]->icon_name, this->queue[this->screen_pointer]->text);
}
}
}
else
{
for (auto *t : on_next_screen_triggers_)
{
t->process(this->queue[this->screen_pointer]->icon_name, this->queue[this->screen_pointer]->text);
}
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
{
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
{
ESP_LOGD(TAG, "tick rectangle %d", this->is_running);
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->boot_anim++;
}
{
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->boot_anim++;
}
}
void EHMTX::skip_screen()
@ -617,7 +605,14 @@ 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;
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->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);
screen->mode = MODE_CLOCK;
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;
} 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->status();

@ -37,7 +37,7 @@ namespace esphome
class EHMTX : public PollingComponent, public api::CustomAPIDevice {
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_;
uint32_t boot_anim=0;
uint8_t screen_pointer;
@ -109,7 +109,7 @@ namespace esphome
void skip_screen();
void hold_screen(int t=30);
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_clock_time(uint16_t t=10);
void set_show_day_of_week(bool b);
@ -176,7 +176,6 @@ namespace esphome
public:
uint8_t centerx_;
uint16_t shiftx_;
uint16_t pixels_;
uint16_t screen_time_;
bool default_font;

@ -9,7 +9,6 @@ namespace esphome
this->endtime = 0;
this->last_time = 0;
this->centerx_ = 0;
this->shiftx_ = 0;
this->screen_time_ = 0;
this->mode = MODE_EMPTY;
this->icon_name = "";
@ -76,7 +75,7 @@ namespace esphome
// no correction
break;
}
if (this->config_->display_gauge)
{
startx += 2;
@ -91,7 +90,7 @@ namespace esphome
}
else
{
return startx + this->shiftx_;
return startx + this->config_->scroll_step;
}
}
else
@ -102,7 +101,7 @@ namespace esphome
}
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();
}
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)
{
this->config_->icons[this->icon]->next_frame();
@ -194,7 +167,7 @@ namespace esphome
break;
case MODE_RAINBOW_DATE:
case MODE_DATE:
if (this->config_->clock->now().is_valid())
if (this->config_->clock->now().is_valid())
{
color_ = (this->mode == MODE_RAINBOW_DATE) ? this->config_->rainbow_color : this->config_->clock_color;
time_t ts = this->config_->clock->now().timestamp;
@ -230,13 +203,15 @@ namespace esphome
}
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->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->text.c_str());
this->text.c_str());
}
if (this->config_->display_gauge)
{
@ -295,12 +270,11 @@ namespace esphome
this->pixels_ = w;
this->centerx_ = 0;
this->shiftx_ = 0;
switch (this->mode)
{
case MODE_RAINBOW_TEXT:
case MODE_TEXT_SCREEN:
case MODE_TEXT_SCREEN:
if (this->pixels_ < 32)
{
this->screen_time_ = screen_time;

Loading…
Cancel
Save