8 static const char *
const EZO_COMMAND_TYPE_STRINGS[] = {
"EZO_READ",
"EZO_LED",
"EZO_DEVICE_INFORMATION",
9 "EZO_SLOPE",
"EZO_CALIBRATION",
"EZO_SLEEP",
10 "EZO_I2C",
"EZO_T",
"EZO_CUSTOM"};
12 static const char *
const EZO_CALIBRATION_TYPE_STRINGS[] = {
"LOW",
"MID",
"HIGH"};
15 LOG_SENSOR(
"",
"EZO",
this);
18 ESP_LOGE(TAG,
"Communication with EZO circuit failed!");
20 LOG_UPDATE_INTERVAL(
this);
38 std::unique_ptr<EzoCommand> ezo_command(
new EzoCommand);
39 ezo_command->command =
"R";
41 ezo_command->delay_ms = 900;
43 auto it = this->commands_.begin();
45 this->commands_.insert(it, std::move(ezo_command));
62 const uint8_t *data =
reinterpret_cast<const uint8_t *
>(to_run->
command.c_str());
63 ESP_LOGVV(TAG,
"Sending command \"%s\"", data);
80 if (
millis() - this->start_time_ < to_run->delay_ms)
88 ESP_LOGE(TAG,
"read error");
97 ESP_LOGE(TAG,
"device returned a syntax error");
102 ESP_LOGE(TAG,
"device returned no data");
105 ESP_LOGE(TAG,
"device returned an unknown response: %d", buf[0]);
109 ESP_LOGV(TAG,
"Received buffer \"%s\" for command type %s", &buf[1], EZO_COMMAND_TYPE_STRINGS[to_run->
command_type]);
112 std::string payload =
reinterpret_cast<char *
>(&buf[1]);
113 if (!payload.empty()) {
117 int start_location = 0;
118 if ((start_location = payload.find(
',')) != std::string::npos) {
119 payload.erase(start_location);
121 auto val = parse_number<float>(payload);
122 if (!
val.has_value()) {
123 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
134 int start_location = 0;
135 if ((start_location = payload.find(
',')) != std::string::npos) {
141 int start_location = 0;
142 if ((start_location = payload.find(
',')) != std::string::npos) {
148 int start_location = 0;
149 if ((start_location = payload.find(
',')) != std::string::npos) {
155 int start_location = 0;
156 if ((start_location = payload.find(
',')) != std::string::npos) {
157 this->
t_callback_.call(payload.substr(start_location + 1));
176 std::unique_ptr<EzoCommand> ezo_command(
new EzoCommand);
177 ezo_command->command = command;
178 ezo_command->command_type = command_type;
179 ezo_command->delay_ms = delay_ms;
180 this->
commands_.push_back(std::move(ezo_command));
184 std::string payload =
str_sprintf(
"Cal,%s,%0.2f", EZO_CALIBRATION_TYPE_STRINGS[type], value);
189 if (address > 0 && address < 128) {
190 std::string payload =
str_sprintf(
"I2C,%u", address);
194 ESP_LOGE(TAG,
"Invalid I2C address");
209 std::string payload =
str_sprintf(
"T,%0.2f", value);
230 std::string payload =
str_sprintf(
"Cal,%0.2f", value);
239 std::string to_send =
"L,";
240 to_send += on ?
"1" :
"0";
void set_calibration_generic(float value)
void get_device_information()
void set_address(uint8_t address)
EzoCommandType command_type
void set_calibration_point_low(float value)
optional< std::array< uint8_t, N > > read_bytes_raw()
void send_custom(const std::string &to_send)
void set_calibration_point_(EzoCalibrationType type, float value)
CallbackManager< void(std::string)> device_infomation_callback_
uint32_t IRAM_ATTR HOT millis()
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
CallbackManager< void(std::string)> slope_callback_
void set_calibration_point_high(float value)
std::string str_sprintf(const char *fmt,...)
CallbackManager< void(std::string)> t_callback_
void publish_state(float state)
Publish a new state to the front-end.
void set_calibration_point_mid(float value)
void set_tempcomp_value(float temp)
CallbackManager< void(std::string)> custom_callback_
uint8_t address_
store the address of the device on the bus
void add_command_(const std::string &command, EzoCommandType command_type, uint16_t delay_ms=300)
CallbackManager< void(std::string)> calibration_callback_
Implementation of SPI Controller mode.
void dump_config() override
void set_led_state(bool on)
std::deque< std::unique_ptr< EzoCommand > > commands_
CallbackManager< void(bool)> led_callback_