mirror of
https://github.com/esphome/esphome.git
synced 2025-10-06 20:03:46 +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_);
|
ESP_LOGV(TAG, " Serial number: %s", this->serial_number_);
|
||||||
|
|
||||||
bool result;
|
|
||||||
if (this->fan_interval_.has_value()) {
|
if (this->fan_interval_.has_value()) {
|
||||||
// override default 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 {
|
} else {
|
||||||
result = this->write_command(SPS30_CMD_SET_AUTOMATIC_CLEANING_INTERVAL_SECONDS);
|
this->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->status_clear_warning();
|
this->set_timeout(20, [this]() {
|
||||||
this->skipped_data_read_cycles_ = 0;
|
if (this->result_) {
|
||||||
this->start_continuous_measurement_();
|
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() {
|
void SPS30Component::update() {
|
||||||
|
if (!this->setup_complete_)
|
||||||
|
return;
|
||||||
/// Check if warning flag active (sensor reconnected?)
|
/// Check if warning flag active (sensor reconnected?)
|
||||||
if (this->status_has_warning()) {
|
if (this->status_has_warning()) {
|
||||||
ESP_LOGD(TAG, "Reconnecting");
|
ESP_LOGD(TAG, "Reconnecting");
|
||||||
|
@@ -30,9 +30,12 @@ class SPS30Component : public PollingComponent, public sensirion_common::Sensiri
|
|||||||
bool start_fan_cleaning();
|
bool start_fan_cleaning();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool result_{false};
|
||||||
|
bool setup_complete_{false};
|
||||||
uint16_t raw_firmware_version_;
|
uint16_t raw_firmware_version_;
|
||||||
char serial_number_[17] = {0}; /// Terminating NULL character
|
char serial_number_[17] = {0}; /// Terminating NULL character
|
||||||
uint8_t skipped_data_read_cycles_ = 0;
|
uint8_t skipped_data_read_cycles_ = 0;
|
||||||
|
|
||||||
bool start_continuous_measurement_();
|
bool start_continuous_measurement_();
|
||||||
|
|
||||||
enum ErrorCode : uint8_t {
|
enum ErrorCode : uint8_t {
|
||||||
|
Reference in New Issue
Block a user