9static constexpr uint32_t DATA_TIMEOUT_ID = 0;
13 if (!this->
read_byte(REGISTER_VERSION, &version) || version == 0xFF) {
17 ESP_LOGI(TAG,
"Found ufire_ec board version 0x%02X", version);
20 const bool compensate = this->temperature_sensor_ !=
nullptr || this->external_temperature_sensor_ !=
nullptr;
21 this->
update_register(REGISTER_CONFIG, CONFIG_TEMP_COMPENSATION, compensate ? CONFIG_TEMP_COMPENSATION : 0);
28void UFireECComponent::update() {
31 if (this->temperature_sensor_ !=
nullptr) {
32 this->
write_byte(REGISTER_TASK, COMMAND_MEASURE_TEMP);
34 }
else if (this->external_temperature_sensor_ !=
nullptr) {
38 if (this->ec_sensor_ !=
nullptr) {
39 this->
write_byte(REGISTER_TASK, COMMAND_MEASURE_EC);
50 PUBLISH_STATE(this->ec_sensor_, this->
measure_ms_());
59 if (std::abs(denom) < 1e-6f) {
60 ESP_LOGE(TAG,
"Temperature compensation denominator is zero");
74void UFireECComponent::calibrate_probe(
float solution,
float temperature) {
77 this->
write_byte(REGISTER_TASK, COMMAND_CALIBRATE_PROBE);
80void UFireECComponent::reset_board() { this->
write_data_(REGISTER_CALIBRATE_OFFSET, NAN); }
89 for (uint8_t i = 0; i < 4; i++) {
92 memcpy(&f, temp,
sizeof(f));
100 memcpy(temp, &data,
sizeof(data));
105void UFireECComponent::dump_config() {
108 " Temperature Compensation: %f\n"
109 " Temperature Coefficient: %f",
112 LOG_UPDATE_INTERVAL(this);
113 LOG_SENSOR(" ", "EC Sensor", this->ec_sensor_);
114 LOG_SENSOR(" ", "Temperature Sensor", this->temperature_sensor_);
115 LOG_SENSOR(" ", "Temperature Sensor external", this->external_temperature_sensor_);
bool update_register(uint8_t a_register, uint8_t mask, uint8_t value)
Read a register, replace the bits in mask with those of value and write it back.