9static const char *
const TAG =
"ufire_ise";
13 if (!this->
read_byte(REGISTER_VERSION, &version) && version != 0xFF) {
17 ESP_LOGI(TAG,
"Found uFire_ise board version 0x%02X", version);
21 this->
read_byte(REGISTER_CONFIG, &config);
23 config &= ~CONFIG_TEMP_COMPENSATION;
25 config |= CONFIG_TEMP_COMPENSATION;
33 this->
write_byte(REGISTER_TASK, COMMAND_MEASURE_TEMP);
37 this->
write_byte(REGISTER_TASK, COMMAND_MEASURE_MV);
74 ph = fabs(7.0 - (mv / PROBE_MV_TO_PH));
77 float distance_from_7 = std::abs(7 - roundf(ph));
78 float distance_from_25 = std::floor(std::abs(25 - roundf(
temperature)) / 10);
79 float temp_multiplier = (distance_from_25 * distance_from_7) * PROBE_TMP_CORRECTION;
81 temp_multiplier *= -1;
83 temp_multiplier *= -1;
85 ph += temp_multiplier;
86 if ((ph <= 0.0) || (ph > 14.0))
97 solution = (7 - solution) * PROBE_MV_TO_PH;
103 this->
write_byte(REGISTER_TASK, COMMAND_CALIBRATE_LOW);
108 this->
write_byte(REGISTER_TASK, COMMAND_CALIBRATE_HIGH);
122 this->
write(®, 1);
125 for (uint8_t i = 0; i < 4; i++) {
128 memcpy(&f, temp,
sizeof(f));
136 memcpy(temp, &data,
sizeof(data));
142 ESP_LOGCONFIG(TAG,
"uFire-ISE");
144 LOG_UPDATE_INTERVAL(
this)
145 LOG_SENSOR(
" ",
"PH Sensor", this->
ph_sensor_)
virtual void mark_failed()
Mark this component as failed.
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len, bool stop=true)
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
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, bool stop=true)
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
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)
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT delay(uint32_t ms)