mirror of
https://github.com/esphome/esphome.git
synced 2025-07-28 06:06:33 +00:00
[scd4x] Memory optimization (#9358)
This commit is contained in:
parent
e49b89a051
commit
364b6ca8d0
@ -58,7 +58,7 @@ void SCD4XComponent::setup() {
|
||||
}
|
||||
|
||||
// If pressure compensation available use it, else use altitude
|
||||
if (this->ambient_pressure_compensation_) {
|
||||
if (this->ambient_pressure_) {
|
||||
if (!this->update_ambient_pressure_compensation_(this->ambient_pressure_)) {
|
||||
ESP_LOGE(TAG, "Error setting ambient pressure compensation");
|
||||
this->error_code_ = MEASUREMENT_INIT_FAILED;
|
||||
@ -137,7 +137,7 @@ void SCD4XComponent::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, " Dynamic ambient pressure compensation using '%s'",
|
||||
this->ambient_pressure_source_->get_name().c_str());
|
||||
} else {
|
||||
if (this->ambient_pressure_compensation_) {
|
||||
if (this->ambient_pressure_) {
|
||||
ESP_LOGCONFIG(TAG,
|
||||
" Altitude compensation disabled\n"
|
||||
" Ambient pressure compensation: %dmBar",
|
||||
@ -230,7 +230,7 @@ bool SCD4XComponent::perform_forced_calibration(uint16_t current_co2_concentrati
|
||||
// frc takes 400 ms
|
||||
// because this method will be used very rarly
|
||||
// the simple approach with delay is ok
|
||||
delay(400); // NOLINT'
|
||||
delay(400); // NOLINT
|
||||
if (!this->start_measurement_()) {
|
||||
return false;
|
||||
} else {
|
||||
@ -267,8 +267,7 @@ bool SCD4XComponent::factory_reset() {
|
||||
}
|
||||
|
||||
void SCD4XComponent::set_ambient_pressure_compensation(float pressure_in_hpa) {
|
||||
ambient_pressure_compensation_ = true;
|
||||
uint16_t new_ambient_pressure = (uint16_t) pressure_in_hpa;
|
||||
uint16_t new_ambient_pressure = static_cast<uint16_t>(pressure_in_hpa);
|
||||
if (!this->initialized_) {
|
||||
this->ambient_pressure_ = new_ambient_pressure;
|
||||
return;
|
||||
|
@ -46,19 +46,17 @@ class SCD4XComponent : public PollingComponent, public sensirion_common::Sensiri
|
||||
bool update_ambient_pressure_compensation_(uint16_t pressure_in_hpa);
|
||||
bool start_measurement_();
|
||||
|
||||
uint16_t altitude_compensation_;
|
||||
uint16_t ambient_pressure_;
|
||||
bool initialized_{false};
|
||||
bool ambient_pressure_compensation_;
|
||||
bool enable_asc_;
|
||||
float temperature_offset_;
|
||||
ErrorCode error_code_;
|
||||
MeasurementMode measurement_mode_{PERIODIC};
|
||||
sensor::Sensor *co2_sensor_{nullptr};
|
||||
sensor::Sensor *temperature_sensor_{nullptr};
|
||||
sensor::Sensor *humidity_sensor_{nullptr};
|
||||
// used for compensation
|
||||
sensor::Sensor *ambient_pressure_source_{nullptr};
|
||||
sensor::Sensor *ambient_pressure_source_{nullptr}; // used for compensation
|
||||
float temperature_offset_;
|
||||
uint16_t altitude_compensation_{0};
|
||||
uint16_t ambient_pressure_{0}; // Per datasheet, valid values are 700 to 1200 hPa; 0 is a valid sentinel value
|
||||
bool initialized_{false};
|
||||
bool enable_asc_{false};
|
||||
ErrorCode error_code_;
|
||||
MeasurementMode measurement_mode_{PERIODIC};
|
||||
};
|
||||
|
||||
} // namespace scd4x
|
||||
|
Loading…
x
Reference in New Issue
Block a user