rainbow icon and indicator size

pull/2/head
LuBeDa 3 years ago
parent 0a8ea1388e
commit 7532d67cd6

@ -175,13 +175,13 @@ The alarm is displayed in the upper right corner at all screentypes! You can set
###### service
```c
show_alarm => { "r", "g", "b"}
show_alarm => { "r", "g", "b","s"}
```
###### api
```c
void EHMTX::show_alarm(int r, int g, int b);
void EHMTX::show_alarm(int r, int g, int b, int s=2);
```
r,g,b: 0-255 color components
@ -207,13 +207,13 @@ The indicator is in the lower left corner but not displayed in fullscreen 8x32 a
###### service
```c
show_indicator => { "r", "g", "b"}
show_indicator => { "r", "g", "b","s"}
```
###### api
```c
void EHMTX::show_indicator(int r, int g, int b);
void EHMTX::show_indicator(int r, int g, int ,int s=3);
```
r,g,b: 0-255 color components

@ -6,8 +6,8 @@ namespace esphome
{
this->show_display = true;
this->display_gauge = false;
this->display_indicator = false;
this->display_alarm = false;
this->display_indicator = 0;
this->display_alarm = 0;
this->icon_count = 0;
this->hue_ = 0;
this->text_color = Color(C_RED, C_GREEN, C_BLUE);
@ -38,16 +38,16 @@ namespace esphome
this->date_fmt = s;
}
void EHMTX::show_indicator(int r, int g, int b)
void EHMTX::show_indicator(int r, int g, int b,int s)
{
this->indicator_color = Color((uint8_t)r & 248, (uint8_t)g & 252, (uint8_t)b & 248);
this->display_indicator = true;
ESP_LOGD(TAG, "show_indicator r: %d g: %d b: %d", r, g, b);
this->display_indicator = s;
ESP_LOGD(TAG, "show_indicator (%d)r: %d g: %d b: %d", s, r, g, b );
}
void EHMTX::hide_indicator()
{
this->display_indicator = false;
this->display_indicator = 0;
ESP_LOGD(TAG, "hide_indicator");
}
@ -169,8 +169,8 @@ namespace esphome
register_service(&EHMTX::hide_gauge, "hide_gauge");
register_service(&EHMTX::hide_alarm, "hide_alarm");
register_service(&EHMTX::show_gauge, "show_gauge", {"percent", "r", "g", "b"});
register_service(&EHMTX::show_alarm, "show_alarm", {"r", "g", "b"});
register_service(&EHMTX::show_indicator, "show_indicator", {"r", "g", "b"});
register_service(&EHMTX::show_alarm, "show_alarm", {"r", "g", "b","s"});
register_service(&EHMTX::show_indicator, "show_indicator", {"r", "g", "b","s"});
register_service(&EHMTX::set_text_color, "text_color", {"r", "g", "b"});
register_service(&EHMTX::set_clock_color, "clock_color", {"r", "g", "b"});
@ -194,16 +194,16 @@ namespace esphome
this->is_running = true;
}
void EHMTX::show_alarm(int r, int g, int b)
void EHMTX::show_alarm(int r, int g, int b, int s)
{
this->alarm_color = Color((uint8_t)r & 248, (uint8_t)g & 252, (uint8_t)b & 248);
this->display_alarm = true;
ESP_LOGD(TAG, "show alarm color r: %d g: %d b: %d", r, g, b);
this->display_alarm = s;
ESP_LOGD(TAG, "show alarm color(%d) r: %d g: %d b: %d",s, r, g, b);
}
void EHMTX::hide_alarm()
{
this->display_alarm = false;
this->display_alarm = 0;
ESP_LOGD(TAG, "hide_alarm");
}
@ -321,6 +321,15 @@ namespace esphome
void EHMTX::tick()
{
this->hue_++;
if (this->hue_ == 360)
{
this->hue_ = 0;
}
float red,green,blue ;
esphome::hsv_to_rgb ( this->hue_,0.8,0.8,red,green, blue );
this->rainbow_color = Color(uint8_t (255 * red),uint8_t (255 * green),uint8_t (255 * blue));
if (this->is_running)
{
time_t ts = this->clock->now().timestamp;
@ -364,8 +373,8 @@ namespace esphome
}
else
{
uint8_t w = ((uint8_t)(32 / 14) * (this->boot_anim / 14)) % 32;
this->display->rectangle(0, 2, w, 4, Color(120, 190, 40));
uint8_t w = ((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++;
}
}
@ -397,14 +406,6 @@ namespace esphome
ESP_LOGI(TAG, "status time format: %s", this->time_fmt.c_str());
ESP_LOGI(TAG, "status text_color: RGB(%d,%d,%d)", this->text_color.r, this->text_color.g, this->text_color.b);
ESP_LOGI(TAG, "status alarm_color: RGB(%d,%d,%d)", this->alarm_color.r, this->alarm_color.g, this->alarm_color.b);
if (this->display_indicator)
{
ESP_LOGI(TAG, "status indicator on");
}
else
{
ESP_LOGI(TAG, "status indicator off");
}
if (this->show_display)
{
ESP_LOGI(TAG, "status display on");
@ -451,6 +452,12 @@ namespace esphome
this->scroll_interval = si;
}
void EHMTX::set_rainbow_interval(uint16_t si)
{
this->rainbow_interval = si;
}
void EHMTX::del_screen(std::string icon_name, int mode)
{
for (uint8_t i = 0; i < MAXQUEUE; i++)
@ -530,6 +537,8 @@ namespace esphome
}
screen->set_text(text, icon, w, lifetime, screen_time);
screen->default_font = default_font;
screen->text = text;
screen->pixels_ = w;
screen->mode = MODE_RAINBOW_ICON;
screen->icon_name = iconname;
ESP_LOGD(TAG, "rainbow_icon_screen icon: %d iconname: %s text: %s lifetime: %d screen_time: %d", icon, iconname.c_str(), text.c_str(), lifetime, screen_time);
@ -846,13 +855,21 @@ namespace esphome
this->queue[this->screen_pointer]->draw();
this->draw_gauge();
if (this->display_indicator)
if (this->display_indicator>2)
{
this->display->line(31, 5, 29, 7, this->indicator_color);
}
if (this->display_indicator>1){
this->display->draw_pixel_at(30, 7, this->indicator_color);
this->display->draw_pixel_at(31, 6, this->indicator_color);
}
if (this->display_indicator>0)
{
this->display->draw_pixel_at(31, 7, this->indicator_color);
}
}
}

@ -58,8 +58,8 @@ namespace esphome
std::string time_fmt;
std::string date_fmt;
bool display_indicator;
bool display_alarm;
int display_indicator;
int display_alarm;
bool display_gauge;
bool is_running=false;
bool show_date;
@ -84,11 +84,13 @@ namespace esphome
bool string_has_ending(std::string const &fullString, std::string const &ending);
bool show_seconds;
uint16_t scroll_interval; // ms to between scrollsteps
uint16_t rainbow_interval; // ms to between scrollsteps
uint16_t frame_interval; // ms to next_frame()
uint16_t hold_time; // seconds display of screen_time to extend
uint16_t screen_time; // seconds display of screen
uint8_t icon_count; // max iconnumber -1
unsigned long last_scroll_time;
unsigned long last_rainbow_time;
unsigned long last_anim_time;
time_t next_action_time = 0; // when is the next screen change
void draw_day_of_week();
@ -119,15 +121,16 @@ namespace esphome
void set_special_font(display::Font *font);
void set_frame_interval(uint16_t interval);
void set_scroll_interval(uint16_t interval);
void set_rainbow_interval(uint16_t interval);
void set_scroll_count(uint8_t count);
void set_time_format(std::string s);
void set_date_format(std::string s);
void show_indicator(int r=C_RED, int g=C_GREEN, int b=C_BLUE);
void show_indicator(int r=C_RED, int g=C_GREEN, int b=C_BLUE,int s=3);
void set_text_color(int r, int g, int b);
void set_clock_color(int r=C_RED, int g=C_GREEN, int b=C_BLUE);
void set_today_color(int r, int g, int b);
void set_weekday_color(int r, int g, int b);
void show_alarm(int r=CA_RED, int g=C_GREEN, int b=C_BLUE);
void show_alarm(int r=CA_RED, int g=C_GREEN, int b=C_BLUE, int s= 2);
void show_gauge(int v,int r=C_RED, int g=C_GREEN, int b=C_BLUE); // int because of register_service
void hide_gauge();
void hide_indicator();

