mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-25 21:23:53 +01:00 
			
		
		
		
	[sps30] remove delay (#10964)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
		| @@ -45,24 +45,26 @@ void SPS30Component::setup() { | ||||
|     } | ||||
|     ESP_LOGV(TAG, "  Serial number: %s", this->serial_number_); | ||||
|  | ||||
|     bool result; | ||||
|     if (this->fan_interval_.has_value()) { | ||||
|       // override default value | ||||
|       result = this->write_command(SPS30_CMD_SET_AUTOMATIC_CLEANING_INTERVAL_SECONDS, this->fan_interval_.value()); | ||||
|       this->result_ = | ||||
|           this->write_command(SPS30_CMD_SET_AUTOMATIC_CLEANING_INTERVAL_SECONDS, this->fan_interval_.value()); | ||||
|     } else { | ||||
|       result = this->write_command(SPS30_CMD_SET_AUTOMATIC_CLEANING_INTERVAL_SECONDS); | ||||
|     } | ||||
|     if (result) { | ||||
|       delay(20); | ||||
|       uint16_t secs[2]; | ||||
|       if (this->read_data(secs, 2)) { | ||||
|         this->fan_interval_ = secs[0] << 16 | secs[1]; | ||||
|       } | ||||
|       this->result_ = this->write_command(SPS30_CMD_SET_AUTOMATIC_CLEANING_INTERVAL_SECONDS); | ||||
|     } | ||||
|  | ||||
|     this->status_clear_warning(); | ||||
|     this->skipped_data_read_cycles_ = 0; | ||||
|     this->start_continuous_measurement_(); | ||||
|     this->set_timeout(20, [this]() { | ||||
|       if (this->result_) { | ||||
|         uint16_t secs[2]; | ||||
|         if (this->read_data(secs, 2)) { | ||||
|           this->fan_interval_ = secs[0] << 16 | secs[1]; | ||||
|         } | ||||
|       } | ||||
|       this->status_clear_warning(); | ||||
|       this->skipped_data_read_cycles_ = 0; | ||||
|       this->start_continuous_measurement_(); | ||||
|       this->setup_complete_ = true; | ||||
|     }); | ||||
|   }); | ||||
| } | ||||
|  | ||||
| @@ -111,6 +113,8 @@ void SPS30Component::dump_config() { | ||||
| } | ||||
|  | ||||
| void SPS30Component::update() { | ||||
|   if (!this->setup_complete_) | ||||
|     return; | ||||
|   /// Check if warning flag active (sensor reconnected?) | ||||
|   if (this->status_has_warning()) { | ||||
|     ESP_LOGD(TAG, "Reconnecting"); | ||||
|   | ||||
| @@ -30,9 +30,12 @@ class SPS30Component : public PollingComponent, public sensirion_common::Sensiri | ||||
|   bool start_fan_cleaning(); | ||||
|  | ||||
|  protected: | ||||
|   bool result_{false}; | ||||
|   bool setup_complete_{false}; | ||||
|   uint16_t raw_firmware_version_; | ||||
|   char serial_number_[17] = {0};  /// Terminating NULL character | ||||
|   uint8_t skipped_data_read_cycles_ = 0; | ||||
|  | ||||
|   bool start_continuous_measurement_(); | ||||
|  | ||||
|   enum ErrorCode : uint8_t { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user