1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-31 07:03:55 +00:00

[nextion] Replace boolean flags with bitfields to optimize memory usage (#9359)

This commit is contained in:
Edward Firmo
2025-07-07 06:07:03 +02:00
committed by GitHub
parent 364b6ca8d0
commit 2510b5ffb5
6 changed files with 58 additions and 53 deletions

View File

@@ -1302,7 +1302,7 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe
* @return true if the Nextion display is connected and ready to receive commands
* @return false if the display is not yet connected or connection was lost
*/
bool is_connected() { return this->is_connected_; }
bool is_connected() { return this->connection_state_.is_connected_; }
protected:
#ifdef USE_NEXTION_MAX_COMMANDS_PER_LOOP
@@ -1336,21 +1336,28 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe
bool remove_from_q_(bool report_empty = true);
/**
* @brief
* Sends commands ignoring of the Nextion has been setup.
* @brief Status flags for Nextion display state management
*
* Uses bitfields to pack multiple boolean states into a single byte,
* saving 5 bytes of RAM compared to individual bool variables.
*/
bool ignore_is_setup_ = false;
struct {
uint8_t is_connected_ : 1; ///< Connection established with Nextion display
uint8_t sent_setup_commands_ : 1; ///< Initial setup commands have been sent
uint8_t ignore_is_setup_ : 1; ///< Temporarily ignore setup state for special operations
uint8_t nextion_reports_is_setup_ : 1; ///< Nextion has reported successful initialization
uint8_t is_updating_ : 1; ///< TFT firmware update is currently in progress
uint8_t auto_wake_on_touch_ : 1; ///< Display should wake automatically on touch (default: true)
uint8_t reserved_ : 2; ///< Reserved bits for future flag additions
} connection_state_{}; ///< Zero-initialized status flags (all start as false)
bool nextion_reports_is_setup_ = false;
void process_nextion_commands_();
void process_serial_();
bool is_updating_ = false;
uint16_t touch_sleep_timeout_ = 0;
uint8_t wake_up_page_ = 255;
#ifdef USE_NEXTION_CONF_START_UP_PAGE
uint8_t start_up_page_ = 255;
#endif // USE_NEXTION_CONF_START_UP_PAGE
bool auto_wake_on_touch_ = true;
bool exit_reparse_on_start_ = false;
bool skip_connection_handshake_ = false;
@@ -1472,11 +1479,9 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe
void reset_(bool reset_nextion = true);
std::string command_data_;
bool is_connected_ = false;
const uint16_t startup_override_ms_ = 8000;
const uint16_t max_q_age_ms_ = 8000;
uint32_t started_ms_ = 0;
bool sent_setup_commands_ = false;
};
} // namespace nextion