Nextion - Review set_protocol_reparse_mode() (#6567)

This commit is contained in:
Edward Firmo 2024-04-18 01:07:05 +02:00 committed by GitHub
parent 6075067e84
commit 8c323e2e4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 19 deletions

View File

@ -878,12 +878,24 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe
*/ */
void sleep(bool sleep); void sleep(bool sleep);
/** /**
* Sets Nextion Protocol Reparse mode between active or passive * @brief Sets the Nextion display's protocol reparse mode.
* @param True or false. *
* active_mode=true to enter active protocol reparse mode * This function toggles the Nextion display's protocol reparse mode between active and passive.
* active_mode=false to enter passive protocol reparse mode. * In active mode, the display actively parses incoming data.
* In passive mode, it does not parse data unless specifically instructed to do so.
* This is useful for managing how the Nextion display interprets incoming commands,
* especially during initialization or in scenarios where precise control over command processing is needed.
*
* @param active_mode A boolean value indicating the desired reparse mode.
* - true to set the display to active protocol reparse mode, where it actively parses incoming commands.
* - false to set the display to passive protocol reparse mode, where command parsing is done only on explicit
* instruction.
*
* @return bool Returns true if all commands were sent successfully to the Nextion display, indicating that the mode
* was set as expected. Returns false if any of the commands failed to send, indicating that the desired reparse mode
* may not be correctly set.
*/ */
void set_protocol_reparse_mode(bool active_mode); bool set_protocol_reparse_mode(bool active_mode);
// ========== INTERNAL METHODS ========== // ========== INTERNAL METHODS ==========
// (In most use cases you won't need these) // (In most use cases you won't need these)

View File

@ -36,22 +36,23 @@ void Nextion::sleep(bool sleep) {
// End sleep safe commands // End sleep safe commands
// Protocol reparse mode // Protocol reparse mode
void Nextion::set_protocol_reparse_mode(bool active_mode) { bool Nextion::set_protocol_reparse_mode(bool active_mode) {
const uint8_t to_send[3] = {0xFF, 0xFF, 0xFF}; ESP_LOGV(TAG, "Set Nextion protocol reparse mode: %s", YESNO(active_mode));
this->ignore_is_setup_ = true; // if not in reparse mode setup will fail, so it should be ignored
bool all_commands_sent = true;
if (active_mode) { // Sets active protocol reparse mode if (active_mode) { // Sets active protocol reparse mode
this->write_str( all_commands_sent &= this->send_command_("recmod=1");
"recmod=1"); // send_command_ cannot be used as Nextion might not be setup if incorrect reparse mode } else { // Sets passive protocol reparse mode
this->write_array(to_send, sizeof(to_send)); all_commands_sent &=
} else { // Sets passive protocol reparse mode this->send_command_("DRAKJHSUYDGBNCJHGJKSHBDN"); // To exit active reparse mode this sequence must be sent
this->write_str("DRAKJHSUYDGBNCJHGJKSHBDN"); // To exit active reparse mode this sequence must be sent all_commands_sent &= this->send_command_("recmod=0"); // Sending recmode=0 twice is recommended
this->write_array(to_send, sizeof(to_send)); all_commands_sent &= this->send_command_("recmod=0");
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"); if (!this->nextion_reports_is_setup_) { // No need to connect if is already setup
this->write_array(to_send, sizeof(to_send)); all_commands_sent &= this->send_command_("connect");
}
this->ignore_is_setup_ = false;
return all_commands_sent;
} }
void Nextion::set_exit_reparse_on_start(bool exit_reparse) { this->exit_reparse_on_start_ = exit_reparse; } void Nextion::set_exit_reparse_on_start(bool exit_reparse) { this->exit_reparse_on_start_ = exit_reparse; }