mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	[nextion] Extract common upload_end_ function to shared file (#9155)
				
					
				
			This commit is contained in:
		
							
								
								
									
										36
									
								
								esphome/components/nextion/nextion_upload.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								esphome/components/nextion/nextion_upload.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,36 @@ | |||||||
|  | #include "nextion.h" | ||||||
|  |  | ||||||
|  | #ifdef USE_NEXTION_TFT_UPLOAD | ||||||
|  |  | ||||||
|  | #include "esphome/core/application.h" | ||||||
|  |  | ||||||
|  | namespace esphome { | ||||||
|  | namespace nextion { | ||||||
|  | static const char *const TAG = "nextion.upload"; | ||||||
|  |  | ||||||
|  | bool Nextion::upload_end_(bool successful) { | ||||||
|  |   if (successful) { | ||||||
|  |     ESP_LOGD(TAG, "Upload successful"); | ||||||
|  |     delay(1500);  // NOLINT | ||||||
|  |     App.safe_reboot(); | ||||||
|  |   } else { | ||||||
|  |     ESP_LOGE(TAG, "Upload failed"); | ||||||
|  |  | ||||||
|  |     this->is_updating_ = false; | ||||||
|  |     this->ignore_is_setup_ = false; | ||||||
|  |  | ||||||
|  |     uint32_t baud_rate = this->parent_->get_baud_rate(); | ||||||
|  |     if (baud_rate != this->original_baud_rate_) { | ||||||
|  |       ESP_LOGD(TAG, "Baud: %" PRIu32 "->%" PRIu32, baud_rate, this->original_baud_rate_); | ||||||
|  |       this->parent_->set_baud_rate(this->original_baud_rate_); | ||||||
|  |       this->parent_->load_settings(); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   return successful; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | }  // namespace nextion | ||||||
|  | }  // namespace esphome | ||||||
|  |  | ||||||
|  | #endif  // USE_NEXTION_TFT_UPLOAD | ||||||
| @@ -335,31 +335,6 @@ bool Nextion::upload_tft(uint32_t baud_rate, bool exit_reparse) { | |||||||
|   return upload_end_(true); |   return upload_end_(true); | ||||||
| } | } | ||||||
|  |  | ||||||
| bool Nextion::upload_end_(bool successful) { |  | ||||||
|   ESP_LOGD(TAG, "TFT upload done: %s", YESNO(successful)); |  | ||||||
|  |  | ||||||
|   if (successful) { |  | ||||||
|     ESP_LOGD(TAG, "Restart"); |  | ||||||
|     delay(1500);  // NOLINT |  | ||||||
|     App.safe_reboot(); |  | ||||||
|     delay(1500);  // NOLINT |  | ||||||
|   } else { |  | ||||||
|     ESP_LOGE(TAG, "TFT upload failed"); |  | ||||||
|  |  | ||||||
|     this->is_updating_ = false; |  | ||||||
|     this->ignore_is_setup_ = false; |  | ||||||
|  |  | ||||||
|     uint32_t baud_rate = this->parent_->get_baud_rate(); |  | ||||||
|     if (baud_rate != this->original_baud_rate_) { |  | ||||||
|       ESP_LOGD(TAG, "Baud back: %" PRIu32 "->%" PRIu32, baud_rate, this->original_baud_rate_); |  | ||||||
|       this->parent_->set_baud_rate(this->original_baud_rate_); |  | ||||||
|       this->parent_->load_settings(); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   return successful; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| #ifdef USE_ESP8266 | #ifdef USE_ESP8266 | ||||||
| WiFiClient *Nextion::get_wifi_client_() { | WiFiClient *Nextion::get_wifi_client_() { | ||||||
|   if (this->tft_url_.compare(0, 6, "https:") == 0) { |   if (this->tft_url_.compare(0, 6, "https:") == 0) { | ||||||
|   | |||||||
| @@ -335,30 +335,6 @@ bool Nextion::upload_tft(uint32_t baud_rate, bool exit_reparse) { | |||||||
|   return this->upload_end_(true); |   return this->upload_end_(true); | ||||||
| } | } | ||||||
|  |  | ||||||
| bool Nextion::upload_end_(bool successful) { |  | ||||||
|   ESP_LOGD(TAG, "TFT upload done: %s", YESNO(successful)); |  | ||||||
|  |  | ||||||
|   if (successful) { |  | ||||||
|     ESP_LOGD(TAG, "Restart"); |  | ||||||
|     delay(1500);  // NOLINT |  | ||||||
|     App.safe_reboot(); |  | ||||||
|   } else { |  | ||||||
|     ESP_LOGE(TAG, "TFT upload failed"); |  | ||||||
|  |  | ||||||
|     this->is_updating_ = false; |  | ||||||
|     this->ignore_is_setup_ = false; |  | ||||||
|  |  | ||||||
|     uint32_t baud_rate = this->parent_->get_baud_rate(); |  | ||||||
|     if (baud_rate != this->original_baud_rate_) { |  | ||||||
|       ESP_LOGD(TAG, "Baud back: %" PRIu32 "->%" PRIu32, baud_rate, this->original_baud_rate_); |  | ||||||
|       this->parent_->set_baud_rate(this->original_baud_rate_); |  | ||||||
|       this->parent_->load_settings(); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   return successful; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| }  // namespace nextion | }  // namespace nextion | ||||||
| }  // namespace esphome | }  // namespace esphome | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user