7static const char *
const EZO_COMMAND_TYPE_STRINGS[] = {
"EZO_READ",
"EZO_LED",
"EZO_DEVICE_INFORMATION",
8 "EZO_SLOPE",
"EZO_CALIBRATION",
"EZO_SLEEP",
9 "EZO_I2C",
"EZO_T",
"EZO_CUSTOM"};
11static const char *
const EZO_CALIBRATION_TYPE_STRINGS[] = {
"LOW",
"MID",
"HIGH"};
14 LOG_SENSOR(
"",
"EZO",
this);
16 LOG_UPDATE_INTERVAL(
this);
23 this->commands_.size() > 1) {
34 auto ezo_command = make_unique<EzoCommand>();
35 ezo_command->command =
"R";
37 ezo_command->delay_ms = 900;
39 auto it = this->commands_.begin();
41 this->commands_.insert(it, std::move(ezo_command));
58 const uint8_t *data =
reinterpret_cast<const uint8_t *
>(to_run->
command.c_str());
59 ESP_LOGVV(TAG,
"Sending command \"%s\"", data);
85 ESP_LOGE(TAG,
"read error");
94 ESP_LOGE(TAG,
"device returned a syntax error");
99 ESP_LOGE(TAG,
"device returned no data");
102 ESP_LOGE(TAG,
"device returned an unknown response: %d", buf[0]);
106 ESP_LOGV(TAG,
"Received buffer \"%s\" for command type %s", &buf[1], EZO_COMMAND_TYPE_STRINGS[to_run->
command_type]);
109 std::string payload =
reinterpret_cast<char *
>(&buf[1]);
110 if (!payload.empty()) {
111 auto start_location = payload.find(
',');
115 if (start_location != std::string::npos) {
116 payload.erase(start_location);
119 if (!
val.has_value()) {
120 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
130 if (start_location != std::string::npos) {
135 if (start_location != std::string::npos) {
140 if (start_location != std::string::npos) {
145 if (start_location != std::string::npos) {
146 this->
t_callback_.call(payload.substr(start_location + 1));
161 auto ezo_command = make_unique<EzoCommand>();
162 ezo_command->command = command;
163 ezo_command->command_type = command_type;
164 ezo_command->delay_ms = delay_ms;
165 this->
commands_.push_back(std::move(ezo_command));
171 snprintf(payload,
sizeof(payload),
"Cal,%s,%0.2f", EZO_CALIBRATION_TYPE_STRINGS[
type], value);
179 snprintf(payload,
sizeof(payload),
"I2C,%u",
address);
183 ESP_LOGE(TAG,
"Invalid I2C address");
200 snprintf(payload,
sizeof(payload),
"T,%0.2f", value);
223 snprintf(payload,
sizeof(payload),
"Cal,%0.2f", value);
void set_led_state(bool on)
void set_address(uint8_t address)
CallbackManager< void(std::string)> calibration_callback_
void set_calibration_point_mid(float value)
void set_calibration_point_high(float value)
void set_calibration_point_low(float value)
CallbackManager< void(bool)> led_callback_
void set_calibration_generic(float value)
void set_tempcomp_value(float temp)
void get_device_information()
CallbackManager< void(std::string)> device_infomation_callback_
CallbackManager< void(std::string)> t_callback_
void set_calibration_point_(EzoCalibrationType type, float value)
CallbackManager< void(std::string)> slope_callback_
std::deque< std::unique_ptr< EzoCommand > > commands_
void send_custom(const std::string &to_send)
CallbackManager< void(std::string)> custom_callback_
void add_command_(const char *command, EzoCommandType command_type, uint16_t delay_ms=300)
void dump_config() override
EzoCommandType command_type
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
optional< std::array< uint8_t, N > > read_bytes_raw()
uint8_t address_
store the address of the device on the bus
void publish_state(float state)
Publish a new state to the front-end.
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.
uint32_t IRAM_ATTR HOT millis()