mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
[nextion] Optionally skip connection handshake (#6905)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
9699719305
commit
d0dc275e30
4 changed files with 40 additions and 4 deletions
|
@ -27,6 +27,7 @@ CONF_BACKGROUND_PRESSED_COLOR = "background_pressed_color"
|
|||
CONF_FOREGROUND_PRESSED_COLOR = "foreground_pressed_color"
|
||||
CONF_FONT_ID = "font_id"
|
||||
CONF_EXIT_REPARSE_ON_START = "exit_reparse_on_start"
|
||||
CONF_SKIP_CONNECTION_HANDSHAKE = "skip_connection_handshake"
|
||||
|
||||
|
||||
def NextionName(value):
|
||||
|
|
|
@ -23,6 +23,7 @@ from .base_component import (
|
|||
CONF_START_UP_PAGE,
|
||||
CONF_AUTO_WAKE_ON_TOUCH,
|
||||
CONF_EXIT_REPARSE_ON_START,
|
||||
CONF_SKIP_CONNECTION_HANDSHAKE,
|
||||
)
|
||||
|
||||
CODEOWNERS = ["@senexcrenshaw", "@edwardtfn"]
|
||||
|
@ -72,6 +73,7 @@ CONFIG_SCHEMA = (
|
|||
cv.Optional(CONF_START_UP_PAGE): cv.uint8_t,
|
||||
cv.Optional(CONF_AUTO_WAKE_ON_TOUCH, default=True): cv.boolean,
|
||||
cv.Optional(CONF_EXIT_REPARSE_ON_START, default=False): cv.boolean,
|
||||
cv.Optional(CONF_SKIP_CONNECTION_HANDSHAKE, default=False): cv.boolean,
|
||||
}
|
||||
)
|
||||
.extend(cv.polling_component_schema("5s"))
|
||||
|
@ -118,6 +120,8 @@ async def to_code(config):
|
|||
|
||||
cg.add(var.set_exit_reparse_on_start_internal(config[CONF_EXIT_REPARSE_ON_START]))
|
||||
|
||||
cg.add(var.set_skip_connection_handshake(config[CONF_SKIP_CONNECTION_HANDSHAKE]))
|
||||
|
||||
await display.register_display(var, config)
|
||||
|
||||
for conf in config.get(CONF_ON_SETUP, []):
|
||||
|
|
|
@ -43,6 +43,16 @@ bool Nextion::check_connect_() {
|
|||
if (this->get_is_connected_())
|
||||
return true;
|
||||
|
||||
// Check if the handshake should be skipped for the Nextion connection
|
||||
if (this->skip_connection_handshake_) {
|
||||
// Log the connection status without handshake
|
||||
ESP_LOGW(TAG, "Nextion display set as connected without performing handshake");
|
||||
// Set the connection status to true
|
||||
this->is_connected_ = true;
|
||||
// Return true indicating the connection is set
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this->comok_sent_ == 0) {
|
||||
this->reset_(false);
|
||||
|
||||
|
@ -126,10 +136,14 @@ void Nextion::reset_(bool reset_nextion) {
|
|||
|
||||
void Nextion::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "Nextion:");
|
||||
if (this->skip_connection_handshake_) {
|
||||
ESP_LOGCONFIG(TAG, " Skip handshake: %s", YESNO(this->skip_connection_handshake_));
|
||||
} else {
|
||||
ESP_LOGCONFIG(TAG, " Device Model: %s", this->device_model_.c_str());
|
||||
ESP_LOGCONFIG(TAG, " Firmware Version: %s", this->firmware_version_.c_str());
|
||||
ESP_LOGCONFIG(TAG, " Serial Number: %s", this->serial_number_.c_str());
|
||||
ESP_LOGCONFIG(TAG, " Flash Size: %s", this->flash_size_.c_str());
|
||||
}
|
||||
ESP_LOGCONFIG(TAG, " Wake On Touch: %s", YESNO(this->auto_wake_on_touch_));
|
||||
ESP_LOGCONFIG(TAG, " Exit reparse: %s", YESNO(this->exit_reparse_on_start_));
|
||||
|
||||
|
@ -262,6 +276,7 @@ void Nextion::loop() {
|
|||
this->goto_page(this->start_up_page_);
|
||||
}
|
||||
|
||||
// This could probably be removed from the loop area, as those are redundant.
|
||||
this->set_auto_wake_on_touch(this->auto_wake_on_touch_);
|
||||
this->set_exit_reparse_on_start(this->exit_reparse_on_start_);
|
||||
|
||||
|
|
|
@ -926,6 +926,21 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe
|
|||
*/
|
||||
void set_exit_reparse_on_start(bool exit_reparse);
|
||||
|
||||
/**
|
||||
* Sets whether the Nextion display should skip the connection handshake process.
|
||||
* @param skip_handshake True or false. When skip_connection_handshake is true,
|
||||
* the connection will be established without performing the handshake.
|
||||
* This can be useful when using Nextion Simulator.
|
||||
*
|
||||
* Example:
|
||||
* ```cpp
|
||||
* it.set_skip_connection_handshake(true);
|
||||
* ```
|
||||
*
|
||||
* When set to true, the display will be marked as connected without performing a handshake.
|
||||
*/
|
||||
void set_skip_connection_handshake(bool skip_handshake) { this->skip_connection_handshake_ = skip_handshake; }
|
||||
|
||||
/**
|
||||
* Sets Nextion mode between sleep and awake
|
||||
* @param True or false. Sleep=true to enter sleep mode or sleep=false to exit sleep mode.
|
||||
|
@ -1221,6 +1236,7 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe
|
|||
int16_t start_up_page_ = -1;
|
||||
bool auto_wake_on_touch_ = true;
|
||||
bool exit_reparse_on_start_ = false;
|
||||
bool skip_connection_handshake_ = false;
|
||||
|
||||
/**
|
||||
* Manually send a raw command to the display and don't wait for an acknowledgement packet.
|
||||
|
|
Loading…
Reference in a new issue