ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
ezo_pmp.h
Go to the documentation of this file.
1#pragma once
2
7
8#ifdef USE_BINARY_SENSOR
10#endif
11
12#ifdef USE_SENSOR
14#endif
15
16#ifdef USE_TEXT_SENSOR
18#endif
19
20namespace esphome {
21namespace ezo_pmp {
22
23class EzoPMP : public PollingComponent, public i2c::I2CDevice {
24 public:
25 void dump_config() override;
26
27 void loop() override;
28 void update() override;
29
30#ifdef USE_SENSOR
31 void set_current_volume_dosed(sensor::Sensor *current_volume_dosed) { current_volume_dosed_ = current_volume_dosed; }
32 void set_total_volume_dosed(sensor::Sensor *total_volume_dosed) { total_volume_dosed_ = total_volume_dosed; }
33 void set_absolute_total_volume_dosed(sensor::Sensor *absolute_total_volume_dosed) {
34 absolute_total_volume_dosed_ = absolute_total_volume_dosed;
35 }
36 void set_pump_voltage(sensor::Sensor *pump_voltage) { pump_voltage_ = pump_voltage; }
37 void set_last_volume_requested(sensor::Sensor *last_volume_requested) {
38 last_volume_requested_ = last_volume_requested;
39 }
40 void set_max_flow_rate(sensor::Sensor *max_flow_rate) { max_flow_rate_ = max_flow_rate; }
41#endif
42
43#ifdef USE_BINARY_SENSOR
44 void set_is_dosing(binary_sensor::BinarySensor *is_dosing) { is_dosing_ = is_dosing; }
45 void set_is_paused(binary_sensor::BinarySensor *is_paused) { is_paused_ = is_paused; }
46#endif
47
48#ifdef USE_TEXT_SENSOR
49 void set_dosing_mode(text_sensor::TextSensor *dosing_mode) { dosing_mode_ = dosing_mode; }
50 void set_calibration_status(text_sensor::TextSensor *calibration_status) { calibration_status_ = calibration_status; }
51#endif
52
53 // Actions for EZO-PMP
54 void find();
55 void dose_continuously();
56 void dose_volume(double volume);
57 void dose_volume_over_time(double volume, int duration);
58 void dose_with_constant_flow_rate(double volume, int duration);
59 void set_calibration_volume(double volume);
61 void clear_calibration();
62 void pause_dosing();
63 void stop_dosing();
65 void exec_arbitrary_command(const std::basic_string<char> &command);
66
67 protected:
68 uint32_t start_time_ = 0;
69 uint32_t wait_time_ = 0;
70 bool is_waiting_ = false;
71 bool is_first_read_ = true;
72
73 uint16_t next_command_ = 0;
74 double next_command_volume_ = 0; // might be negative
76
77 uint16_t next_command_queue_[10];
83
84 uint16_t current_command_ = 0;
85 bool is_paused_flag_ = false;
86 bool is_dosing_flag_ = false;
87
88 const char *arbitrary_command_{nullptr};
89
90 void send_next_command_();
93 void queue_command_(uint16_t command, double volume, int duration, bool should_schedule);
94 void pop_next_command_();
95 uint16_t peek_next_command_();
96
97#ifdef USE_SENSOR
104#endif
105
106#ifdef USE_BINARY_SENSOR
109#endif
110
111#ifdef USE_TEXT_SENSOR
114#endif
115};
116
117// Action Templates
118template<typename... Ts> class EzoPMPFindAction : public Action<Ts...> {
119 public:
120 EzoPMPFindAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
121
122 void play(Ts... x) override { this->ezopmp_->find(); }
123
124 protected:
126};
127
128template<typename... Ts> class EzoPMPDoseContinuouslyAction : public Action<Ts...> {
129 public:
131
132 void play(Ts... x) override { this->ezopmp_->dose_continuously(); }
133
134 protected:
136};
137
138template<typename... Ts> class EzoPMPDoseVolumeAction : public Action<Ts...> {
139 public:
140 EzoPMPDoseVolumeAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
141
142 void play(Ts... x) override { this->ezopmp_->dose_volume(this->volume_.value(x...)); }
143 TEMPLATABLE_VALUE(double, volume)
144
145 protected:
146 EzoPMP *ezopmp_;
147};
148
149template<typename... Ts> class EzoPMPDoseVolumeOverTimeAction : public Action<Ts...> {
150 public:
152
153 void play(Ts... x) override {
154 this->ezopmp_->dose_volume_over_time(this->volume_.value(x...), this->duration_.value(x...));
155 }
156 TEMPLATABLE_VALUE(double, volume)
158
159 protected:
161};
162
163template<typename... Ts> class EzoPMPDoseWithConstantFlowRateAction : public Action<Ts...> {
164 public:
166
167 void play(Ts... x) override {
168 this->ezopmp_->dose_with_constant_flow_rate(this->volume_.value(x...), this->duration_.value(x...));
169 }
170 TEMPLATABLE_VALUE(double, volume)
172
173 protected:
175};
176
177template<typename... Ts> class EzoPMPSetCalibrationVolumeAction : public Action<Ts...> {
178 public:
179 EzoPMPSetCalibrationVolumeAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
180
181 void play(Ts... x) override { this->ezopmp_->set_calibration_volume(this->volume_.value(x...)); }
182 TEMPLATABLE_VALUE(double, volume)
183
184 protected:
185 EzoPMP *ezopmp_;
186};
187
188template<typename... Ts> class EzoPMPClearTotalVolumeDispensedAction : public Action<Ts...> {
189 public:
191
192 void play(Ts... x) override { this->ezopmp_->clear_total_volume_dosed(); }
193
194 protected:
196};
197
198template<typename... Ts> class EzoPMPClearCalibrationAction : public Action<Ts...> {
199 public:
201
202 void play(Ts... x) override { this->ezopmp_->clear_calibration(); }
203
204 protected:
206};
207
208template<typename... Ts> class EzoPMPPauseDosingAction : public Action<Ts...> {
209 public:
211
212 void play(Ts... x) override { this->ezopmp_->pause_dosing(); }
213
214 protected:
216};
217
218template<typename... Ts> class EzoPMPStopDosingAction : public Action<Ts...> {
219 public:
221
222 void play(Ts... x) override { this->ezopmp_->stop_dosing(); }
223
224 protected:
226};
227
228template<typename... Ts> class EzoPMPChangeI2CAddressAction : public Action<Ts...> {
229 public:
230 EzoPMPChangeI2CAddressAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
231
232 void play(Ts... x) override { this->ezopmp_->change_i2c_address(this->address_.value(x...)); }
233 TEMPLATABLE_VALUE(int, address)
234
235 protected:
236 EzoPMP *ezopmp_;
237};
238
239template<typename... Ts> class EzoPMPArbitraryCommandAction : public Action<Ts...> {
240 public:
241 EzoPMPArbitraryCommandAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
242
243 void play(Ts... x) override { this->ezopmp_->exec_arbitrary_command(this->command_.value(x...)); }
244 TEMPLATABLE_VALUE(std::string, command)
245
246 protected:
247 EzoPMP *ezopmp_;
248};
249
250} // namespace ezo_pmp
251} // namespace esphome
uint8_t address
Definition bl0906.h:4
This class simplifies creating components that periodically check a state.
Definition component.h:425
Base class for all binary_sensor-type classes.
TEMPLATABLE_VALUE(double, volume) TEMPLATABLE_VALUE(int
TEMPLATABLE_VALUE(double, volume) TEMPLATABLE_VALUE(int
void play(Ts... x) override
Definition ezo_pmp.h:122
sensor::Sensor * total_volume_dosed_
Definition ezo_pmp.h:99
void exec_arbitrary_command(const std::basic_string< char > &command)
Definition ezo_pmp.cpp:537
const char * arbitrary_command_
Definition ezo_pmp.h:88
void dose_volume(double volume)
Definition ezo_pmp.cpp:489
uint16_t current_command_
Definition ezo_pmp.h:84
void set_is_paused(binary_sensor::BinarySensor *is_paused)
Definition ezo_pmp.h:45
binary_sensor::BinarySensor * is_paused_
Definition ezo_pmp.h:108
int next_command_duration_queue_[10]
Definition ezo_pmp.h:79
void set_current_volume_dosed(sensor::Sensor *current_volume_dosed)
Definition ezo_pmp.h:31
sensor::Sensor * max_flow_rate_
Definition ezo_pmp.h:102
void set_pump_voltage(sensor::Sensor *pump_voltage)
Definition ezo_pmp.h:36
void set_dosing_mode(text_sensor::TextSensor *dosing_mode)
Definition ezo_pmp.h:49
uint16_t next_command_queue_[10]
Definition ezo_pmp.h:77
void dump_config() override
Definition ezo_pmp.cpp:41
void set_max_flow_rate(sensor::Sensor *max_flow_rate)
Definition ezo_pmp.h:40
double next_command_volume_queue_[10]
Definition ezo_pmp.h:78
void set_calibration_volume(double volume)
Definition ezo_pmp.cpp:507
void set_absolute_total_volume_dosed(sensor::Sensor *absolute_total_volume_dosed)
Definition ezo_pmp.h:33
void set_total_volume_dosed(sensor::Sensor *total_volume_dosed)
Definition ezo_pmp.h:32
void set_calibration_status(text_sensor::TextSensor *calibration_status)
Definition ezo_pmp.h:50
void change_i2c_address(int address)
Definition ezo_pmp.cpp:533
void queue_command_(uint16_t command, double volume, int duration, bool should_schedule)
Definition ezo_pmp.cpp:454
void loop() override
Definition ezo_pmp.cpp:81
binary_sensor::BinarySensor * is_dosing_
Definition ezo_pmp.h:107
sensor::Sensor * last_volume_requested_
Definition ezo_pmp.h:103
void set_is_dosing(binary_sensor::BinarySensor *is_dosing)
Definition ezo_pmp.h:44
void dose_volume_over_time(double volume, int duration)
Definition ezo_pmp.cpp:495
void set_last_volume_requested(sensor::Sensor *last_volume_requested)
Definition ezo_pmp.h:37
uint16_t peek_next_command_()
Definition ezo_pmp.cpp:446
sensor::Sensor * absolute_total_volume_dosed_
Definition ezo_pmp.h:100
text_sensor::TextSensor * dosing_mode_
Definition ezo_pmp.h:112
sensor::Sensor * pump_voltage_
Definition ezo_pmp.h:101
sensor::Sensor * current_volume_dosed_
Definition ezo_pmp.h:98
void dose_with_constant_flow_rate(double volume, int duration)
Definition ezo_pmp.cpp:501
void update() override
Definition ezo_pmp.cpp:49
text_sensor::TextSensor * calibration_status_
Definition ezo_pmp.h:113
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:133
Base-class for all sensors.
Definition sensor.h:59
uint8_t duration
Definition msa3xx.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t x
Definition tt21100.cpp:5