@ -72,19 +72,20 @@ namespace esphome
void EHMTX_queue::update_screen()
{
if (millis() - this->config_->last_scroll_time >= this->config_->scroll_interval )
if (millis() - this->config_->last_rainbow_time >= this->config_->rainbow_interval )
{
this->config_->hue_++;
if (this->config_->hue_ == 360)
{
this->config_->hue_ = 0;
}
float red, green,blue ;
float red,green,blue ;
esphome::hsv_to_rgb ( this->config_->hue_,0.8,0.8,red,green, blue );
this->config_->rainbow_color = Color(uint8_t (255 * red),uint8_t (255 * green),uint8_t (255 * blue));
this->config_->last_rainbow_time = millis();
}
if (this->mode == MODE_ICONSCREEN || this->mode == MODE_RAINBOW_ICON)
if ((this->mode == MODE_ICONSCREEN) || (this->mode == MODE_RAINBOW_ICON))
{
if (millis() - this->config_->last_scroll_time >= this->config_->scroll_interval && this->pixels_ > TEXTSTARTOFFSET)
{
@ -96,7 +97,7 @@ namespace esphome
this->config_->last_scroll_time = millis();
}
}
if (this->mode == MODE_TEXT || this->mode == MODE_RAINBOW_TEXT)
if ((this->mode == MODE_TEXT) || (this->mode == MODE_RAINBOW_TEXT))
{
if (millis() - this->config_->last_scroll_time >= this->config_->scroll_interval && this->pixels_ >= 32)
{
@ -179,14 +180,22 @@ namespace esphome
extraoffset += 2;
}
color_ = (this->mode == MODE_RAINBOW_TEXT)?this->config_->rainbow_color:this->text_color;
color_ = (this->mode == MODE_RAINBOW_ICON)?this->config_->rainbow_color:this->config_->text_color;
this->config_->display->print(this->centerx_ + TEXTSCROLLSTART - this->shiftx_ + extraoffset + xoffset, yoffset, font, color_, esphome::display::TextAlign::BASELINE_LEFT,
this->text.c_str());
if (this->config_->display_alarm)
if (this->config_->display_alarm>2)
{
this->config_->display->line(31, 2, 29, 0, this->config_->alarm_color);
}
if (this->config_->display_alarm>1)
{
this->config_->display->draw_pixel_at(30, 0, this->config_->alarm_color);
this->config_->display->draw_pixel_at(31, 1, this->config_->alarm_color);
}
if (this->config_->display_alarm>0)
{
this->config_->display->draw_pixel_at(31, 0, this->config_->alarm_color);
}

@ -67,6 +67,7 @@ CONF_SCROLLCOUNT = "scroll_count"
CONF_MATRIXCOMPONENT = "matrix_component"
CONF_HTML = "icons2html"
CONF_SCROLLINTERVAL = "scroll_interval"
CONF_RAINBOWINTERVAL = "rainbow_interval"
CONF_FRAMEINTERVAL = "frame_interval"
CONF_DEFAULT_FONT_ID = "default_font_id"
CONF_DEFAULT_FONT = "default_font"
@ -137,6 +138,8 @@ EHMTX_SCHEMA = cv.Schema({
): cv.templatable(cv.int_range(min=0, max=3600)),
cv.Optional(CONF_SCROLLINTERVAL, default="80"
): cv.templatable(cv.positive_int),
cv.Optional(CONF_RAINBOWINTERVAL, default="32"
): cv.templatable(cv.positive_int),
cv.Optional(CONF_SCROLLCOUNT, default="2"
): cv.templatable(cv.positive_int),
cv.Optional(
@ -386,6 +389,7 @@ async def to_code(config):
cg.add(var.set_brightness(config[CONF_BRIGHTNESS]))
cg.add(var.set_screen_time(config[CONF_SCREENTIME]))
cg.add(var.set_scroll_interval(config[CONF_SCROLLINTERVAL]))
cg.add(var.set_rainbow_interval(config[CONF_SCROLLINTERVAL]))
cg.add(var.set_scroll_count(config[CONF_SCROLLCOUNT]))
cg.add(var.set_frame_interval(config[CONF_FRAMEINTERVAL]))
cg.add(var.set_week_start(config[CONF_WEEK_START_MONDAY]))

Loading…
Cancel
Save