8 static const char *
const TAG =
"ezo.sensor";
10 static const uint16_t EZO_STATE_WAIT = 1;
11 static const uint16_t EZO_STATE_SEND_TEMP = 2;
12 static const uint16_t EZO_STATE_WAIT_TEMP = 4;
15 LOG_SENSOR(
"",
"EZO",
this);
18 ESP_LOGE(TAG,
"Communication with EZO circuit failed!");
19 LOG_UPDATE_INTERVAL(
this);
23 if (this->
state_ & EZO_STATE_WAIT) {
24 ESP_LOGE(TAG,
"update overrun, still waiting for previous response");
29 this->
state_ |= EZO_STATE_WAIT;
36 if (!(this->
state_ & EZO_STATE_WAIT)) {
37 if (this->
state_ & EZO_STATE_SEND_TEMP) {
38 int len = sprintf((
char *) buf,
"T,%0.3f", this->
tempcomp_);
39 this->
write(buf, len);
40 this->
state_ = EZO_STATE_WAIT | EZO_STATE_WAIT_TEMP;
50 ESP_LOGE(TAG,
"read error");
58 ESP_LOGE(TAG,
"device returned a syntax error");
63 ESP_LOGE(TAG,
"device returned no data");
66 ESP_LOGE(TAG,
"device returned an unknown response: %d", buf[0]);
69 if (this->
state_ & EZO_STATE_WAIT_TEMP) {
73 this->
state_ &= ~EZO_STATE_WAIT;
78 for (
size_t i = 1; i <
sizeof(buf) - 1; i++) {
83 float val = parse_number<float>((
char *) &buf[1]).value_or(0);
89 this->
state_ |= EZO_STATE_SEND_TEMP;
optional< std::array< uint8_t, N > > read_bytes_raw()
uint32_t IRAM_ATTR HOT millis()
void publish_state(float state)
Publish a new state to the front-end.
ErrorCode write(const uint8_t *data, uint8_t len, bool stop=true)
void set_tempcomp_value(float temp)
void dump_config() override