13#ifdef USE_NEXTION_WAVEFORM
20#ifdef USE_NEXTION_TFT_UPLOAD
22#include <esp_http_client.h>
23#elif defined(USE_ESP8266)
24#include <ESP8266HTTPClient.h>
25#include <WiFiClientSecure.h>
32class NextionComponentBase;
36#ifdef USE_NEXTION_COMMAND_SPACING
49 void set_spacing(uint8_t spacing_ms) { spacing_ms_ = spacing_ms; }
63 bool can_send(
uint32_t now)
const {
return (now - last_command_time_) >= spacing_ms_; }
81#ifdef USE_NEXTION_MAX_COMMANDS_PER_LOOP
97#ifdef USE_NEXTION_MAX_QUEUE_SIZE
111#ifdef USE_NEXTION_COMMAND_SPACING
615#ifdef USE_NEXTION_WAVEFORM
622 void add_waveform_data(uint8_t component_id, uint8_t channel_number, uint8_t value);
640 void display_picture(uint16_t picture_id, uint16_t x_start, uint16_t y_start);
660 void fill_area(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t color);
679 void fill_area(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height,
const char *color);
698 void fill_area(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height,
Color color);
718 void line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
737 void line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,
const char *color);
756 void line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,
Color color);
776 void rectangle(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t color);
795 void rectangle(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height,
const char *color);
814 void rectangle(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height,
Color color);
825 void circle(uint16_t center_x, uint16_t center_y, uint16_t radius, uint16_t color);
835 void circle(uint16_t center_x, uint16_t center_y, uint16_t radius,
const char *color);
844 void circle(uint16_t center_x, uint16_t center_y, uint16_t radius,
Color color);
862 void filled_circle(uint16_t center_x, uint16_t center_y, uint16_t radius, uint16_t color);
879 void filled_circle(uint16_t center_x, uint16_t center_y, uint16_t radius,
const char *color);
896 void filled_circle(uint16_t center_x, uint16_t center_y, uint16_t radius,
Color color);
916 void qrcode(uint16_t x1, uint16_t y1,
const char *content, uint16_t
size = 200, uint16_t background_color = 65535,
917 uint16_t foreground_color = 0, int32_t logo_pic = -1, uint8_t border_width = 8);
940 void qrcode(uint16_t x1, uint16_t y1,
const char *content, uint16_t
size,
942 int32_t logo_pic = -1, uint8_t border_width = 8);
1082#ifdef USE_NEXTION_TFT_UPLOAD
1193#ifdef USE_NEXTION_TRIGGER_CUSTOM_BINARY_SENSOR
1206#ifdef USE_NEXTION_TRIGGER_CUSTOM_SENSOR
1219#ifdef USE_NEXTION_TRIGGER_CUSTOM_SWITCH
1232#ifdef USE_NEXTION_TRIGGER_CUSTOM_TEXT_SENSOR
1265 int32_t state_value)
override;
1269 const std::string &state_value)
override;
1273#ifdef USE_NEXTION_WAVEFORM
1328#ifdef USE_NEXTION_CONF_START_UP_PAGE
1437#ifdef USE_NEXTION_MAX_COMMANDS_PER_LOOP
1440#ifdef USE_NEXTION_MAX_QUEUE_SIZE
1444#ifdef USE_NEXTION_COMMAND_SPACING
1461#ifdef USE_NEXTION_WAVEFORM
1491#ifdef USE_NEXTION_CONF_START_UP_PAGE
1506#ifdef USE_NEXTION_COMMAND_SPACING
1527 const std::
string &variable_name_to_send, int32_t state_value,
1528 bool is_sleep_safe = false);
1531 const std::
string &variable_name_to_send,
1532 const std::
string &state_value,
bool is_sleep_safe = false);
1534#ifdef USE_NEXTION_WAVEFORM
1538#ifdef USE_NEXTION_TFT_UPLOAD
1563#elif defined(USE_ARDUINO)
1597#ifdef USE_NEXTION_TRIGGER_CUSTOM_BINARY_SENSOR
1600#ifdef USE_NEXTION_TRIGGER_CUSTOM_SENSOR
1603#ifdef USE_NEXTION_TRIGGER_CUSTOM_SWITCH
1606#ifdef USE_NEXTION_TRIGGER_CUSTOM_TEXT_SENSOR
1613#ifdef USE_NEXTION_CONFIG_DUMP_DEVICE_INFO
1622#ifdef NEXTION_PROTOCOL_LOG
This class simplifies creating components that periodically check a state.
Fixed-size circular buffer with FIFO semantics and iteration support.
StringRef is a reference to a string owned by something else.
void set_spacing(uint8_t spacing_ms)
Set the minimum time between commands.
uint8_t get_spacing() const
Get current command spacing.
bool can_send(uint32_t now) const
Check if enough time has passed to send the next command.
NextionCommandPacer(uint8_t initial_spacing=0)
Creates command pacer with initial spacing.
void mark_sent(uint32_t now)
Record the transmit timestamp for the most recently sent command.
void add_sleep_state_callback(F &&callback)
Add a callback to be notified of sleep state changes.
void set_component_font_color(const char *component, uint16_t color)
Set the font color of a component.
std::vector< NextionComponentBase * > touch_
void open_waveform_channel(uint8_t component_id, uint8_t channel_number, uint8_t value)
void set_component_visibility(const char *component, bool show) override
Set the visibility of a component.
std::vector< NextionComponentBase * > switchtype_
void set_component_drag(const char *component, bool drag)
Set the drag availability of a component.
std::vector< NextionComponentBase * > binarysensortype_
int upload_by_chunks_(esp_http_client_handle_t http_client, uint32_t &range_start)
will request 4096 bytes chunks from the web server and send each to Nextion
void set_component_foreground_color(const char *component, uint16_t color)
Set the foreground color of a component.
void set_component_font(const char *component, uint8_t font_id) override
Set the font id for a component.
StaticRingBuffer< NextionQueue *, 4 > waveform_queue_
Fixed-size ring buffer for waveform queue.
uint16_t max_q_age_ms_
Maximum age for queue items in ms.
bool send_command_(const std::string &command)
Manually send a raw command to the display and don't wait for an acknowledgement packet.
size_t get_max_queue_size() const
Get the maximum allowed queue size.
uint8_t tft_upload_http_retries_
HTTP retry count (default: 5)
void set_max_queue_size(size_t size)
Set the maximum allowed queue size.
std::vector< NextionComponentBase * > textsensortype_
void set_max_commands_per_loop(uint16_t value)
Set the maximum number of commands to process in each loop iteration.
uint8_t auto_wake_on_touch_
Display should wake automatically on touch (default: true)
CallbackManager< void(uint8_t)> page_callback_
void add_custom_text_sensor_callback(F &&callback)
Add a callback to be notified when Nextion sends a custom text sensor protocol frame (0x92).
void set_component_text_printf(const char *component, const char *format,...) __attribute__((format(printf
Set the text of a component to a formatted string.
void set_brightness(float brightness)
void check_pending_waveform_()
void set_component_text(const char *component, const char *text)
Set the text of a component to a static string.
void set_tft_upload_http_retries(uint8_t retries)
Set the number of HTTP retries for TFT upload requests.
struct esphome::nextion::Nextion::@144 connection_state_
Status flags for Nextion display state management.
CallbackManager< void(StringRef, int32_t)> custom_sensor_callback_
void set_wake_up_page(uint8_t wake_up_page=255)
Sets which page Nextion loads when exiting sleep mode.
std::string device_model_
void set_nextion_rtc_time(ESPTime time)
Send the current time to the nextion display.
void all_components_send_state_(bool force_update=false)
void set_start_up_page(uint8_t start_up_page=255)
Sets which page Nextion loads when connecting to ESPHome.
void set_component_pressed_foreground_color(const char *component, uint16_t color)
Set the pressed foreground color of a component.
std::string firmware_version_
void set_nextion_sensor_state(int queue_type, const std::string &name, float state)
Set the nextion sensor state object.
void add_addt_command_to_queue(NextionComponentBase *component) override
uint16_t get_startup_override_ms() const
Get the startup override timeout.
void soft_reset()
Softreset the Nextion.
void filled_circle(uint16_t center_x, uint16_t center_y, uint16_t radius, uint16_t color)
Draw a filled circled.
void register_textsensor_component(NextionComponentBase *obj)
void circle(uint16_t center_x, uint16_t center_y, uint16_t radius, uint16_t color)
Draw a circle outline.
uint16_t max_commands_per_loop_
void enable_component_touch(const char *component)
Enable touch for a component.
void rectangle(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t color)
Draw a rectangle outline.
void add_no_result_to_queue_with_set(const std::string &variable_name, const std::string &variable_name_to_send, const std::string &state_value) override
uint16_t startup_override_ms_
Timeout before forcing setup complete.
void process_nextion_commands_()
void add_to_get_queue(NextionComponentBase *component) override
void void set_component_value(const char *component, int32_t value)
Set the integer value of a component.
uint8_t is_updating_
TFT firmware update is currently in progress.
bool send_command_printf(const char *format,...) __attribute__((format(printf
Manually send a raw formatted command to the display.
void set_max_queue_age(uint16_t age_ms)
Set the maximum age for queue items.
WiFiClient * wifi_client_
std::list< NextionQueue * > nextion_queue_
void set_component_picture(const char *component, uint8_t picture_id)
Set the picture of an image component.
bool void set_tft_upload_http_timeout(uint16_t timeout_ms)
Set the HTTP timeout for TFT upload requests.
void add_no_result_to_queue_with_set(const std::string &variable_name, const std::string &variable_name_to_send, int32_t state_value) override
void set_auto_wake_on_touch(bool auto_wake_on_touch)
Sets if Nextion should auto-wake from sleep when touch press occurs.
bool remove_from_q_(bool report_empty=true)
bool upload_tft(uint32_t baud_rate=0, bool exit_reparse=true)
Uploads the TFT file to the Nextion display.
uint16_t tft_upload_http_timeout_
HTTP timeout in ms (default: 4.5s)
void add_setup_state_callback(F &&callback)
Add a callback to be notified when the nextion completes its initialize setup.
void set_component_pic(const char *component, uint16_t pic_id)
Set the picture id of a component.
bool set_protocol_reparse_mode(bool active_mode)
Sets the Nextion display's protocol reparse mode.
std::vector< NextionComponentBase * > sensortype_
bool upload_end_(bool successful)
Ends the upload process, restart Nextion and, if successful, restarts ESP.
BearSSL::WiFiClientSecure * wifi_client_secure_
void set_component_coordinates(const char *component, uint16_t x, uint16_t y)
Set the coordinates of a component on screen.
void add_new_page_callback(F &&callback)
Add a callback to be notified when the nextion changes pages.
uint16_t touch_sleep_timeout_
uint8_t sent_setup_commands_
Initial setup commands have been sent.
void add_no_result_to_queue_with_set(NextionComponentBase *component, const std::string &state_value) override
void set_component_picc(const char *component, uint16_t pic_id)
Set the background picture id of component.
void sleep(bool sleep)
Sets Nextion mode between sleep and awake.
bool add_no_result_to_queue_with_printf_(const std::string &variable_name, const char *format,...) __attribute__((format(printf
void set_touch_sleep_timeout(uint16_t touch_sleep_timeout=0)
Set the touch sleep timeout of the display using the thsp command.
CallbackManager< void()> setup_callback_
void hide_component(const char *component) override
Hide a component.
std::string command_data_
void set_component_position(const char *component, uint32_t x, uint32_t y)
Set the position of a component.
uint16_t get_max_queue_age() const
Get the maximum age for queue items.
optional< float > brightness_
CallbackManager< void()> wake_callback_
void add_waveform_data(uint8_t component_id, uint8_t channel_number, uint8_t value)
Add waveform data to a waveform component.
void disable_component_touch(const char *component)
Disable touch for a component.
bool is_updating() override
Check if the TFT update process is currently running.
uint16_t recv_ret_string_(std::string &response, uint32_t timeout, bool recv_flag)
void set_component_pressed_font_color(const char *component, uint16_t color)
Set the pressed font color of a component.
void register_touch_component(NextionComponentBase *obj)
void set_startup_override_ms(uint16_t timeout_ms)
Set the startup override timeout.
void goto_page(const char *page)
Show the page with a given name.
void add_buffer_overflow_event_callback(F &&callback)
Add a callback to be notified when the nextion reports a buffer overflow.
void add_custom_binary_sensor_callback(F &&callback)
Add a callback to be notified when Nextion sends a custom binary sensor protocol frame (0x93).
bool void add_no_result_to_queue_with_set_internal_(const std::string &variable_name, const std::string &variable_name_to_send, int32_t state_value, bool is_sleep_safe=false)
uint8_t reserved_
Reserved bits for future flag additions.
bool void add_no_result_to_queue_with_command_(const std::string &variable_name, const std::string &command)
void add_touch_event_callback(F &&callback)
Add a callback to be notified when Nextion has a touch event.
CallbackManager< void(StringRef, bool)> custom_binary_sensor_callback_
void set_wait_for_ack(bool wait_for_ack)
void set_nextion_sensor_state(NextionQueueType queue_type, const std::string &name, float state)
WiFiClient * get_wifi_client_()
void register_switch_component(NextionComponentBase *obj)
void set_tft_upload_watchdog_timeout(uint32_t timeout_ms)
Set the watchdog timeout during TFT upload.
size_t queue_size()
Retrieves the number of commands pending in the Nextion command queue.
bool send_command(const char *command)
Manually send a raw command to the display.
std::string serial_number_
CallbackManager< void()> sleep_callback_
void add_custom_sensor_callback(F &&callback)
Add a callback to be notified when Nextion sends a custom sensor protocol frame (0x91).
void set_tft_url(const std::string &tft_url)
Set the tft file URL.
void set_component_pressed_background_color(const char *component, uint16_t color)
Set the pressed background color of a component.
uint8_t ignore_is_setup_
Temporarily ignore setup state for special operations.
void set_component_vid(const char *component, uint8_t vid_id)
Set the video id of a component.
void set_component_background_color(const char *component, uint16_t color)
Set the background color of a component.
bool is_connected()
Check if the Nextion display is successfully connected.
void reset_(bool reset_nextion=true)
void update_all_components()
void qrcode(uint16_t x1, uint16_t y1, const char *content, uint16_t size=200, uint16_t background_color=65535, uint16_t foreground_color=0, int32_t logo_pic=-1, uint8_t border_width=8)
Draws a QR code in the screen.
void remove_front_no_sensors_()
void process_pending_in_queue_()
Process any commands in the queue that are pending due to command spacing.
void add_no_result_to_queue_(const std::string &variable_name)
void add_wake_state_callback(F &&callback)
Add a callback to be notified of wake state changes.
CallbackManager< void(uint8_t, uint8_t, bool)> touch_callback_
void register_binarysensor_component(NextionComponentBase *obj)
uint16_t get_max_commands_per_loop() const
Get the current maximum number of commands allowed per loop iteration.
void print_queue_members_()
void dump_config() override
void set_command_spacing(uint32_t spacing_ms)
Set the command spacing for the display.
NextionCommandPacer command_pacer_
void fill_area(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t color)
Fill a rectangle with a color.
void set_nextion_text_state(const std::string &name, const std::string &state)
uint32_t original_baud_rate_
void add_custom_switch_callback(F &&callback)
Add a callback to be notified when Nextion sends a custom switch protocol frame (0x90).
bool add_no_result_to_queue_with_ignore_sleep_printf_(const std::string &variable_name, const char *format,...) __attribute__((format(printf
void display_picture(uint16_t picture_id, uint16_t x_start, uint16_t y_start)
Display a picture at coordinates.
uint8_t is_connected_
Connection established with Nextion display.
CallbackManager< void()> buffer_overflow_callback_
void show_component(const char *component) override
Show a component.
void set_writer(const nextion_writer_t &writer)
CallbackManager< void(StringRef, StringRef)> custom_text_sensor_callback_
void add_no_result_to_queue_with_pending_command_(const std::string &variable_name, const std::string &command)
Add a command to the Nextion queue with a pending command for retry.
void register_sensor_component(NextionComponentBase *obj)
void add_no_result_to_queue_with_set(NextionComponentBase *component, int32_t state_value) override
CallbackManager< void(StringRef, bool)> custom_switch_callback_
void set_component_aph(const char *component, uint8_t aph)
Set the opaqueness (fading) of a component.
void update_components_by_prefix(const std::string &prefix)
uint32_t tft_upload_watchdog_timeout_
WDT timeout in ms (0 = no adjustment)
bool upload_first_chunk_sent_
uint8_t nextion_reports_is_setup_
Nextion has reported successful initialization.
void set_backlight_brightness(float brightness)
Set the brightness of the backlight.
struct @65::@66 __attribute__
Wake the main loop task from an ISR. ISR-safe.
const Component * component
const char int const __FlashStringHelper * format
A more user-friendly version of struct tm from time.h.