Skip to content

Commit

Permalink
Merge pull request #108 from andrewjswan/2023.9.1-90-Graph_with_icon
Browse files Browse the repository at this point in the history
2023.9.1-90: Add Graph with icon screen
  • Loading branch information
lubeda authored Oct 12, 2023
2 parents 3c0ba1e + cf1a34d commit b50152d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,8 @@ Numerous features are accessible with services from home assistant and lambdas t
|`icon_screen_progress`|"icon_name", "text", "progress", "lifetime", "screen_time", "default_font", "r", "g", "b"|show the specified icon with text and with progress bar on bottom|
|`icon_clock`|"icon_name", "lifetime", "screen_time", "default_font", "r", "g", "b"|show the specified icon with time, there is support for [displaying text on top of the icon](#icon_text)|
|`icon_date`|"icon_name", "lifetime", "screen_time", "default_font", "r", "g", "b"|show the specified icon with date, there is support for [displaying text on top of the icon](#icon_text)|
|`graph_screen`|lifetime", "screen_time"|show graph as defined in the YAML file|
|`graph_screen`|"lifetime", "screen_time"|show graph as defined in the YAML file|
|`icon_graph_screen`|"icon_name", "lifetime", "screen_time"|show the specified icon with graph as defined in the YAML file|
|`set_infotext_color`|"left_r", "left_g", "left_b", "right_r", "right_g", "right_b","default_font","y_offset"|set the special color for left and right char on info text|

#### Parameter description
Expand Down
40 changes: 40 additions & 0 deletions components/ehmtxv2/EHMTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ namespace esphome
register_service(&EHMTX::icon_date, "icon_date", {"icon_name", "lifetime", "screen_time", "default_font", "r", "g", "b"});
#ifdef USE_GRAPH
register_service(&EHMTX::graph_screen, "graph_screen", {"lifetime", "screen_time"});
register_service(&EHMTX::icon_graph_screen, "icon_graph_screen", {"icon_name", "lifetime", "screen_time"});
#endif
register_service(&EHMTX::rainbow_icon_screen, "rainbow_icon_screen", {"icon_name", "text", "lifetime", "screen_time", "default_font"});

Expand Down Expand Up @@ -1391,11 +1392,50 @@ namespace esphome

screen->endtime = this->clock->now().timestamp + lifetime * 60;
screen->mode = MODE_GRAPH_SCREEN;
screen->icon = MAXICONS;
screen->screen_time_ = screen_time;

this->graph->set_height(8);
this->graph->set_width(32);

for (auto *t : on_add_screen_triggers_)
{
t->process("graph", (uint8_t)screen->mode);
}
screen->status();
}

void EHMTX::icon_graph_screen(std::string iconname, int lifetime, int screen_time)
{
uint8_t icon = this->find_icon(iconname.c_str());

if (icon >= this->icon_count)
{
ESP_LOGW(TAG, "graph screen with icon: icon %d not found => default: 0", icon);
for (auto *t : on_icon_error_triggers_)
{
t->process(iconname);
}
graph_screen(lifetime, screen_time);
return;
}

EHMTX_queue *screen = this->find_mode_queue_element(MODE_GRAPH_SCREEN);

screen->endtime = this->clock->now().timestamp + lifetime * 60;
screen->mode = MODE_GRAPH_SCREEN;
screen->icon = icon;
screen->icon_name = iconname;
screen->screen_time_ = screen_time;

this->graph->set_height(8);
this->graph->set_width(24);

for (auto *t : on_add_screen_triggers_)
{
t->process("graph", (uint8_t)screen->mode);
}
ESP_LOGD(TAG, "graph screen with icon: icon: %d iconname: %s lifetime: %d screen_time:%d ", icon, iconname.c_str(), lifetime, screen_time);
screen->status();
}

Expand Down
3 changes: 2 additions & 1 deletion components/ehmtxv2/EHMTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ namespace esphome
addressable_light::AddressableLightDisplay *display;
esphome::time::RealTimeClock *clock;
#ifdef USE_GRAPH
void graph_screen(int lifetime = 2 , int screen_time = 20);
void graph_screen(int lifetime = D_LIFETIME, int screen_time = D_SCREEN_TIME);
void icon_graph_screen(std::string icon, int lifetime = D_LIFETIME, int screen_time = D_SCREEN_TIME);
graph::Graph *graph;
#endif

Expand Down
10 changes: 9 additions & 1 deletion components/ehmtxv2/EHMTX_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,15 @@ namespace esphome

#ifdef USE_GRAPH
case MODE_GRAPH_SCREEN:
this->config_->display->graph(0,0, this->config_->graph);
if (this->icon == MAXICONS)
{
this->config_->display->graph(0, 0, this->config_->graph);
}
else
{
this->config_->display->graph(8, 0, this->config_->graph);
this->config_->display->image(0, 0, this->config_->icons[this->icon]);
}
break;
#endif

Expand Down

0 comments on commit b50152d

Please sign in to comment.