mirror of
https://github.com/esphome/esphome.git
synced 2024-11-14 02:58:11 +01:00
SPS30 : fix i2c read size (#2866)
This commit is contained in:
parent
c84efe64d3
commit
14f6ae75ea
2 changed files with 17 additions and 10 deletions
|
@ -32,14 +32,11 @@ void SPS30Component::setup() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t raw_firmware_version[4];
|
if (!this->read_data_(&raw_firmware_version_, 1)) {
|
||||||
if (!this->read_data_(raw_firmware_version, 4)) {
|
|
||||||
this->error_code_ = FIRMWARE_VERSION_READ_FAILED;
|
this->error_code_ = FIRMWARE_VERSION_READ_FAILED;
|
||||||
this->mark_failed();
|
this->mark_failed();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ESP_LOGD(TAG, " Firmware version v%0d.%02d", (raw_firmware_version[0] >> 8),
|
|
||||||
uint16_t(raw_firmware_version[0] & 0xFF));
|
|
||||||
/// Serial number identification
|
/// Serial number identification
|
||||||
if (!this->write_command_(SPS30_CMD_GET_SERIAL_NUMBER)) {
|
if (!this->write_command_(SPS30_CMD_GET_SERIAL_NUMBER)) {
|
||||||
this->error_code_ = SERIAL_NUMBER_REQUEST_FAILED;
|
this->error_code_ = SERIAL_NUMBER_REQUEST_FAILED;
|
||||||
|
@ -59,6 +56,8 @@ void SPS30Component::setup() {
|
||||||
this->serial_number_[i * 2 + 1] = uint16_t(uint16_t(raw_serial_number[i] & 0xFF));
|
this->serial_number_[i * 2 + 1] = uint16_t(uint16_t(raw_serial_number[i] & 0xFF));
|
||||||
}
|
}
|
||||||
ESP_LOGD(TAG, " Serial Number: '%s'", this->serial_number_);
|
ESP_LOGD(TAG, " Serial Number: '%s'", this->serial_number_);
|
||||||
|
this->status_clear_warning();
|
||||||
|
this->skipped_data_read_cycles_ = 0;
|
||||||
this->start_continuous_measurement_();
|
this->start_continuous_measurement_();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -93,10 +92,17 @@ void SPS30Component::dump_config() {
|
||||||
}
|
}
|
||||||
LOG_UPDATE_INTERVAL(this);
|
LOG_UPDATE_INTERVAL(this);
|
||||||
ESP_LOGCONFIG(TAG, " Serial Number: '%s'", this->serial_number_);
|
ESP_LOGCONFIG(TAG, " Serial Number: '%s'", this->serial_number_);
|
||||||
LOG_SENSOR(" ", "PM1.0", this->pm_1_0_sensor_);
|
ESP_LOGCONFIG(TAG, " Firmware version v%0d.%0d", (raw_firmware_version_ >> 8),
|
||||||
LOG_SENSOR(" ", "PM2.5", this->pm_2_5_sensor_);
|
uint16_t(raw_firmware_version_ & 0xFF));
|
||||||
LOG_SENSOR(" ", "PM4", this->pm_4_0_sensor_);
|
LOG_SENSOR(" ", "PM1.0 Weight Concentration", this->pm_1_0_sensor_);
|
||||||
LOG_SENSOR(" ", "PM10", this->pm_10_0_sensor_);
|
LOG_SENSOR(" ", "PM2.5 Weight Concentration", this->pm_2_5_sensor_);
|
||||||
|
LOG_SENSOR(" ", "PM4 Weight Concentration", this->pm_4_0_sensor_);
|
||||||
|
LOG_SENSOR(" ", "PM10 Weight Concentration", this->pm_10_0_sensor_);
|
||||||
|
LOG_SENSOR(" ", "PM1.0 Number Concentration", this->pmc_1_0_sensor_);
|
||||||
|
LOG_SENSOR(" ", "PM2.5 Number Concentration", this->pmc_2_5_sensor_);
|
||||||
|
LOG_SENSOR(" ", "PM4 Number Concentration", this->pmc_4_0_sensor_);
|
||||||
|
LOG_SENSOR(" ", "PM10 Number Concentration", this->pmc_10_0_sensor_);
|
||||||
|
LOG_SENSOR(" ", "PM typical size", this->pm_size_sensor_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SPS30Component::update() {
|
void SPS30Component::update() {
|
||||||
|
@ -123,8 +129,8 @@ void SPS30Component::update() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t raw_read_status[1];
|
uint16_t raw_read_status;
|
||||||
if (!this->read_data_(raw_read_status, 1) || raw_read_status[0] == 0x00) {
|
if (!this->read_data_(&raw_read_status, 1) || raw_read_status == 0x00) {
|
||||||
ESP_LOGD(TAG, "Sensor measurement not ready yet.");
|
ESP_LOGD(TAG, "Sensor measurement not ready yet.");
|
||||||
this->skipped_data_read_cycles_++;
|
this->skipped_data_read_cycles_++;
|
||||||
/// The following logic is required to address the cases when a sensor is quickly replaced before it's marked
|
/// The following logic is required to address the cases when a sensor is quickly replaced before it's marked
|
||||||
|
|
|
@ -33,6 +33,7 @@ class SPS30Component : public PollingComponent, public i2c::I2CDevice {
|
||||||
bool read_data_(uint16_t *data, uint8_t len);
|
bool read_data_(uint16_t *data, uint8_t len);
|
||||||
uint8_t sht_crc_(uint8_t data1, uint8_t data2);
|
uint8_t sht_crc_(uint8_t data1, uint8_t data2);
|
||||||
char serial_number_[17] = {0}; /// Terminating NULL character
|
char serial_number_[17] = {0}; /// Terminating NULL character
|
||||||
|
uint16_t raw_firmware_version_;
|
||||||
bool start_continuous_measurement_();
|
bool start_continuous_measurement_();
|
||||||
uint8_t skipped_data_read_cycles_ = 0;
|
uint8_t skipped_data_read_cycles_ = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue