mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 17:05:21 +01:00
Remove floating point ops from the ISR (#2751)
Co-authored-by: Samuel Sieb <samuel@sieb.net>
This commit is contained in:
parent
61ec16cdfc
commit
1424091ee5
2 changed files with 28 additions and 20 deletions
|
@ -57,38 +57,46 @@ void IRAM_ATTR ZaSensorStore::interrupt(ZaSensorStore *arg) {
|
||||||
void IRAM_ATTR ZaSensorStore::set_data_(ZaMessage *message) {
|
void IRAM_ATTR ZaSensorStore::set_data_(ZaMessage *message) {
|
||||||
switch (message->type) {
|
switch (message->type) {
|
||||||
case HUMIDITY:
|
case HUMIDITY:
|
||||||
this->humidity = (message->value > 10000) ? NAN : (message->value / 100.0f);
|
this->humidity = message->value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TEMPERATURE:
|
case TEMPERATURE:
|
||||||
this->temperature = (message->value > 5970) ? NAN : (message->value / 16.0f - 273.15f);
|
this->temperature = message->value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CO2:
|
case CO2:
|
||||||
this->co2 = (message->value > 10000) ? NAN : message->value;
|
this->co2 = message->value;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZyAuraSensor::publish_state_(sensor::Sensor *sensor, float *value) {
|
bool ZyAuraSensor::publish_state_(ZaDataType data_type, sensor::Sensor *sensor, uint16_t *data_value) {
|
||||||
// Sensor doesn't added to configuration
|
// Sensor wasn't added to configuration
|
||||||
if (sensor == nullptr) {
|
if (sensor == nullptr) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sensor->publish_state(*value);
|
float value = NAN;
|
||||||
|
switch (data_type) {
|
||||||
|
case HUMIDITY:
|
||||||
|
value = (*data_value > 10000) ? NAN : (*data_value / 100.0f);
|
||||||
|
break;
|
||||||
|
case TEMPERATURE:
|
||||||
|
value = (*data_value > 5970) ? NAN : (*data_value / 16.0f - 273.15f);
|
||||||
|
break;
|
||||||
|
case CO2:
|
||||||
|
value = (*data_value > 10000) ? NAN : *data_value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
sensor->publish_state(value);
|
||||||
|
|
||||||
// Sensor reported wrong value
|
// Sensor reported wrong value
|
||||||
if (std::isnan(*value)) {
|
if (std::isnan(value)) {
|
||||||
ESP_LOGW(TAG, "Sensor reported invalid data. Is the update interval too small?");
|
ESP_LOGW(TAG, "Sensor reported invalid data. Is the update interval too small?");
|
||||||
this->status_set_warning();
|
this->status_set_warning();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
*value = NAN;
|
*data_value = -1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,9 +112,9 @@ void ZyAuraSensor::dump_config() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZyAuraSensor::update() {
|
void ZyAuraSensor::update() {
|
||||||
bool co2_result = this->publish_state_(this->co2_sensor_, &this->store_.co2);
|
bool co2_result = this->publish_state_(CO2, this->co2_sensor_, &this->store_.co2);
|
||||||
bool temperature_result = this->publish_state_(this->temperature_sensor_, &this->store_.temperature);
|
bool temperature_result = this->publish_state_(TEMPERATURE, this->temperature_sensor_, &this->store_.temperature);
|
||||||
bool humidity_result = this->publish_state_(this->humidity_sensor_, &this->store_.humidity);
|
bool humidity_result = this->publish_state_(HUMIDITY, this->humidity_sensor_, &this->store_.humidity);
|
||||||
|
|
||||||
if (co2_result && temperature_result && humidity_result) {
|
if (co2_result && temperature_result && humidity_result) {
|
||||||
this->status_clear_warning();
|
this->status_clear_warning();
|
||||||
|
|
|
@ -42,9 +42,9 @@ class ZaDataProcessor {
|
||||||
|
|
||||||
class ZaSensorStore {
|
class ZaSensorStore {
|
||||||
public:
|
public:
|
||||||
float co2 = NAN;
|
uint16_t co2 = -1;
|
||||||
float temperature = NAN;
|
uint16_t temperature = -1;
|
||||||
float humidity = NAN;
|
uint16_t humidity = -1;
|
||||||
|
|
||||||
void setup(InternalGPIOPin *pin_clock, InternalGPIOPin *pin_data);
|
void setup(InternalGPIOPin *pin_clock, InternalGPIOPin *pin_data);
|
||||||
static void interrupt(ZaSensorStore *arg);
|
static void interrupt(ZaSensorStore *arg);
|
||||||
|
@ -79,7 +79,7 @@ class ZyAuraSensor : public PollingComponent {
|
||||||
sensor::Sensor *temperature_sensor_{nullptr};
|
sensor::Sensor *temperature_sensor_{nullptr};
|
||||||
sensor::Sensor *humidity_sensor_{nullptr};
|
sensor::Sensor *humidity_sensor_{nullptr};
|
||||||
|
|
||||||
bool publish_state_(sensor::Sensor *sensor, float *value);
|
bool publish_state_(ZaDataType data_type, sensor::Sensor *sensor, uint16_t *data_value);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace zyaura
|
} // namespace zyaura
|
||||||
|
|
Loading…
Reference in a new issue