7static const char *
const TAG =
"mlx90393";
12 return LOG_STR(
"gain");
14 return LOG_STR(
"resolution");
16 return LOG_STR(
"oversampling");
18 return LOG_STR(
"digital filtering");
20 return LOG_STR(
"temperature oversampling");
22 return LOG_STR(
"temperature compensation");
24 return LOG_STR(
"hallconf");
26 return LOG_STR(
"error");
28 return LOG_STR(
"unknown");
35 ESP_LOGV(TAG,
"i2c failed to write %u", e);
38 e = this->
read(response, response_size);
40 ESP_LOGV(TAG,
"i2c failed to read %u", e);
71 ret = this->
mlx_.setDigitalFiltering(this->
filter_);
85 if (ret != MLX90393::STATUS_OK) {
95 this->
mlx_.getGainSel(ignore);
97 uint8_t result = MLX90393::STATUS_OK;
102 return result == MLX90393::STATUS_OK;
106 ESP_LOGCONFIG(TAG,
"Setting up MLX90393...");
110 this->
mlx_.begin_with_hal(
this, 0, 0);
121 ESP_LOGCONFIG(TAG,
"MLX90393:");
122 LOG_I2C_DEVICE(
this);
125 ESP_LOGE(TAG,
"Communication with MLX90393 failed!");
128 LOG_UPDATE_INTERVAL(
this);
130 LOG_SENSOR(
" ",
"X Axis", this->
x_sensor_);
131 LOG_SENSOR(
" ",
"Y Axis", this->
y_sensor_);
132 LOG_SENSOR(
" ",
"Z Axis", this->
z_sensor_);
133 LOG_SENSOR(
" ",
"Temperature", this->
t_sensor_);
141 if (this->
mlx_.readData(data) == MLX90393::STATUS_OK) {
142 ESP_LOGD(TAG,
"received %f %f %f", data.x, data.y, data.z);
157 ESP_LOGE(TAG,
"failed to read data");
163 uint8_t read_value = 0xFF;
164 uint8_t expected_value = 0xFF;
165 uint8_t read_status = -1;
166 char read_back_str[25] = {0};
170 read_status = this->
mlx_.getGainSel(read_value);
171 expected_value = this->
gain_;
176 uint8_t read_resolutions[3] = {0xFF};
177 read_status = this->
mlx_.getResolution(read_resolutions[0], read_resolutions[1], read_resolutions[2]);
178 snprintf(read_back_str,
sizeof(read_back_str),
"%u %u %u expected %u %u %u", read_resolutions[0],
181 bool is_correct =
true;
182 for (
int i = 0; i < 3; i++) {
183 is_correct &= read_resolutions[i] == this->
resolutions_[i];
197 read_status = this->
mlx_.getOverSampling(read_value);
202 read_status = this->
mlx_.getDigitalFiltering(read_value);
203 expected_value = this->
filter_;
207 read_status = this->
mlx_.getTemperatureOverSampling(read_value);
212 read_status = this->
mlx_.getTemperatureCompensation(read_value);
217 read_status = this->
mlx_.getHallConf(read_value);
225 if (read_status != MLX90393::STATUS_OK) {
226 ESP_LOGE(TAG,
"verify error: failed to read %s", LOG_STR_ARG(
settings_to_string(which)));
229 if (read_back_str[0] == 0x0) {
230 snprintf(read_back_str,
sizeof(read_back_str),
"%u expected %u", read_value, expected_value);
232 bool is_correct = read_value == expected_value;
234 ESP_LOGW(TAG,
"verify failed: read back wrong %s: got %s", LOG_STR_ARG(
settings_to_string(which)), read_back_str);
237 ESP_LOGD(TAG,
"verify succeeded for %s. got %s", LOG_STR_ARG(
settings_to_string(which)), read_back_str);
251 if (!is_setting_ok) {
252 if (this->
mlx_.checkStatus(this->mlx_.reset()) != MLX90393::STATUS_OK) {
253 ESP_LOGE(TAG,
"failed to reset device");
260 ESP_LOGE(TAG,
"failed to re-apply settings");
264 ESP_LOGI(TAG,
"reset and re-apply settings completed");
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message="unspecified")
void status_set_error(const char *message="unspecified")
void status_clear_warning()
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
virtual bool digital_read()=0
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
void sleep_micros(uint32_t micros) override
sensor::Sensor * x_sensor_
uint8_t temperature_oversampling_
void sleep_millis(uint32_t millis) override
sensor::Sensor * z_sensor_
sensor::Sensor * t_sensor_
bool read_drdy_pin() override
bool apply_all_settings_()
void verify_settings_timeout_(MLX90393Setting stage)
Regularly checks that our settings are still applied.
void dump_config() override
float get_setup_priority() const override
bool verify_setting_(MLX90393Setting which)
sensor::Sensor * y_sensor_
bool transceive(const uint8_t *request, size_t request_size, uint8_t *response, size_t response_size) override
bool has_drdy_pin() override
bool temperature_compensation_
uint8_t apply_setting_(MLX90393Setting which)
void publish_state(float state)
Publish a new state to the front-end.
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
@ ERROR_OK
No error found during execution of method.
@ MLX90393_TEMPERATURE_OVER_SAMPLING
@ MLX90393_DIGITAL_FILTERING
@ MLX90393_TEMPERATURE_COMPENSATION
const LogString * settings_to_string(MLX90393Setting setting)
const float DATA
For components that import data from directly connected sensors like DHT.
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
uint32_t IRAM_ATTR HOT micros()
void IRAM_ATTR HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()