14#ifdef USE_NEXTION_TFT_UPLOAD
17#include <HTTPClient.h>
20#include <ESP8266HTTPClient.h>
21#include <WiFiClientSecure.h>
23#elif defined(USE_ESP_IDF)
24#include <esp_http_client.h>
32class NextionComponentBase;
36static const std::string COMMAND_DELIMITER{
static_cast<char>(255),
static_cast<char>(255),
static_cast<char>(255)};
38#ifdef USE_NEXTION_COMMAND_SPACING
51 void set_spacing(uint8_t spacing_ms) { spacing_ms_ = spacing_ms; }
63 bool can_send()
const {
return (
millis() - last_command_time_) >= spacing_ms_; }
72 uint32_t last_command_time_{0};
78#ifdef USE_NEXTION_COMMAND_SPACING
571 void add_waveform_data(uint8_t component_id, uint8_t channel_number, uint8_t value);
588 void display_picture(uint16_t picture_id, uint16_t x_start, uint16_t y_start);
608 void fill_area(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t color);
627 void fill_area(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, const
char *color);
646 void fill_area(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height,
Color color);
666 void line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
685 void line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, const
char *color);
704 void line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,
Color color);
724 void rectangle(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t color);
743 void rectangle(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, const
char *color);
762 void rectangle(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height,
Color color);
773 void circle(uint16_t center_x, uint16_t center_y, uint16_t radius, uint16_t color);
783 void circle(uint16_t center_x, uint16_t center_y, uint16_t radius, const
char *color);
792 void circle(uint16_t center_x, uint16_t center_y, uint16_t radius,
Color color);
810 void filled_circle(uint16_t center_x, uint16_t center_y, uint16_t radius, uint16_t color);
827 void filled_circle(uint16_t center_x, uint16_t center_y, uint16_t radius, const
char *color);
844 void filled_circle(uint16_t center_x, uint16_t center_y, uint16_t radius,
Color color);
864 void qrcode(uint16_t x1, uint16_t y1, const
char *content, uint16_t size = 200, uint16_t background_color = 65535,
865 uint16_t foreground_color = 0, uint8_t logo_pic = -1, uint8_t border_width = 8);
888 void qrcode(uint16_t x1, uint16_t y1, const
char *content, uint16_t size,
890 uint8_t logo_pic = -1, uint8_t border_width = 8);
1021 void setup()
override;
1025 void loop()
override;
1046#ifdef USE_NEXTION_TFT_UPLOAD
1072 bool upload_tft(uint32_t baud_rate = 0,
bool exit_reparse =
true);
1139 int32_t state_value)
override;
1143 const std::string &state_value)
override;
1276#ifdef USE_NEXTION_COMMAND_SPACING
1281 uint16_t
recv_ret_string_(std::string &response, uint32_t timeout,
bool recv_flag);
1319 const std::
string &variable_name_to_send, int32_t state_value,
1320 bool is_sleep_safe = false);
1323 const std::
string &variable_name_to_send,
1324 const std::
string &state_value,
bool is_sleep_safe = false);
1328#ifdef USE_NEXTION_TFT_UPLOAD
1349#elif defined(USE_ESP_IDF)
1357 int upload_by_chunks_(esp_http_client_handle_t http_client, uint32_t &range_start);
1400#ifdef NEXTION_PROTOCOL_LOG
1403 void reset_(
bool reset_nextion =
true);
This class simplifies creating components that periodically check a state.
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() const
Check if enough time has passed to send next command.
void mark_sent()
Mark a command as sent, updating the timing.
NextionCommandPacer(uint8_t initial_spacing=0)
Creates command pacer with initial spacing.
void add_setup_state_callback(std::function< void()> &&callback)
Add a callback to be notified when the nextion completes its initialize setup.
void set_skip_connection_handshake(bool skip_handshake)
Sets whether the Nextion display should skip the connection handshake process.
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)
std::vector< NextionComponentBase * > switchtype_
void set_component_drag(const char *component, bool drag)
Set the drag availability of a component.
void add_buffer_overflow_event_callback(std::function< void()> &&callback)
Add a callback to be notified when the nextion reports a buffer overflow.
std::vector< NextionComponentBase * > binarysensortype_
uint32_t get_free_heap_()
Returns the ESP Free Heap memory.
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.
const uint16_t max_q_age_ms_
const uint16_t startup_override_ms_
bool send_command_(const std::string &command)
Manually send a raw command to the display and don't wait for an acknowledgement packet.
std::vector< NextionComponentBase * > textsensortype_
CallbackManager< void(uint8_t)> page_callback_
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_wake_up_page(uint8_t wake_up_page=255)
Sets which page Nextion loads when exiting sleep mode.
optional< nextion_writer_t > writer_
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
Add addt command to the queue.
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.
bool ignore_is_setup_
Sends commands ignoring of the Nextion has been setup.
void register_textsensor_component(NextionComponentBase *obj)
void add_new_page_callback(std::function< void(uint8_t)> &&callback)
Add a callback to be notified when the nextion changes pages.
void circle(uint16_t center_x, uint16_t center_y, uint16_t radius, uint16_t color)
Draw a circle outline.
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 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.
bool send_command_printf(const char *format,...) __attribute__((format(printf
Manually send a raw formatted command to the display.
WiFiClient * wifi_client_
void set_component_picture(const char *component, uint8_t picture_id)
Set the picture of an image component.
void set_component_picc(const char *component, uint8_t pic_id)
Set the background picture id of component.
std::deque< NextionQueue * > nextion_queue_
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.
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.
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)
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 set_exit_reparse_on_start(bool exit_reparse_on_start)
Sets if Nextion should exit the active reparse mode before the "connect" command is sent.
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
Sends a formatted command to the nextion.
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.
optional< float > brightness_
CallbackManager< void()> wake_callback_
bool exit_reparse_on_start_
void add_sleep_state_callback(std::function< void()> &&callback)
Add a callback to be notified of sleep state changes.
bool void set_tft_url(const std::string &tft_url)
Set the tft file URL.
void add_waveform_data(uint8_t component_id, uint8_t channel_number, uint8_t value)
Add waveform data to a waveform component.
bool sent_setup_commands_
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 goto_page(const char *page)
Show the page with a given name.
void set_touch_sleep_timeout(uint32_t touch_sleep_timeout)
Set the touch sleep timeout of the display.
void set_wait_for_ack(bool wait_for_ack)
WiFiClient * get_wifi_client_()
void register_switch_component(NextionComponentBase *obj)
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_
void set_component_pic(const char *component, uint8_t pic_id)
Set the picture id of a component.
bool nextion_reports_is_setup_
CallbackManager< void()> sleep_callback_
void set_component_pressed_background_color(const char *component, uint16_t color)
Set the pressed background color of a component.
float get_setup_priority() const override
void set_component_vid(const char *component, uint8_t vid_id)
Set the video id of a component.
bool void add_no_result_to_queue_with_command_(const std::string &variable_name, const std::string &command)
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 line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Draw a line on the screen.
void update_all_components()
void remove_front_no_sensors_()
void add_no_result_to_queue_(const std::string &variable_name)
CallbackManager< void(uint8_t, uint8_t, bool)> touch_callback_
void register_binarysensor_component(NextionComponentBase *obj)
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_
std::deque< NextionQueue * > waveform_queue_
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.
uint32_t touch_sleep_timeout_
void add_wake_state_callback(std::function< void()> &&callback)
Add a callback to be notified of wake state changes.
CallbackManager< void()> buffer_overflow_callback_
void show_component(const char *component) override
Show a component.
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, uint8_t logo_pic=-1, uint8_t border_width=8)
Draws a QR code in the screen.
bool skip_connection_handshake_
void set_writer(const nextion_writer_t &writer)
int upload_by_chunks_(HTTPClient &http_client, uint32_t &range_start)
will request chunk_size chunks from the web server and send each to the nextion
void register_sensor_component(NextionComponentBase *obj)
void add_no_result_to_queue_with_set(NextionComponentBase *component, int32_t state_value) override
void add_touch_event_callback(std::function< void(uint8_t, uint8_t, bool)> &&callback)
Add a callback to be notified when Nextion has a touch event.
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)
bool upload_first_chunk_sent_
void set_backlight_brightness(float brightness)
Set the brightness of the backlight.
struct @67::@68 __attribute__
std::function< void(Nextion &)> nextion_writer_t
Providing packet encoding functions for exchanging data with a remote host.
uint32_t IRAM_ATTR HOT millis()
A more user-friendly version of struct tm from time.h.