ESPHome  2024.11.0
ufire_ise.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_ise {
11 
12 static const float PROBE_MV_TO_PH = 59.2;
13 static const float PROBE_TMP_CORRECTION = 0.03;
14 
15 static const uint8_t CONFIG_TEMP_COMPENSATION = 0x02;
16 
17 static const uint8_t REGISTER_VERSION = 0;
18 static const uint8_t REGISTER_MV = 1;
19 static const uint8_t REGISTER_TEMP = 5;
20 static const uint8_t REGISTER_REFHIGH = 13;
21 static const uint8_t REGISTER_REFLOW = 17;
22 static const uint8_t REGISTER_READHIGH = 21;
23 static const uint8_t REGISTER_READLOW = 25;
24 static const uint8_t REGISTER_SOLUTION = 29;
25 static const uint8_t REGISTER_CONFIG = 38;
26 static const uint8_t REGISTER_TASK = 39;
27 
28 static const uint8_t COMMAND_CALIBRATE_HIGH = 8;
29 static const uint8_t COMMAND_CALIBRATE_LOW = 10;
30 static const uint8_t COMMAND_MEASURE_TEMP = 40;
31 static const uint8_t COMMAND_MEASURE_MV = 80;
32 
34  public:
35  void setup() override;
36  void update() override;
37  void dump_config() override;
38 
39  void set_temperature_sensor(sensor::Sensor *temperature_sensor) { this->temperature_sensor_ = temperature_sensor; }
40  void set_temperature_sensor_external(sensor::Sensor *temperature_sensor) {
41  this->temperature_sensor_external_ = temperature_sensor;
42  }
43  void set_ph_sensor(sensor::Sensor *ph_sensor) { this->ph_sensor_ = ph_sensor; }
44  void calibrate_probe_low(float solution);
45  void calibrate_probe_high(float solution);
46  void reset_board();
47 
48  protected:
49  float measure_temperature_();
50  float measure_mv_();
51  float measure_ph_(float temperature);
52  void set_solution_(float solution);
53  float read_data_(uint8_t reg);
54  void write_data_(uint8_t reg, float data);
55  void update_internal_();
56 
60 };
61 
62 template<typename... Ts> class UFireISECalibrateProbeLowAction : public Action<Ts...> {
63  public:
64  UFireISECalibrateProbeLowAction(UFireISEComponent *parent) : parent_(parent) {}
65  TEMPLATABLE_VALUE(float, solution)
66 
67  void play(Ts... x) override { this->parent_->calibrate_probe_low(this->solution_.value(x...)); }
68 
69  protected:
71 };
72 
73 template<typename... Ts> class UFireISECalibrateProbeHighAction : public Action<Ts...> {
74  public:
76  TEMPLATABLE_VALUE(float, solution)
77 
78  void play(Ts... x) override { this->parent_->calibrate_probe_high(this->solution_.value(x...)); }
79 
80  protected:
82 };
83 
84 template<typename... Ts> class UFireISEResetAction : public Action<Ts...> {
85  public:
86  UFireISEResetAction(UFireISEComponent *parent) : parent_(parent) {}
87 
88  void play(Ts... x) override { this->parent_->reset_board(); }
89 
90  protected:
92 };
93 
94 } // namespace ufire_ise
95 } // namespace esphome
UFireISECalibrateProbeLowAction(UFireISEComponent *parent)
Definition: ufire_ise.h:64
void write_data_(uint8_t reg, float data)
Definition: ufire_ise.cpp:135
TEMPLATABLE_VALUE(float, solution) void play(Ts... x) override
Definition: ufire_ise.h:65
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition: i2c.h:149
uint16_t x
Definition: tt21100.cpp:17
This class simplifies creating components that periodically check a state.
Definition: component.h:283
UFireISECalibrateProbeHighAction(UFireISEComponent *parent)
Definition: ufire_ise.h:75
sensor::Sensor * temperature_sensor_external_
Definition: ufire_ise.h:58
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition: ufire_ise.h:39
void set_ph_sensor(sensor::Sensor *ph_sensor)
Definition: ufire_ise.h:43
void calibrate_probe_high(float solution)
Definition: ufire_ise.cpp:108
uint16_t temperature
Definition: sun_gtil2.cpp:26
TEMPLATABLE_VALUE(float, solution) void play(Ts... x) override
Definition: ufire_ise.h:76
void calibrate_probe_low(float solution)
Definition: ufire_ise.cpp:103
float measure_ph_(float temperature)
Definition: ufire_ise.cpp:69
sensor::Sensor * temperature_sensor_
Definition: ufire_ise.h:57
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
UFireISEResetAction(UFireISEComponent *parent)
Definition: ufire_ise.h:86
void set_solution_(float solution)
Definition: ufire_ise.cpp:98
Base-class for all sensors.
Definition: sensor.h:57
void set_temperature_sensor_external(sensor::Sensor *temperature_sensor)
Definition: ufire_ise.h:40
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133