mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	[nextion] Memory optimization (#9338)
This commit is contained in:
		| @@ -167,6 +167,7 @@ async def to_code(config): | ||||
|         cg.add(var.set_wake_up_page(config[CONF_WAKE_UP_PAGE])) | ||||
|  | ||||
|     if CONF_START_UP_PAGE in config: | ||||
|         cg.add_define("USE_NEXTION_CONF_START_UP_PAGE") | ||||
|         cg.add(var.set_start_up_page(config[CONF_START_UP_PAGE])) | ||||
|  | ||||
|     cg.add(var.set_auto_wake_on_touch(config[CONF_AUTO_WAKE_ON_TOUCH])) | ||||
|   | ||||
| @@ -167,13 +167,15 @@ void Nextion::dump_config() { | ||||
|     ESP_LOGCONFIG(TAG, "  Touch Timeout:  %" PRIu16, this->touch_sleep_timeout_); | ||||
|   } | ||||
|  | ||||
|   if (this->wake_up_page_ != -1) { | ||||
|     ESP_LOGCONFIG(TAG, "  Wake Up Page:   %d", this->wake_up_page_); | ||||
|   if (this->wake_up_page_ != 255) { | ||||
|     ESP_LOGCONFIG(TAG, "  Wake Up Page:   %u", this->wake_up_page_); | ||||
|   } | ||||
|  | ||||
|   if (this->start_up_page_ != -1) { | ||||
|     ESP_LOGCONFIG(TAG, "  Start Up Page:  %d", this->start_up_page_); | ||||
| #ifdef USE_NEXTION_CONF_START_UP_PAGE | ||||
|   if (this->start_up_page_ != 255) { | ||||
|     ESP_LOGCONFIG(TAG, "  Start Up Page:  %u", this->start_up_page_); | ||||
|   } | ||||
| #endif  // USE_NEXTION_CONF_START_UP_PAGE | ||||
|  | ||||
| #ifdef USE_NEXTION_COMMAND_SPACING | ||||
|   ESP_LOGCONFIG(TAG, "  Cmd spacing:      %u ms", this->command_pacer_.get_spacing()); | ||||
| @@ -301,12 +303,14 @@ void Nextion::loop() { | ||||
|       this->set_backlight_brightness(this->brightness_.value()); | ||||
|     } | ||||
|  | ||||
| #ifdef USE_NEXTION_CONF_START_UP_PAGE | ||||
|     // Check if a startup page has been set and send the command | ||||
|     if (this->start_up_page_ >= 0) { | ||||
|     if (this->start_up_page_ != 255) { | ||||
|       this->goto_page(this->start_up_page_); | ||||
|     } | ||||
| #endif  // USE_NEXTION_CONF_START_UP_PAGE | ||||
|  | ||||
|     if (this->wake_up_page_ >= 0) { | ||||
|     if (this->wake_up_page_ != 255) { | ||||
|       this->set_wake_up_page(this->wake_up_page_); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1194,7 +1194,7 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe | ||||
|  | ||||
|   /** | ||||
|    * Sets which page Nextion loads when exiting sleep mode. Note this can be set even when Nextion is in sleep mode. | ||||
|    * @param wake_up_page The page id, from 0 to the last page in Nextion. Set -1 (not set to any existing page) to | ||||
|    * @param wake_up_page The page id, from 0 to the last page in Nextion. Set 255 (not set to any existing page) to | ||||
|    * wakes up to current page. | ||||
|    * | ||||
|    * Example: | ||||
| @@ -1204,11 +1204,12 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe | ||||
|    * | ||||
|    * The display will wake up to page 2. | ||||
|    */ | ||||
|   void set_wake_up_page(int16_t wake_up_page = -1); | ||||
|   void set_wake_up_page(uint8_t wake_up_page = 255); | ||||
|  | ||||
| #ifdef USE_NEXTION_CONF_START_UP_PAGE | ||||
|   /** | ||||
|    * Sets which page Nextion loads when connecting to ESPHome. | ||||
|    * @param start_up_page The page id, from 0 to the last page in Nextion. Set -1 (not set to any existing page) to | ||||
|    * @param start_up_page The page id, from 0 to the last page in Nextion. Set 255 (not set to any existing page) to | ||||
|    * wakes up to current page. | ||||
|    * | ||||
|    * Example: | ||||
| @@ -1218,7 +1219,8 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe | ||||
|    * | ||||
|    * The display will go to page 2 when it establishes a connection to ESPHome. | ||||
|    */ | ||||
|   void set_start_up_page(int16_t start_up_page = -1) { this->start_up_page_ = start_up_page; } | ||||
|   void set_start_up_page(uint8_t start_up_page = 255) { this->start_up_page_ = start_up_page; } | ||||
| #endif  // USE_NEXTION_CONF_START_UP_PAGE | ||||
|  | ||||
|   /** | ||||
|    * Sets if Nextion should auto-wake from sleep when touch press occurs. | ||||
| @@ -1344,8 +1346,10 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe | ||||
|   void process_serial_(); | ||||
|   bool is_updating_ = false; | ||||
|   uint16_t touch_sleep_timeout_ = 0; | ||||
|   int16_t wake_up_page_ = -1; | ||||
|   int16_t start_up_page_ = -1; | ||||
|   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; | ||||
|   | ||||
| @@ -10,7 +10,7 @@ static const char *const TAG = "nextion"; | ||||
| // Sleep safe commands | ||||
| void Nextion::soft_reset() { this->send_command_("rest"); } | ||||
|  | ||||
| void Nextion::set_wake_up_page(int16_t wake_up_page) { | ||||
| void Nextion::set_wake_up_page(uint8_t wake_up_page) { | ||||
|   this->wake_up_page_ = wake_up_page; | ||||
|   this->add_no_result_to_queue_with_set_internal_("wake_up_page", "wup", wake_up_page, true); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user