Skip to content

Commit

Permalink
trip5 and find_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lubeda committed Sep 23, 2023
1 parent ca983d4 commit b8b921b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void full_screen(string iconname, int =D_LIFETIME, int screen_time=D_SCREEN_TIME

##### icon clock

display the clock with an icon. the time format an the show_dow are the same as the normal clock.
display the clock with an icon. the time format an the show_dow are the same as the normal clock. take care of the font size, the time should not need more then 23 pixels width.

###### service via API

Expand Down
33 changes: 24 additions & 9 deletions components/ehmtxv2/EHMTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace esphome
this->bitmap[i++] = c;
}

EHMTX_queue *screen = this->find_free_queue_element();
EHMTX_queue *screen = this->find_mode_queue_element(MODE_BITMAP_SCREEN);

screen->text = "";
screen->endtime = this->clock->now().timestamp + lifetime * 60;
Expand Down Expand Up @@ -160,8 +160,8 @@ namespace esphome
this->sbitmap[i++] = c;
}

EHMTX_queue *screen = this->find_free_queue_element();

EHMTX_queue *screen = this->find_mode_queue_element(MODE_BITMAP_SMALL);
screen->text = text;
screen->text_color = Color(r, g, b);
screen->endtime = this->clock->now().timestamp + lifetime * 60;
Expand Down Expand Up @@ -794,7 +794,7 @@ namespace esphome
t->process(iconname);
}
}
EHMTX_queue *screen = this->find_free_queue_element();
EHMTX_queue *screen = this->find_mode_queue_element(MODE_ICON_CLOCK);

screen->endtime = this->clock->now().timestamp + lifetime * 60;
screen->text_color = Color(r, g, b);
Expand All @@ -807,7 +807,7 @@ namespace esphome
{
t->process(screen->icon_name, (uint8_t)screen->mode);
}
ESP_LOGD(TAG, "icon timen icon: %d iconname: %s lifetime: %d screen_time: %d", icon, iconname.c_str(), lifetime, screen_time);
ESP_LOGD(TAG, "icon clock icon: %d iconname: %s lifetime: %d screen_time: %d", icon, iconname.c_str(), lifetime, screen_time);
screen->status();
}

Expand Down Expand Up @@ -844,7 +844,7 @@ namespace esphome

void EHMTX::rainbow_clock_screen(int lifetime, int screen_time, bool default_font)
{
EHMTX_queue *screen = this->find_free_queue_element();
EHMTX_queue *screen = this->find_mode_queue_element(MODE_RAINBOW_CLOCK);

ESP_LOGD(TAG, "rainbow_clock_screen lifetime: %d screen_time: %d", lifetime, screen_time);
screen->mode = MODE_RAINBOW_CLOCK;
Expand All @@ -864,7 +864,7 @@ namespace esphome
void EHMTX::rainbow_date_screen(int lifetime, int screen_time, bool default_font)
{
ESP_LOGD(TAG, "rainbow_date_screen lifetime: %d screen_time: %d", lifetime, screen_time);
EHMTX_queue *screen = this->find_free_queue_element();
EHMTX_queue *screen = this->find_mode_queue_element(MODE_RAINBOW_DATE);

screen->mode = MODE_RAINBOW_DATE;
screen->default_font = default_font;
Expand Down Expand Up @@ -927,7 +927,7 @@ namespace esphome

void EHMTX::fire_screen( int lifetime, int screen_time)
{
EHMTX_queue *screen = this->find_icon_queue_element(0);
EHMTX_queue *screen = this->find_mode_queue_element(MODE_FIRE);
screen->mode = MODE_FIRE;
screen->icon = 0;
screen->screen_time_ = screen_time;
Expand Down Expand Up @@ -970,7 +970,7 @@ void EHMTX::fire_screen( int lifetime, int screen_time)

void EHMTX::clock_screen(int lifetime, int screen_time, bool default_font, int r, int g, int b)
{
EHMTX_queue *screen = this->find_free_queue_element();
EHMTX_queue *screen = this->find_mode_queue_element(MODE_CLOCK);
screen->text_color = Color(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;
Expand Down Expand Up @@ -1022,6 +1022,21 @@ void EHMTX::fire_screen( int lifetime, int screen_time)
return this->queue[0];
}

EHMTX_queue *EHMTX::find_mode_queue_element(uint8_t mode)
{
time_t ts = this->clock->now().timestamp;
for (size_t i = 0; i < MAXQUEUE; i++)
{
if (this->queue[i]->mode == mode)
{
ESP_LOGD(TAG, "find screen: found by mode %d", i);
return this->queue[i];
}
}
return this->find_free_queue_element();
}


void EHMTX::set_show_seconds(bool b)
{
this->show_seconds = b;
Expand Down
1 change: 1 addition & 0 deletions components/ehmtxv2/EHMTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace esphome
std::vector<EHMTXStartRunningTrigger *> on_start_running_triggers_;
std::vector<EHMTXAddScreenTrigger *> on_add_screen_triggers_;
EHMTX_queue *find_icon_queue_element(uint8_t icon);
EHMTX_queue *find_mode_queue_element(uint8_t mode);
EHMTX_queue *find_free_queue_element();

public:
Expand Down
10 changes: 5 additions & 5 deletions copy2esphome/easy_automation_extended_state.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ blueprint:
selector:
boolean:
default: true
darkpoet78_replace:
name: Use special character provided by darkpoet78 fonts (default=false)
description: If you are using the bdf fonts of https://github.com/darkpoet78/Matrix-Fonts you have to translate some character e.g. the euro sign. This flag actives the translation.
trip5_replace:
name: Use special character provided by trip5 fonts (default=false)
description: If you are using the bdf fonts of https://github.com/trip5/Matrix-Fonts you have to translate some character e.g. the euro sign. This flag actives the translation.
selector:
boolean:
default: false
Expand All @@ -100,13 +100,13 @@ variables:
{{trigger.to_state.state}} {{trigger.to_state.attributes.unit_of_measurement}}
textstr: |-
{% if bfriendly %}
{% if darkpoet78_replace %}
{% if trip5_replace %}
{{ f_text |replace ("€","¼")| replace ("°C","¬")|replace ("℃","¬")| replace ("°F","¯")|replace ("℉","¯")|replace ("₴","¾")|replace ("₿","¨")|replace ("₩","½")|replace ("Ξ","¸") }}
{% else %}
{{ f_text }}
{% endif %}
{% else %}
{% if darkpoet78_replace %}
{% if trip5_replace %}
{{ n_text |replace ("€","¼")| replace ("°C","¬")|replace ("℃","¬")| replace ("°F","¯")|replace ("℉","¯")|replace ("₴","¾")|replace ("₿","¨")|replace ("₩","½")|replace ("Ξ","¸") }}
{% else %}
{{ n_text }}
Expand Down

0 comments on commit b8b921b

Please sign in to comment.