ESPHome 2026.3.0
Loading...
Searching...
No Matches
ezo_pmp.cpp
Go to the documentation of this file.
1#include "ezo_pmp.h"
2#include "esphome/core/log.h"
3#include "esphome/core/hal.h"
4
5namespace esphome {
6namespace ezo_pmp {
7
8static const char *const TAG = "ezo-pmp";
9
10static const uint16_t EZO_PMP_COMMAND_NONE = 0;
11static const uint16_t EZO_PMP_COMMAND_TYPE_READ = 1;
12
13static const uint16_t EZO_PMP_COMMAND_FIND = 2;
14static const uint16_t EZO_PMP_COMMAND_DOSE_CONTINUOUSLY = 4;
15static const uint16_t EZO_PMP_COMMAND_DOSE_VOLUME = 8;
16static const uint16_t EZO_PMP_COMMAND_DOSE_VOLUME_OVER_TIME = 16;
17static const uint16_t EZO_PMP_COMMAND_DOSE_WITH_CONSTANT_FLOW_RATE = 32;
18static const uint16_t EZO_PMP_COMMAND_SET_CALIBRATION_VOLUME = 64;
19static const uint16_t EZO_PMP_COMMAND_CLEAR_TOTAL_VOLUME_DOSED = 128;
20static const uint16_t EZO_PMP_COMMAND_CLEAR_CALIBRATION = 256;
21static const uint16_t EZO_PMP_COMMAND_PAUSE_DOSING = 512;
22static const uint16_t EZO_PMP_COMMAND_STOP_DOSING = 1024;
23static const uint16_t EZO_PMP_COMMAND_CHANGE_I2C_ADDRESS = 2048;
24static const uint16_t EZO_PMP_COMMAND_EXEC_ARBITRARY_COMMAND_ADDRESS = 4096;
25
26static const uint16_t EZO_PMP_COMMAND_READ_DOSING = 3;
27static const uint16_t EZO_PMP_COMMAND_READ_SINGLE_REPORT = 5;
28static const uint16_t EZO_PMP_COMMAND_READ_MAX_FLOW_RATE = 9;
29static const uint16_t EZO_PMP_COMMAND_READ_PAUSE_STATUS = 17;
30static const uint16_t EZO_PMP_COMMAND_READ_TOTAL_VOLUME_DOSED = 33;
31static const uint16_t EZO_PMP_COMMAND_READ_ABSOLUTE_TOTAL_VOLUME_DOSED = 65;
32static const uint16_t EZO_PMP_COMMAND_READ_CALIBRATION_STATUS = 129;
33static const uint16_t EZO_PMP_COMMAND_READ_PUMP_VOLTAGE = 257;
34
35static const std::string DOSING_MODE_NONE = "None";
36static const std::string DOSING_MODE_VOLUME = "Volume";
37static const std::string DOSING_MODE_VOLUME_OVER_TIME = "Volume/Time";
38static const std::string DOSING_MODE_CONSTANT_FLOW_RATE = "Constant Flow Rate";
39static const std::string DOSING_MODE_CONTINUOUS = "Continuous";
40
42 LOG_I2C_DEVICE(this);
43 if (this->is_failed()) {
44 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
45 }
46 LOG_UPDATE_INTERVAL(this);
47}
48
50 if (this->is_waiting_) {
51 return;
52 }
53
54 if (this->is_first_read_) {
55 this->queue_command_(EZO_PMP_COMMAND_READ_CALIBRATION_STATUS, 0, 0, (bool) this->calibration_status_);
56 this->queue_command_(EZO_PMP_COMMAND_READ_MAX_FLOW_RATE, 0, 0, (bool) this->max_flow_rate_);
57 this->queue_command_(EZO_PMP_COMMAND_READ_SINGLE_REPORT, 0, 0, (bool) this->current_volume_dosed_);
58 this->queue_command_(EZO_PMP_COMMAND_READ_TOTAL_VOLUME_DOSED, 0, 0, (bool) this->total_volume_dosed_);
59 this->queue_command_(EZO_PMP_COMMAND_READ_ABSOLUTE_TOTAL_VOLUME_DOSED, 0, 0,
60 (bool) this->absolute_total_volume_dosed_);
61 this->queue_command_(EZO_PMP_COMMAND_READ_PAUSE_STATUS, 0, 0, true);
62 this->is_first_read_ = false;
63 }
64
65 if (!this->is_waiting_ && this->peek_next_command_() == EZO_PMP_COMMAND_NONE) {
66 this->queue_command_(EZO_PMP_COMMAND_READ_DOSING, 0, 0, true);
67
68 if (this->is_dosing_flag_) {
69 this->queue_command_(EZO_PMP_COMMAND_READ_SINGLE_REPORT, 0, 0, (bool) this->current_volume_dosed_);
70 this->queue_command_(EZO_PMP_COMMAND_READ_TOTAL_VOLUME_DOSED, 0, 0, (bool) this->total_volume_dosed_);
71 this->queue_command_(EZO_PMP_COMMAND_READ_ABSOLUTE_TOTAL_VOLUME_DOSED, 0, 0,
72 (bool) this->absolute_total_volume_dosed_);
73 }
74
75 this->queue_command_(EZO_PMP_COMMAND_READ_PUMP_VOLTAGE, 0, 0, (bool) this->pump_voltage_);
76 } else {
77 ESP_LOGV(TAG, "Not Scheduling new Command during update()");
78 }
79}
80
82 // If we are not waiting for anything and there is no command to be sent, return
83 if (!this->is_waiting_ && this->peek_next_command_() == EZO_PMP_COMMAND_NONE) {
84 return;
85 }
86
87 // If we are not waiting for anything and there IS a command to be sent, do it.
88 if (!this->is_waiting_ && this->peek_next_command_() != EZO_PMP_COMMAND_NONE) {
89 this->send_next_command_();
90 }
91
92 // If we are waiting for something but it isn't ready yet, then return
93 if (this->is_waiting_ && millis() - this->start_time_ < this->wait_time_) {
94 return;
95 }
96
97 // We are waiting for something and it should be ready.
99}
100
102 this->current_command_ = EZO_PMP_COMMAND_NONE;
103 this->is_waiting_ = false;
104}
105
107 uint8_t response_buffer[21] = {'\0'};
108
109 response_buffer[0] = 0;
110 if (!this->read_bytes_raw(response_buffer, 20)) {
111 ESP_LOGE(TAG, "read error");
113 return;
114 }
115
116 switch (response_buffer[0]) {
117 case 254:
118 return; // keep waiting
119 case 1:
120 break;
121 case 2:
122 ESP_LOGE(TAG, "device returned a syntax error");
124 return;
125 case 255:
126 ESP_LOGE(TAG, "device returned no data");
128 return;
129 default:
130 ESP_LOGE(TAG, "device returned an unknown response: %d", response_buffer[0]);
132 return;
133 }
134
135 char first_parameter_buffer[10] = {'\0'};
136 char second_parameter_buffer[10] = {'\0'};
137 char third_parameter_buffer[10] = {'\0'};
138
139 first_parameter_buffer[0] = '\0';
140 second_parameter_buffer[0] = '\0';
141 third_parameter_buffer[0] = '\0';
142
143 int current_parameter = 1;
144
145 size_t position_in_parameter_buffer = 0;
146 // some sensors return multiple comma-separated values, terminate string after first one
147 for (size_t i = 1; i < sizeof(response_buffer) - 1; i++) {
148 char current_char = response_buffer[i];
149
150 if (current_char == '\0') {
151 ESP_LOGV(TAG,
152 "Read Response from device: %s\n"
153 " First Component: %s\n"
154 " Second Component: %s\n"
155 " Third Component: %s",
156 (char *) response_buffer, (char *) first_parameter_buffer, (char *) second_parameter_buffer,
157 (char *) third_parameter_buffer);
158
159 break;
160 }
161
162 if (current_char == ',') {
163 current_parameter++;
164 position_in_parameter_buffer = 0;
165 continue;
166 }
167
168 if (position_in_parameter_buffer < sizeof(first_parameter_buffer) - 1) {
169 switch (current_parameter) {
170 case 1:
171 first_parameter_buffer[position_in_parameter_buffer] = current_char;
172 first_parameter_buffer[position_in_parameter_buffer + 1] = '\0';
173 break;
174 case 2:
175 second_parameter_buffer[position_in_parameter_buffer] = current_char;
176 second_parameter_buffer[position_in_parameter_buffer + 1] = '\0';
177 break;
178 case 3:
179 third_parameter_buffer[position_in_parameter_buffer] = current_char;
180 third_parameter_buffer[position_in_parameter_buffer + 1] = '\0';
181 break;
182 }
183 position_in_parameter_buffer++;
184 }
185 }
186
187 auto parsed_first_parameter = parse_number<float>(first_parameter_buffer);
188 auto parsed_second_parameter = parse_number<float>(second_parameter_buffer);
189 auto parsed_third_parameter = parse_number<float>(third_parameter_buffer);
190
191 switch (this->current_command_) {
192 // Read Commands
193 case EZO_PMP_COMMAND_READ_DOSING: // Page 54
194 if (parsed_third_parameter.has_value())
195 this->is_dosing_flag_ = parsed_third_parameter.value_or(0) == 1;
196
197 if (this->is_dosing_)
199
200 if (parsed_second_parameter.has_value() && this->last_volume_requested_) {
201 this->last_volume_requested_->publish_state(parsed_second_parameter.value_or(0));
202 }
203
204 if (!this->is_dosing_flag_ && !this->is_paused_flag_) {
205 // If pump is not paused and not dispensing
206 if (this->dosing_mode_ && this->dosing_mode_->state != DOSING_MODE_NONE)
207 this->dosing_mode_->publish_state(DOSING_MODE_NONE);
208 }
209
210 break;
211
212 case EZO_PMP_COMMAND_READ_SINGLE_REPORT: // Single Report (page 53)
213 if (parsed_first_parameter.has_value() && (bool) this->current_volume_dosed_) {
214 this->current_volume_dosed_->publish_state(parsed_first_parameter.value_or(0));
215 }
216 break;
217
218 case EZO_PMP_COMMAND_READ_MAX_FLOW_RATE: // Constant Flow Rate (page 57)
219 if (parsed_second_parameter.has_value() && this->max_flow_rate_)
220 this->max_flow_rate_->publish_state(parsed_second_parameter.value_or(0));
221 break;
222
223 case EZO_PMP_COMMAND_READ_PAUSE_STATUS: // Pause (page 61)
224 if (parsed_second_parameter.has_value())
225 this->is_paused_flag_ = parsed_second_parameter.value_or(0) == 1;
226
227 if (this->is_paused_)
229 break;
230
231 case EZO_PMP_COMMAND_READ_TOTAL_VOLUME_DOSED: // Total Volume Dispensed (page 64)
232 if (parsed_second_parameter.has_value() && this->total_volume_dosed_)
233 this->total_volume_dosed_->publish_state(parsed_second_parameter.value_or(0));
234 break;
235
236 case EZO_PMP_COMMAND_READ_ABSOLUTE_TOTAL_VOLUME_DOSED: // Total Volume Dispensed (page 64)
237 if (parsed_second_parameter.has_value() && this->absolute_total_volume_dosed_)
238 this->absolute_total_volume_dosed_->publish_state(parsed_second_parameter.value_or(0));
239 break;
240
241 case EZO_PMP_COMMAND_READ_CALIBRATION_STATUS: // Calibration (page 65)
242 if (parsed_second_parameter.has_value() && this->calibration_status_) {
243 if (parsed_second_parameter.value_or(0) == 1) {
244 this->calibration_status_->publish_state("Fixed Volume");
245 } else if (parsed_second_parameter.value_or(0) == 2) {
246 this->calibration_status_->publish_state("Volume/Time");
247 } else if (parsed_second_parameter.value_or(0) == 3) {
248 this->calibration_status_->publish_state("Fixed Volume & Volume/Time");
249 } else {
250 this->calibration_status_->publish_state("Uncalibrated");
251 }
252 }
253 break;
254
255 case EZO_PMP_COMMAND_READ_PUMP_VOLTAGE: // Pump Voltage (page 67)
256 if (parsed_second_parameter.has_value() && this->pump_voltage_)
257 this->pump_voltage_->publish_state(parsed_second_parameter.value_or(0));
258 break;
259
260 // Non-Read Commands
261
262 case EZO_PMP_COMMAND_DOSE_VOLUME: // Volume Dispensing (page 55)
263 if (this->dosing_mode_ && this->dosing_mode_->state != DOSING_MODE_VOLUME)
264 this->dosing_mode_->publish_state(DOSING_MODE_VOLUME);
265 break;
266
267 case EZO_PMP_COMMAND_DOSE_VOLUME_OVER_TIME: // Dose over time (page 56)
268 if (this->dosing_mode_ && this->dosing_mode_->state != DOSING_MODE_VOLUME_OVER_TIME)
269 this->dosing_mode_->publish_state(DOSING_MODE_VOLUME_OVER_TIME);
270 break;
271
272 case EZO_PMP_COMMAND_DOSE_WITH_CONSTANT_FLOW_RATE: // Constant Flow Rate (page 57)
273 if (this->dosing_mode_ && this->dosing_mode_->state != DOSING_MODE_CONSTANT_FLOW_RATE)
274 this->dosing_mode_->publish_state(DOSING_MODE_CONSTANT_FLOW_RATE);
275 break;
276
277 case EZO_PMP_COMMAND_DOSE_CONTINUOUSLY: // Continuous Dispensing (page 54)
278 if (this->dosing_mode_ && this->dosing_mode_->state != DOSING_MODE_CONTINUOUS)
279 this->dosing_mode_->publish_state(DOSING_MODE_CONTINUOUS);
280 break;
281
282 case EZO_PMP_COMMAND_STOP_DOSING: // Stop (page 62)
283 this->is_paused_flag_ = false;
284 if (this->is_paused_)
286 if (this->dosing_mode_ && this->dosing_mode_->state != DOSING_MODE_NONE)
287 this->dosing_mode_->publish_state(DOSING_MODE_NONE);
288 break;
289
290 case EZO_PMP_COMMAND_EXEC_ARBITRARY_COMMAND_ADDRESS:
291 ESP_LOGI(TAG, "Arbitrary Command Response: %s", (char *) response_buffer);
292 break;
293
294 case EZO_PMP_COMMAND_CLEAR_CALIBRATION: // Clear Calibration (page 65)
295 case EZO_PMP_COMMAND_PAUSE_DOSING: // Pause (page 61)
296 case EZO_PMP_COMMAND_SET_CALIBRATION_VOLUME: // Set Calibration Volume (page 65)
297 case EZO_PMP_COMMAND_CLEAR_TOTAL_VOLUME_DOSED: // Clear Total Volume Dosed (page 64)
298 case EZO_PMP_COMMAND_FIND: // Find (page 52)
299 // Nothing to do here
300 break;
301
302 case EZO_PMP_COMMAND_TYPE_READ:
303 case EZO_PMP_COMMAND_NONE:
304 default:
305 ESP_LOGE(TAG, "Unsupported command received: %d", this->current_command_);
306 return;
307 }
308
310}
311
313 int wait_time_for_command = 400; // milliseconds
314 uint8_t command_buffer[21];
315 int command_buffer_length = 0;
316
317 this->pop_next_command_(); // this->next_command will be updated.
318
319 switch (this->next_command_) {
320 // Read Commands
321 case EZO_PMP_COMMAND_READ_DOSING: // Page 54
322 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "D,?");
323 break;
324
325 case EZO_PMP_COMMAND_READ_SINGLE_REPORT: // Single Report (page 53)
326 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "R");
327 break;
328
329 case EZO_PMP_COMMAND_READ_MAX_FLOW_RATE:
330 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "DC,?");
331 break;
332
333 case EZO_PMP_COMMAND_READ_PAUSE_STATUS:
334 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "P,?");
335 break;
336
337 case EZO_PMP_COMMAND_READ_TOTAL_VOLUME_DOSED:
338 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "TV,?");
339 break;
340
341 case EZO_PMP_COMMAND_READ_ABSOLUTE_TOTAL_VOLUME_DOSED:
342 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "ATV,?");
343 break;
344
345 case EZO_PMP_COMMAND_READ_CALIBRATION_STATUS:
346 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "Cal,?");
347 break;
348
349 case EZO_PMP_COMMAND_READ_PUMP_VOLTAGE:
350 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "PV,?");
351 break;
352
353 // Non-Read Commands
354
355 case EZO_PMP_COMMAND_FIND: // Find (page 52)
356 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "Find");
357 wait_time_for_command = 60000; // This command will block all updates for a minute
358 break;
359
360 case EZO_PMP_COMMAND_DOSE_CONTINUOUSLY: // Continuous Dispensing (page 54)
361 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "D,*");
362 break;
363
364 case EZO_PMP_COMMAND_CLEAR_TOTAL_VOLUME_DOSED: // Clear Total Volume Dosed (page 64)
365 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "Clear");
366 break;
367
368 case EZO_PMP_COMMAND_CLEAR_CALIBRATION: // Clear Calibration (page 65)
369 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "Cal,clear");
370 break;
371
372 case EZO_PMP_COMMAND_PAUSE_DOSING: // Pause (page 61)
373 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "P");
374 break;
375
376 case EZO_PMP_COMMAND_STOP_DOSING: // Stop (page 62)
377 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "X");
378 break;
379
380 // Non-Read commands with parameters
381
382 case EZO_PMP_COMMAND_DOSE_VOLUME: // Volume Dispensing (page 55)
383 command_buffer_length =
384 snprintf((char *) command_buffer, sizeof(command_buffer), "D,%0.1f", this->next_command_volume_);
385 break;
386
387 case EZO_PMP_COMMAND_DOSE_VOLUME_OVER_TIME: // Dose over time (page 56)
388 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "D,%0.1f,%i",
390 break;
391
392 case EZO_PMP_COMMAND_DOSE_WITH_CONSTANT_FLOW_RATE: // Constant Flow Rate (page 57)
393 command_buffer_length = snprintf((char *) command_buffer, sizeof(command_buffer), "DC,%0.1f,%i",
395 break;
396
397 case EZO_PMP_COMMAND_SET_CALIBRATION_VOLUME: // Set Calibration Volume (page 65)
398 command_buffer_length =
399 snprintf((char *) command_buffer, sizeof(command_buffer), "Cal,%0.2f", this->next_command_volume_);
400 break;
401
402 case EZO_PMP_COMMAND_CHANGE_I2C_ADDRESS: // Change I2C Address (page 73)
403 command_buffer_length =
404 snprintf((char *) command_buffer, sizeof(command_buffer), "I2C,%i", this->next_command_duration_);
405 break;
406
407 case EZO_PMP_COMMAND_EXEC_ARBITRARY_COMMAND_ADDRESS: // Run an arbitrary command
408 command_buffer_length =
409 snprintf((char *) command_buffer, sizeof(command_buffer), "%s", this->arbitrary_command_.c_str());
410 ESP_LOGI(TAG, "Sending arbitrary command: %s", (char *) command_buffer);
411 break;
412
413 case EZO_PMP_COMMAND_TYPE_READ:
414 case EZO_PMP_COMMAND_NONE:
415 default:
416 ESP_LOGE(TAG, "Unsupported command received: %d", this->next_command_);
417 return;
418 }
419
420 // Send command
421 ESP_LOGV(TAG, "Sending command to device: %s", (char *) command_buffer);
422 this->write(command_buffer, command_buffer_length);
423
424 this->current_command_ = this->next_command_;
425 this->next_command_ = EZO_PMP_COMMAND_NONE;
426 this->is_waiting_ = true;
427 this->start_time_ = millis();
428 this->wait_time_ = wait_time_for_command;
429}
430
432 if (this->next_command_queue_length_ <= 0) {
433 ESP_LOGE(TAG, "Tried to dequeue command from empty queue");
434 this->next_command_ = EZO_PMP_COMMAND_NONE;
435 this->next_command_volume_ = 0;
436 this->next_command_duration_ = 0;
437 return;
438 }
439
440 // Read from Head
444
445 // Move positions
447 if (next_command_queue_head_ >= 10) {
449 }
450
452}
453
455 if (this->next_command_queue_length_ <= 0) {
456 return EZO_PMP_COMMAND_NONE;
457 }
458
460}
461
462void EzoPMP::queue_command_(uint16_t command, double volume, int duration, bool should_schedule) {
463 if (!should_schedule) {
464 return;
465 }
466
467 if (this->next_command_queue_length_ >= 10) {
468 ESP_LOGE(TAG, "Tried to queue command '%d' but queue is full", command);
469 return;
470 }
471
472 this->next_command_queue_[this->next_command_queue_last_] = command;
475
476 ESP_LOGV(TAG, "Queue command '%d' in position '%d'", command, next_command_queue_last_);
477
478 // Move positions
480 if (next_command_queue_last_ >= 10) {
482 }
483
485}
486
487// Actions
488
489void EzoPMP::find() { this->queue_command_(EZO_PMP_COMMAND_FIND, 0, 0, true); }
490
492 this->queue_command_(EZO_PMP_COMMAND_DOSE_CONTINUOUSLY, 0, 0, true);
493 this->queue_command_(EZO_PMP_COMMAND_READ_DOSING, 0, 0, true);
494 this->queue_command_(EZO_PMP_COMMAND_READ_SINGLE_REPORT, 0, 0, (bool) this->current_volume_dosed_);
495}
496
497void EzoPMP::dose_volume(double volume) {
498 this->queue_command_(EZO_PMP_COMMAND_DOSE_VOLUME, volume, 0, true);
499 this->queue_command_(EZO_PMP_COMMAND_READ_DOSING, 0, 0, true);
500 this->queue_command_(EZO_PMP_COMMAND_READ_SINGLE_REPORT, 0, 0, (bool) this->current_volume_dosed_);
501}
502
503void EzoPMP::dose_volume_over_time(double volume, int duration) {
504 this->queue_command_(EZO_PMP_COMMAND_DOSE_VOLUME_OVER_TIME, volume, duration, true);
505 this->queue_command_(EZO_PMP_COMMAND_READ_DOSING, 0, 0, true);
506 this->queue_command_(EZO_PMP_COMMAND_READ_SINGLE_REPORT, 0, 0, (bool) this->current_volume_dosed_);
507}
508
510 this->queue_command_(EZO_PMP_COMMAND_DOSE_WITH_CONSTANT_FLOW_RATE, volume, duration, true);
511 this->queue_command_(EZO_PMP_COMMAND_READ_DOSING, 0, 0, true);
512 this->queue_command_(EZO_PMP_COMMAND_READ_SINGLE_REPORT, 0, 0, (bool) this->current_volume_dosed_);
513}
514
516 this->queue_command_(EZO_PMP_COMMAND_SET_CALIBRATION_VOLUME, volume, 0, true);
517 this->queue_command_(EZO_PMP_COMMAND_READ_CALIBRATION_STATUS, 0, 0, true);
518 this->queue_command_(EZO_PMP_COMMAND_READ_MAX_FLOW_RATE, 0, 0, true);
519}
520
522 this->queue_command_(EZO_PMP_COMMAND_CLEAR_TOTAL_VOLUME_DOSED, 0, 0, true);
523 this->queue_command_(EZO_PMP_COMMAND_READ_SINGLE_REPORT, 0, 0, true);
524 this->queue_command_(EZO_PMP_COMMAND_READ_TOTAL_VOLUME_DOSED, 0, 0, true);
525 this->queue_command_(EZO_PMP_COMMAND_READ_ABSOLUTE_TOTAL_VOLUME_DOSED, 0, 0, true);
526}
527
529 this->queue_command_(EZO_PMP_COMMAND_CLEAR_CALIBRATION, 0, 0, true);
530 this->queue_command_(EZO_PMP_COMMAND_READ_CALIBRATION_STATUS, 0, 0, true);
531 this->queue_command_(EZO_PMP_COMMAND_READ_MAX_FLOW_RATE, 0, 0, true);
532}
533
535 this->queue_command_(EZO_PMP_COMMAND_PAUSE_DOSING, 0, 0, true);
536 this->queue_command_(EZO_PMP_COMMAND_READ_PAUSE_STATUS, 0, 0, true);
537}
538
539void EzoPMP::stop_dosing() { this->queue_command_(EZO_PMP_COMMAND_STOP_DOSING, 0, 0, true); }
540
542 this->queue_command_(EZO_PMP_COMMAND_CHANGE_I2C_ADDRESS, 0, address, true);
543}
544
545void EzoPMP::exec_arbitrary_command(const std::basic_string<char> &command) {
546 this->arbitrary_command_ = command;
547 this->queue_command_(EZO_PMP_COMMAND_EXEC_ARBITRARY_COMMAND_ADDRESS, 0, 0, true);
548}
549
550} // namespace ezo_pmp
551} // namespace esphome
uint8_t address
Definition bl0906.h:4
bool is_failed() const
Definition component.h:233
void publish_state(bool new_state)
Publish a new state to the front-end.
sensor::Sensor * total_volume_dosed_
Definition ezo_pmp.h:99
void exec_arbitrary_command(const std::basic_string< char > &command)
Definition ezo_pmp.cpp:545
void dose_volume(double volume)
Definition ezo_pmp.cpp:497
uint16_t current_command_
Definition ezo_pmp.h:84
binary_sensor::BinarySensor * is_paused_
Definition ezo_pmp.h:108
int next_command_duration_queue_[10]
Definition ezo_pmp.h:79
sensor::Sensor * max_flow_rate_
Definition ezo_pmp.h:102
uint16_t next_command_queue_[10]
Definition ezo_pmp.h:77
std::string arbitrary_command_
Definition ezo_pmp.h:88
void dump_config() override
Definition ezo_pmp.cpp:41
double next_command_volume_queue_[10]
Definition ezo_pmp.h:78
void set_calibration_volume(double volume)
Definition ezo_pmp.cpp:515
void change_i2c_address(int address)
Definition ezo_pmp.cpp:541
void queue_command_(uint16_t command, double volume, int duration, bool should_schedule)
Definition ezo_pmp.cpp:462
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 dose_volume_over_time(double volume, int duration)
Definition ezo_pmp.cpp:503
uint16_t peek_next_command_()
Definition ezo_pmp.cpp:454
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:509
void update() override
Definition ezo_pmp.cpp:49
text_sensor::TextSensor * calibration_status_
Definition ezo_pmp.h:113
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
Definition i2c.h:183
optional< std::array< uint8_t, N > > read_bytes_raw()
Definition i2c.h:230
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:65
void publish_state(const std::string &state)
uint8_t duration
Definition msa3xx.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.
Definition helpers.h:1007
uint32_t IRAM_ATTR HOT millis()
Definition core.cpp:26