ESPHome  2024.10.2
ufire_ec.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "esphome/core/hal.h"
8 
9 namespace esphome {
10 namespace ufire_ec {
11 
12 static const uint8_t CONFIG_TEMP_COMPENSATION = 0x02;
13 
14 static const uint8_t REGISTER_VERSION = 0;
15 static const uint8_t REGISTER_MS = 1;
16 static const uint8_t REGISTER_TEMP = 5;
17 static const uint8_t REGISTER_SOLUTION = 9;
18 static const uint8_t REGISTER_COEFFICENT = 13;
19 static const uint8_t REGISTER_CALIBRATE_OFFSET = 33;
20 static const uint8_t REGISTER_COMPENSATION = 45;
21 static const uint8_t REGISTER_CONFIG = 54;
22 static const uint8_t REGISTER_TASK = 55;
23 
24 static const uint8_t COMMAND_CALIBRATE_PROBE = 20;
25 static const uint8_t COMMAND_MEASURE_TEMP = 40;
26 static const uint8_t COMMAND_MEASURE_EC = 80;
27 
29  public:
30  void setup() override;
31  void update() override;
32  void dump_config() override;
33 
34  void set_temperature_sensor(sensor::Sensor *temperature_sensor) { this->temperature_sensor_ = temperature_sensor; }
35  void set_temperature_sensor_external(sensor::Sensor *temperature_sensor) {
36  this->temperature_sensor_external_ = temperature_sensor;
37  }
38  void set_ec_sensor(sensor::Sensor *ec_sensor) { this->ec_sensor_ = ec_sensor; }
39  void set_temperature_compensation(float compensation) { this->temperature_compensation_ = compensation; }
40  void set_temperature_coefficient(float coefficient) { this->temperature_coefficient_ = coefficient; }
41  void calibrate_probe(float solution, float temperature);
42  void reset_board();
43 
44  protected:
45  float measure_temperature_();
46  float measure_ms_();
47  void set_solution_(float solution, float temperature);
48  void set_compensation_(float temperature);
49  void set_coefficient_(float coefficient);
50  void set_temperature_(float temperature);
51  float read_data_(uint8_t reg);
52  void write_data_(uint8_t reg, float data);
53  void update_internal_();
54 
60 };
61 
62 template<typename... Ts> class UFireECCalibrateProbeAction : public Action<Ts...> {
63  public:
64  UFireECCalibrateProbeAction(UFireECComponent *parent) : parent_(parent) {}
65  TEMPLATABLE_VALUE(float, solution)
66  TEMPLATABLE_VALUE(float, temperature)
67 
68  void play(Ts... x) override {
69  this->parent_->calibrate_probe(this->solution_.value(x...), this->temperature_.value(x...));
70  }
71 
72  protected:
74 };
75 
76 template<typename... Ts> class UFireECResetAction : public Action<Ts...> {
77  public:
78  UFireECResetAction(UFireECComponent *parent) : parent_(parent) {}
79 
80  void play(Ts... x) override { this->parent_->reset_board(); }
81 
82  protected:
84 };
85 
86 } // namespace ufire_ec
87 } // namespace esphome
sensor::Sensor * temperature_sensor_
Definition: ufire_ec.h:55
void play(Ts... x) override
Definition: ufire_ec.h:80
void calibrate_probe(float solution, float temperature)
Definition: ufire_ec.cpp:76
void set_temperature_coefficient(float coefficient)
Definition: ufire_ec.h:40
void write_data_(uint8_t reg, float data)
Definition: ufire_ec.cpp:98
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition: i2c.h:149
uint16_t x
Definition: tt21100.cpp:17
void set_temperature_compensation(float compensation)
Definition: ufire_ec.h:39
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_temperature_(float temperature)
Definition: ufire_ec.cpp:74
UFireECResetAction(UFireECComponent *parent)
Definition: ufire_ec.h:78
UFireECCalibrateProbeAction(UFireECComponent *parent)
Definition: ufire_ec.h:64
void set_solution_(float solution, float temperature)
Definition: ufire_ec.cpp:65
uint16_t temperature
Definition: sun_gtil2.cpp:26
void set_ec_sensor(sensor::Sensor *ec_sensor)
Definition: ufire_ec.h:38
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition: ufire_ec.h:34
void set_coefficient_(float coefficient)
Definition: ufire_ec.cpp:72
void set_compensation_(float temperature)
Definition: ufire_ec.cpp:70
void set_temperature_sensor_external(sensor::Sensor *temperature_sensor)
Definition: ufire_ec.h:35
sensor::Sensor * temperature_sensor_external_
Definition: ufire_ec.h:56
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base-class for all sensors.
Definition: sensor.h:57
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133