9 static const char *
const TAG =
"ufire_ise";
12 ESP_LOGCONFIG(TAG,
"Setting up uFire_ise...");
15 if (!this->
read_byte(REGISTER_VERSION, &version) && version != 0xFF) {
19 ESP_LOGI(TAG,
"Found uFire_ise board version 0x%02X", version);
23 this->
read_byte(REGISTER_CONFIG, &config);
25 config &= ~CONFIG_TEMP_COMPENSATION;
27 config |= CONFIG_TEMP_COMPENSATION;
35 this->
write_byte(REGISTER_TASK, COMMAND_MEASURE_TEMP);
39 this->
write_byte(REGISTER_TASK, COMMAND_MEASURE_MV);
76 ph = fabs(7.0 - (mv / PROBE_MV_TO_PH));
79 float distance_from_7 = std::abs(7 - roundf(ph));
80 float distance_from_25 = std::floor(std::abs(25 - roundf(temperature)) / 10);
81 float temp_multiplier = (distance_from_25 * distance_from_7) * PROBE_TMP_CORRECTION;
82 if ((ph >= 8.0) && (temperature >= 35))
83 temp_multiplier *= -1;
84 if ((ph <= 6.0) && (temperature <= 15))
85 temp_multiplier *= -1;
87 ph += temp_multiplier;
88 if ((ph <= 0.0) || (ph > 14.0))
99 solution = (7 - solution) * PROBE_MV_TO_PH;
105 this->
write_byte(REGISTER_TASK, COMMAND_CALIBRATE_LOW);
110 this->
write_byte(REGISTER_TASK, COMMAND_CALIBRATE_HIGH);
124 this->
write(®, 1);
127 for (uint8_t i = 0; i < 4; i++) {
130 memcpy(&f, temp,
sizeof(f));
138 memcpy(temp, &data,
sizeof(data));
144 ESP_LOGCONFIG(TAG,
"uFire-ISE");
146 LOG_UPDATE_INTERVAL(
this)
147 LOG_SENSOR(
" ",
"PH Sensor", this->
ph_sensor_)
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
void write_data_(uint8_t reg, float data)
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
optional< std::array< uint8_t, N > > read_bytes_raw()
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
sensor::Sensor * temperature_sensor_external_
float state
This member variable stores the last state that has passed through all filters.
float measure_temperature_()
void dump_config() override
void calibrate_probe_high(float solution)
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * ph_sensor_
float read_data_(uint8_t reg)
void calibrate_probe_low(float solution)
float measure_ph_(float temperature)
sensor::Sensor * temperature_sensor_
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
void set_solution_(float solution)
void IRAM_ATTR HOT delay(uint32_t ms)
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len, bool stop=true)