From 7e27e98bff376a237b8911e87d0d44d5cd6648be Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Mon, 23 Oct 2023 21:02:57 +0200 Subject: [PATCH] set Nextion protocol reparse mode (#5484) --- esphome/components/nextion/nextion.h | 7 +++++++ .../components/nextion/nextion_commands.cpp | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/esphome/components/nextion/nextion.h b/esphome/components/nextion/nextion.h index 28663138d7..7518d7f4cb 100644 --- a/esphome/components/nextion/nextion.h +++ b/esphome/components/nextion/nextion.h @@ -623,6 +623,13 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe * @param True or false. Sleep=true to enter sleep mode or sleep=false to exit sleep mode. */ void sleep(bool sleep); + /** + * Sets Nextion Protocol Reparse mode between active or passive + * @param True or false. + * active_mode=true to enter active protocol reparse mode + * active_mode=false to enter passive protocol reparse mode. + */ + void set_protocol_reparse_mode(bool active_mode); // ========== INTERNAL METHODS ========== // (In most use cases you won't need these) diff --git a/esphome/components/nextion/nextion_commands.cpp b/esphome/components/nextion/nextion_commands.cpp index 806e03850f..c4caf29287 100644 --- a/esphome/components/nextion/nextion_commands.cpp +++ b/esphome/components/nextion/nextion_commands.cpp @@ -32,6 +32,25 @@ void Nextion::sleep(bool sleep) { } // End sleep safe commands +// Protocol reparse mode +void Nextion::set_protocol_reparse_mode(bool active_mode) { + const uint8_t to_send[3] = {0xFF, 0xFF, 0xFF}; + if (active_mode) { // Sets active protocol reparse mode + this->write_str( + "recmod=1"); // send_command_ cannot be used as Nextion might not be setup if incorrect reparse mode + this->write_array(to_send, sizeof(to_send)); + } else { // Sets passive protocol reparse mode + this->write_str("DRAKJHSUYDGBNCJHGJKSHBDN"); // To exit active reparse mode this sequence must be sent + this->write_array(to_send, sizeof(to_send)); + this->write_str("recmod=0"); // Sending recmode=0 twice is recommended + this->write_array(to_send, sizeof(to_send)); + this->write_str("recmod=0"); + this->write_array(to_send, sizeof(to_send)); + } + this->write_str("connect"); + 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=%d", component, color);