10static constexpr uint32_t DATA_TIMEOUT_ID = 0;
14 if (!this->
read_byte(REGISTER_VERSION, &version) || version == 0xFF) {
18 ESP_LOGI(TAG,
"Found uFire_ise board version 0x%02X", version);
22 this->
read_byte(REGISTER_CONFIG, &config);
24 config &= ~CONFIG_TEMP_COMPENSATION;
26 config |= CONFIG_TEMP_COMPENSATION;
34 this->
write_byte(REGISTER_TASK, COMMAND_MEASURE_TEMP);
38 this->
write_byte(REGISTER_TASK, COMMAND_MEASURE_MV);
75 ph = fabsf(7.0f - (mv / PROBE_MV_TO_PH));
78 float distance_from_7 = std::abs(7 - roundf(ph));
79 float distance_from_25 = std::floor(std::abs(25 - roundf(
temperature)) / 10);
80 float temp_multiplier = (distance_from_25 * distance_from_7) * PROBE_TMP_CORRECTION;
82 temp_multiplier *= -1;
84 temp_multiplier *= -1;
86 ph += temp_multiplier;
87 if ((ph <= 0.0f) || (ph > 14.0f))
98 solution = (7 - solution) * PROBE_MV_TO_PH;
104 this->
write_byte(REGISTER_TASK, COMMAND_CALIBRATE_LOW);
109 this->
write_byte(REGISTER_TASK, COMMAND_CALIBRATE_HIGH);
123 this->
write(®, 1);
126 for (uint8_t i = 0; i < 4; i++) {
129 memcpy(&f, temp,
sizeof(f));
137 memcpy(temp, &data,
sizeof(data));
143 ESP_LOGCONFIG(TAG,
"uFire-ISE");
145 LOG_UPDATE_INTERVAL(
this);
146 LOG_SENSOR(
" ",
"PH Sensor", this->
ph_sensor_);
void mark_failed()
Mark this component as failed.
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
optional< std::array< uint8_t, N > > read_bytes_raw()
bool write_byte(uint8_t a_register, uint8_t data) const
bool read_byte(uint8_t a_register, uint8_t *data)
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len) const
void publish_state(float state)
Publish a new state to the front-end.
float state
This member variable stores the last state that has passed through all filters.
float read_data_(uint8_t reg)
sensor::Sensor * ph_sensor_
sensor::Sensor * temperature_sensor_
void set_solution_(float solution)
void write_data_(uint8_t reg, float data)
sensor::Sensor * temperature_sensor_external_
void calibrate_probe_low(float solution)
float measure_ph_(float temperature)
float measure_temperature_()
void dump_config() override
void calibrate_probe_high(float solution)
ESPHOME_LOG_TAG(TAG, "ufire_ise")
void HOT delay(uint32_t ms)