mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 06:58:11 +01:00
Nextion draw QR code at runtime (#6027)
This commit is contained in:
parent
2bb5343d27
commit
869cdf122d
2 changed files with 57 additions and 0 deletions
|
@ -750,6 +750,50 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe
|
|||
*/
|
||||
void filled_circle(int center_x, int center_y, int radius, Color color);
|
||||
|
||||
/**
|
||||
* Draws a QR code in the screen
|
||||
* @param x1 The top left x coordinate to start the QR code.
|
||||
* @param y1 The top left y coordinate to start the QR code.
|
||||
* @param content The content of the QR code (as a plain text - Nextion will generate the QR code).
|
||||
* @param size The size (in pixels) for the QR code. Defaults to 200px.
|
||||
* @param background_color The background color to draw with (as rgb565 integer). Defaults to 65535 (white).
|
||||
* @param foreground_color The foreground color to draw with (as rgb565 integer). Defaults to 0 (black).
|
||||
* @param logo_pic The picture id for the logo in the center of the QR code. Defaults to -1 (no logo).
|
||||
* @param border_width The border width (in pixels) for the QR code. Defaults to 8px.
|
||||
*
|
||||
* Example:
|
||||
* ```cpp
|
||||
* it.qrcode(25, 25, "WIFI:S:MySSID;T:WPA;P:MyPassW0rd;;");
|
||||
* ```
|
||||
*
|
||||
* Draws a QR code with a Wi-Fi network credentials starting at the given coordinates (25,25).
|
||||
*/
|
||||
void qrcode(int x1, int y1, const char *content, int size = 200, uint16_t background_color = 65535,
|
||||
uint16_t foreground_color = 0, int logo_pic = -1, uint8_t border_width = 8);
|
||||
/**
|
||||
* Draws a QR code in the screen
|
||||
* @param x1 The top left x coordinate to start the QR code.
|
||||
* @param y1 The top left y coordinate to start the QR code.
|
||||
* @param content The content of the QR code (as a plain text - Nextion will generate the QR code).
|
||||
* @param size The size (in pixels) for the QR code. Defaults to 200px.
|
||||
* @param background_color The background color to draw with (as Color). Defaults to 65535 (white).
|
||||
* @param foreground_color The foreground color to draw with (as Color). Defaults to 0 (black).
|
||||
* @param logo_pic The picture id for the logo in the center of the QR code. Defaults to -1 (no logo).
|
||||
* @param border_width The border width (in pixels) for the QR code. Defaults to 8px.
|
||||
*
|
||||
* Example:
|
||||
* ```cpp
|
||||
* auto blue = Color(0, 0, 255);
|
||||
* auto red = Color(255, 0, 0);
|
||||
* it.qrcode(25, 25, "WIFI:S:MySSID;T:WPA;P:MyPassW0rd;;", 150, blue, red);
|
||||
* ```
|
||||
*
|
||||
* Draws a QR code with a Wi-Fi network credentials starting at the given coordinates (25,25) with size of 150px in
|
||||
* red on a blue background.
|
||||
*/
|
||||
void qrcode(int x1, int y1, const char *content, int size, Color background_color = Color(255, 255, 255),
|
||||
Color foreground_color = Color(0, 0, 0), int logo_pic = -1, uint8_t border_width = 8);
|
||||
|
||||
/** Set the brightness of the backlight.
|
||||
*
|
||||
* @param brightness The brightness percentage from 0 to 1.0.
|
||||
|
|
|
@ -294,6 +294,19 @@ void Nextion::filled_circle(int center_x, int center_y, int radius, Color color)
|
|||
display::ColorUtil::color_to_565(color));
|
||||
}
|
||||
|
||||
void Nextion::qrcode(int x1, int y1, const char *content, int size, uint16_t background_color,
|
||||
uint16_t foreground_color, int logo_pic, uint8_t border_width) {
|
||||
this->add_no_result_to_queue_with_printf_("qrcode", "qrcode %d,%d,%d,%d,%d,%d,%d,\"%s\"", x1, y1, size,
|
||||
background_color, foreground_color, logo_pic, border_width, content);
|
||||
}
|
||||
|
||||
void Nextion::qrcode(int x1, int y1, const char *content, int size, Color background_color, Color foreground_color,
|
||||
int logo_pic, uint8_t border_width) {
|
||||
this->add_no_result_to_queue_with_printf_(
|
||||
"qrcode", "qrcode %d,%d,%d,%d,%d,%d,%d,\"%s\"", x1, y1, size, display::ColorUtil::color_to_565(background_color),
|
||||
display::ColorUtil::color_to_565(foreground_color), logo_pic, border_width, content);
|
||||
}
|
||||
|
||||
void Nextion::set_nextion_rtc_time(ESPTime time) {
|
||||
this->add_no_result_to_queue_with_printf_("rtc0", "rtc0=%u", time.year);
|
||||
this->add_no_result_to_queue_with_printf_("rtc1", "rtc1=%u", time.month);
|
||||
|
|
Loading…
Reference in a new issue