1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-03 10:32:21 +01:00

Nextion colors parameters (#5699)

* Add `foreground` color

- Adds `set_component_foreground_color` and `set_component_pressed_foreground_color` which does the same as `set_component_font_color` and `set_component_pressed_font_color` but with a more intuitive name, as this can be used for any component and not only the ones with a text (font).
- I've also reviewed some docstring when related to colors.

* Add numeric color to drawing methods

Should I've used uint32_t instead? In order to keep consistency?

* component color support to uint6_t

This is the right format and is now consistent with colors on drawings.
I'm keeping uint32_t also to avoid breaking changes.

* Enforces uint16_t for colors

uint32_t is incorrect for Nextion display colors.

* Fix clang-format
This commit is contained in:
Edward Firmo
2023-11-28 05:50:14 +01:00
committed by GitHub
parent d1be686c54
commit 2f888ff7c5
4 changed files with 307 additions and 84 deletions

View File

@@ -53,9 +53,9 @@ void Nextion::set_protocol_reparse_mode(bool active_mode) {
this->write_array(to_send, sizeof(to_send));
}
// Set Colors
void Nextion::set_component_background_color(const char *component, uint32_t color) {
this->add_no_result_to_queue_with_printf_("set_component_background_color", "%s.bco=%" PRIu32, component, color);
// Set Colors - Background
void Nextion::set_component_background_color(const char *component, uint16_t color) {
this->add_no_result_to_queue_with_printf_("set_component_background_color", "%s.bco=%" PRIu16, component, color);
}
void Nextion::set_component_background_color(const char *component, const char *color) {
@@ -67,8 +67,9 @@ void Nextion::set_component_background_color(const char *component, Color color)
display::ColorUtil::color_to_565(color));
}
void Nextion::set_component_pressed_background_color(const char *component, uint32_t color) {
this->add_no_result_to_queue_with_printf_("set_component_pressed_background_color", "%s.bco2=%" PRIu32, component,
// Set Colors - Background (pressed)
void Nextion::set_component_pressed_background_color(const char *component, uint16_t color) {
this->add_no_result_to_queue_with_printf_("set_component_pressed_background_color", "%s.bco2=%" PRIu16, component,
color);
}
@@ -81,16 +82,38 @@ void Nextion::set_component_pressed_background_color(const char *component, Colo
display::ColorUtil::color_to_565(color));
}
void Nextion::set_component_pic(const char *component, uint8_t pic_id) {
this->add_no_result_to_queue_with_printf_("set_component_pic", "%s.pic=%d", component, pic_id);
// Set Colors - Foreground
void Nextion::set_component_foreground_color(const char *component, uint16_t color) {
this->add_no_result_to_queue_with_printf_("set_component_foreground_color", "%s.pco=%" PRIu16, component, color);
}
void Nextion::set_component_picc(const char *component, uint8_t pic_id) {
this->add_no_result_to_queue_with_printf_("set_component_pic", "%s.picc=%d", component, pic_id);
void Nextion::set_component_foreground_color(const char *component, const char *color) {
this->add_no_result_to_queue_with_printf_("set_component_foreground_color", "%s.pco=%s", component, color);
}
void Nextion::set_component_font_color(const char *component, uint32_t color) {
this->add_no_result_to_queue_with_printf_("set_component_font_color", "%s.pco=%" PRIu32, component, color);
void Nextion::set_component_foreground_color(const char *component, Color color) {
this->add_no_result_to_queue_with_printf_("set_component_foreground_color", "%s.pco=%d", component,
display::ColorUtil::color_to_565(color));
}
// Set Colors - Foreground (pressed)
void Nextion::set_component_pressed_foreground_color(const char *component, uint16_t color) {
this->add_no_result_to_queue_with_printf_("set_component_pressed_foreground_color", "%s.pco2=%" PRIu16, component,
color);
}
void Nextion::set_component_pressed_foreground_color(const char *component, const char *color) {
this->add_no_result_to_queue_with_printf_("set_component_pressed_foreground_color", " %s.pco2=%s", component, color);
}
void Nextion::set_component_pressed_foreground_color(const char *component, Color color) {
this->add_no_result_to_queue_with_printf_("set_component_pressed_foreground_color", "%s.pco2=%d", component,
display::ColorUtil::color_to_565(color));
}
// Set Colors - Font
void Nextion::set_component_font_color(const char *component, uint16_t color) {
this->add_no_result_to_queue_with_printf_("set_component_font_color", "%s.pco=%" PRIu16, component, color);
}
void Nextion::set_component_font_color(const char *component, const char *color) {
@@ -102,8 +125,9 @@ void Nextion::set_component_font_color(const char *component, Color color) {
display::ColorUtil::color_to_565(color));
}
void Nextion::set_component_pressed_font_color(const char *component, uint32_t color) {
this->add_no_result_to_queue_with_printf_("set_component_pressed_font_color", "%s.pco2=%" PRIu32, component, color);
// Set Colors - Font (pressed)
void Nextion::set_component_pressed_font_color(const char *component, uint16_t color) {
this->add_no_result_to_queue_with_printf_("set_component_pressed_font_color", "%s.pco2=%" PRIu16, component, color);
}
void Nextion::set_component_pressed_font_color(const char *component, const char *color) {
@@ -115,6 +139,15 @@ void Nextion::set_component_pressed_font_color(const char *component, Color colo
display::ColorUtil::color_to_565(color));
}
// Set picture
void Nextion::set_component_pic(const char *component, uint8_t pic_id) {
this->add_no_result_to_queue_with_printf_("set_component_pic", "%s.pic=%d", component, pic_id);
}
void Nextion::set_component_picc(const char *component, uint8_t pic_id) {
this->add_no_result_to_queue_with_printf_("set_component_pic", "%s.picc=%d", component, pic_id);
}
void Nextion::set_component_text_printf(const char *component, const char *format, ...) {
va_list arg;
va_start(arg, format);
@@ -193,6 +226,10 @@ void Nextion::display_picture(int picture_id, int x_start, int y_start) {
this->add_no_result_to_queue_with_printf_("display_picture", "pic %d, %d, %d", x_start, y_start, picture_id);
}
void Nextion::fill_area(int x1, int y1, int width, int height, uint16_t color) {
this->add_no_result_to_queue_with_printf_("fill_area", "fill %d,%d,%d,%d,%" PRIu16, x1, y1, width, height, color);
}
void Nextion::fill_area(int x1, int y1, int width, int height, const char *color) {
this->add_no_result_to_queue_with_printf_("fill_area", "fill %d,%d,%d,%d,%s", x1, y1, width, height, color);
}
@@ -202,6 +239,10 @@ void Nextion::fill_area(int x1, int y1, int width, int height, Color color) {
display::ColorUtil::color_to_565(color));
}
void Nextion::line(int x1, int y1, int x2, int y2, uint16_t color) {
this->add_no_result_to_queue_with_printf_("line", "line %d,%d,%d,%d,%" PRIu16, x1, y1, x2, y2, color);
}
void Nextion::line(int x1, int y1, int x2, int y2, const char *color) {
this->add_no_result_to_queue_with_printf_("line", "line %d,%d,%d,%d,%s", x1, y1, x2, y2, color);
}
@@ -211,6 +252,11 @@ void Nextion::line(int x1, int y1, int x2, int y2, Color color) {
display::ColorUtil::color_to_565(color));
}
void Nextion::rectangle(int x1, int y1, int width, int height, uint16_t color) {
this->add_no_result_to_queue_with_printf_("draw", "draw %d,%d,%d,%d,%" PRIu16, x1, y1, x1 + width, y1 + height,
color);
}
void Nextion::rectangle(int x1, int y1, int width, int height, const char *color) {
this->add_no_result_to_queue_with_printf_("draw", "draw %d,%d,%d,%d,%s", x1, y1, x1 + width, y1 + height, color);
}
@@ -220,6 +266,10 @@ void Nextion::rectangle(int x1, int y1, int width, int height, Color color) {
display::ColorUtil::color_to_565(color));
}
void Nextion::circle(int center_x, int center_y, int radius, uint16_t color) {
this->add_no_result_to_queue_with_printf_("cir", "cir %d,%d,%d,%" PRIu16, center_x, center_y, radius, color);
}
void Nextion::circle(int center_x, int center_y, int radius, const char *color) {
this->add_no_result_to_queue_with_printf_("cir", "cir %d,%d,%d,%s", center_x, center_y, radius, color);
}
@@ -229,6 +279,10 @@ void Nextion::circle(int center_x, int center_y, int radius, Color color) {
display::ColorUtil::color_to_565(color));
}
void Nextion::filled_circle(int center_x, int center_y, int radius, uint16_t color) {
this->add_no_result_to_queue_with_printf_("cirs", "cirs %d,%d,%d,%" PRIu16, center_x, center_y, radius, color);
}
void Nextion::filled_circle(int center_x, int center_y, int radius, const char *color) {
this->add_no_result_to_queue_with_printf_("cirs", "cirs %d,%d,%d,%s", center_x, center_y, radius, color);
}