This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
/
EHMTX.h
422 lines (365 loc) · 10.9 KB
/
EHMTX.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
#ifndef EHMTX_H
#define EHMTX_H
#include "esphome.h"
const uint8_t MAXQUEUE = 24;
const uint8_t MAXICONS = 64;
const uint8_t TEXTSCROLLSTART = 8;
const uint8_t TEXTSTARTOFFSET = (32 - 8);
const uint16_t TICKINTERVAL = 1000; // each 1000ms
static const char *const EHMTX_VERSION = "Version: 2023.2.0";
static const char *const TAG = "EHMTX";
namespace esphome
{
class EHMTX_screen;
class EHMTX_store;
class EhmtxSelect;
class EHMTX_Icon;
class EHMTXNextScreenTrigger;
class EHMTX : public PollingComponent
{
protected:
float get_setup_priority() const override { return esphome::setup_priority::AFTER_CONNECTION; }
uint8_t brightness_;
bool week_starts_monday;
bool show_day_of_week;
std::string time_fmt;
std::string date_fmt;
Color indicator_color;
Color clock_color;
Color today_color;
Color weekday_color;
EHMTX_store *store;
std::vector<EHMTXNextScreenTrigger *> on_next_screen_triggers_;
void internal_add_screen(uint8_t icon, std::string text, uint16_t duration, bool alarm);
public:
EHMTX();
Color text_color, alarm_color, gauge_color;
void dump_config();
bool show_screen;
bool show_indicator;
bool show_gauge;
bool show_date;
uint8_t gauge_value;
bool show_icons;
void force_screen(std::string name);
EHMTX_Icon *icons[MAXICONS];
EHMTX_screen *icon_screen;
void add_icon(EHMTX_Icon *icon);
#ifdef USE_EHMTX_SELECT
std::vector<std::string> select_options;
esphome::EhmtxSelect *select;
void set_select(esphome::EhmtxSelect *es);
#endif
addressable_light::AddressableLightDisplay *display;
time::RealTimeClock *clock;
display::Font *font;
int8_t yoffset, xoffset;
uint8_t find_icon(std::string name);
uint16_t duration; // in minutes how long is a screen valid
uint16_t scroll_intervall; // ms to between scrollsteps
uint16_t anim_intervall; // ms to next_frame()
uint16_t clock_time; // seconds display of screen_time - clock_time = date_time
uint16_t screen_time; // seconds display of screen
uint8_t icon_count; // max iconnumber -1
unsigned long last_scroll_time;
unsigned long last_anim_time;
time_t last_clock_time = 0; // starttime clock display
time_t next_action_time = 0; // when is the next screen change
void draw_day_of_week();
void show_all_icons();
void tick();
void draw();
void get_status();
void skip_screen();
std::string get_current();
void set_display(addressable_light::AddressableLightDisplay *disp);
void set_screen_time(uint16_t t);
void set_clock_time(uint16_t t);
void set_show_day_of_week(bool b);
void set_show_date(bool b);
void set_font_offset(int8_t x, int8_t y);
void set_week_start(bool b);
void set_default_brightness(uint8_t b);
void set_brightness(uint8_t b);
uint8_t get_brightness();
void add_screen(std::string icon, std::string text, uint16_t duration, bool alarm);
void del_screen(std::string iname);
void set_clock(time::RealTimeClock *clock);
void set_font(display::Font *font);
void set_anim_intervall(uint16_t intervall);
void set_scroll_intervall(uint16_t intervall);
void set_duration(uint8_t d);
void set_indicator_off();
void set_time_format(std::string s);
void set_date_format(std::string s);
void set_indicator_on();
void set_indicator_color(int r, int g, int b);
void set_gauge_off();
void set_gauge_value(uint8_t v);
void set_gauge_color(int r, int g, int b);
void set_text_color(int r, int g, int b);
void set_clock_color(int r, int g, int b);
void set_today_color(int r, int g, int b);
void set_weekday_color(int r, int g, int b);
void set_alarm_color(int r, int g, int b);
void set_icon_count(uint8_t ic);
void draw_clock();
void add_on_next_screen_trigger(EHMTXNextScreenTrigger *t) { this->on_next_screen_triggers_.push_back(t); }
void setup();
void update();
};
class EHMTX_store
{
protected:
EHMTX_screen *slots[MAXQUEUE];
uint8_t active_slot;
uint8_t force_screen;
uint8_t count_active_screens();
public:
EHMTX_store(EHMTX *config);
void force_next_screen(uint8_t icon_id);
time::RealTimeClock *clock;
EHMTX_screen *find_free_screen(uint8_t icon);
void delete_screen(uint8_t icon);
bool move_next();
EHMTX_screen *current();
void log_status();
};
class EHMTX_screen
{
protected:
uint8_t shiftx_;
uint8_t pixels_;
EHMTX *config_;
public:
uint16_t display_duration;
bool alarm;
time_t endtime;
uint8_t icon;
std::string text;
EHMTX_screen(EHMTX *config);
bool active();
bool is_alarm();
void draw();
void draw_();
bool isfree();
bool update_slot(uint8_t _icon);
void update_screen();
bool del_slot(uint8_t _icon);
void set_text(std::string text, uint8_t icon, uint8_t pixel, uint16_t et);
};
class EHMTXNextScreenTrigger : public Trigger<std::string, std::string>
{
public:
explicit EHMTXNextScreenTrigger(EHMTX *parent) { parent->add_on_next_screen_trigger(this); }
void process(std::string, std::string);
};
template <typename... Ts>
class SetBrightnessAction : public Action<Ts...>
{
public:
SetBrightnessAction(EHMTX *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(uint8_t, brightness)
void play(Ts... x) override
{
auto brightness = this->brightness_.value(x...);
this->parent_->set_brightness(brightness);
}
protected:
EHMTX *parent_;
};
template <typename... Ts>
class AddScreenAction : public Action<Ts...>
{
public:
AddScreenAction(EHMTX *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(std::string, icon)
TEMPLATABLE_VALUE(std::string, text)
TEMPLATABLE_VALUE(uint8_t, duration)
TEMPLATABLE_VALUE(bool, alarm)
void play(Ts... x) override
{
auto icon = this->icon_.value(x...);
auto text = this->text_.value(x...);
auto duration = this->duration_.value(x...);
auto alarm = this->alarm_.value(x...);
if (duration)
{
this->parent_->add_screen(icon, text, duration, alarm);
}
else
{
this->parent_->add_screen(icon, text, this->parent_->duration, alarm);
}
}
protected:
EHMTX *parent_;
};
template <typename... Ts>
class SetIndicatorOn : public Action<Ts...>
{
public:
SetIndicatorOn(EHMTX *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(uint8_t, red)
TEMPLATABLE_VALUE(uint8_t, green)
TEMPLATABLE_VALUE(uint8_t, blue)
void play(Ts... x) override
{
this->parent_->set_indicator_on();
this->parent_->set_indicator_color(this->red_.value(x...), this->green_.value(x...), this->blue_.value(x...));
}
protected:
EHMTX *parent_;
};
template <typename... Ts>
class SetClockColor : public Action<Ts...>
{
public:
SetClockColor(EHMTX *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(uint8_t, red)
TEMPLATABLE_VALUE(uint8_t, green)
TEMPLATABLE_VALUE(uint8_t, blue)
void play(Ts... x) override
{
this->parent_->set_clock_color(this->red_.value(x...), this->green_.value(x...), this->blue_.value(x...));
}
protected:
EHMTX *parent_;
};
template <typename... Ts>
class SetAlarmColor : public Action<Ts...>
{
public:
SetAlarmColor(EHMTX *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(uint8_t, red)
TEMPLATABLE_VALUE(uint8_t, green)
TEMPLATABLE_VALUE(uint8_t, blue)
void play(Ts... x) override
{
this->parent_->set_alarm_color(this->red_.value(x...), this->green_.value(x...), this->blue_.value(x...));
}
protected:
EHMTX *parent_;
};
template <typename... Ts>
class SetTodayColor : public Action<Ts...>
{
public:
SetTodayColor(EHMTX *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(uint8_t, red)
TEMPLATABLE_VALUE(uint8_t, green)
TEMPLATABLE_VALUE(uint8_t, blue)
void play(Ts... x) override
{
this->parent_->set_today_color(this->red_.value(x...), this->green_.value(x...), this->blue_.value(x...));
}
protected:
EHMTX *parent_;
};
template <typename... Ts>
class SetShowDate : public Action<Ts...>
{
public:
SetShowDate(EHMTX *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(uint8_t, flag)
void play(Ts... x) override
{
this->parent_->set_show_date(this->flag_.value(x...));
}
protected:
EHMTX *parent_;
};
template <typename... Ts>
class SetShowDayOfWeek : public Action<Ts...>
{
public:
SetShowDayOfWeek(EHMTX *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(uint8_t, flag)
void play(Ts... x) override
{
this->parent_->set_show_day_of_week(this->flag_.value(x...));
}
protected:
EHMTX *parent_;
};
template <typename... Ts>
class SetTextColor : public Action<Ts...>
{
public:
SetTextColor(EHMTX *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(uint8_t, red)
TEMPLATABLE_VALUE(uint8_t, green)
TEMPLATABLE_VALUE(uint8_t, blue)
void play(Ts... x) override
{
this->parent_->set_text_color(this->red_.value(x...), this->green_.value(x...), this->blue_.value(x...));
}
protected:
EHMTX *parent_;
};
template <typename... Ts>
class SetWeekdayColor : public Action<Ts...>
{
public:
SetWeekdayColor(EHMTX *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(uint8_t, red)
TEMPLATABLE_VALUE(uint8_t, green)
TEMPLATABLE_VALUE(uint8_t, blue)
void play(Ts... x) override
{
this->parent_->set_weekday_color(this->red_.value(x...), this->green_.value(x...), this->blue_.value(x...));
}
protected:
EHMTX *parent_;
};
template <typename... Ts>
class SetIndicatorOff : public Action<Ts...>
{
public:
SetIndicatorOff(EHMTX *parent) : parent_(parent) {}
void play(Ts... x) override
{
this->parent_->set_indicator_off();
}
protected:
EHMTX *parent_;
};
template <typename... Ts>
class DeleteScreen : public Action<Ts...>
{
public:
DeleteScreen(EHMTX *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(std::string, icon)
void play(Ts... x) override
{
this->parent_->del_screen(this->icon_.value(x...));
}
protected:
EHMTX *parent_;
};
template <typename... Ts>
class ForceScreen : public Action<Ts...>
{
public:
ForceScreen(EHMTX *parent) : parent_(parent) {}
TEMPLATABLE_VALUE(std::string, icon)
void play(Ts... x) override
{
this->parent_->force_screen(this->icon_.value(x...));
}
protected:
EHMTX *parent_;
};
class EHMTX_Icon : public display::Animation
{
protected:
bool counting_up;
public:
EHMTX_Icon(const uint8_t *data_start, int width, int height, uint32_t animation_frame_count, display::ImageType type, std::string icon_name, bool revers, uint16_t frame_duration);
std::string name;
uint16_t frame_duration;
void next_frame();
bool reverse;
};
}
#endif