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;
 
 
  109  this->
mlx_.begin_with_hal(
this, 0, 0);
 
 
  120  ESP_LOGCONFIG(TAG, 
"MLX90393:");
 
  121  LOG_I2C_DEVICE(
this);
 
  124    ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
 
  127  LOG_UPDATE_INTERVAL(
this);
 
  129  LOG_SENSOR(
"  ", 
"X Axis", this->
x_sensor_);
 
  130  LOG_SENSOR(
"  ", 
"Y Axis", this->
y_sensor_);
 
  131  LOG_SENSOR(
"  ", 
"Z Axis", this->
z_sensor_);
 
  132  LOG_SENSOR(
"  ", 
"Temperature", this->
t_sensor_);
 
 
  140  if (this->
mlx_.readData(data) == MLX90393::STATUS_OK) {
 
  141    ESP_LOGD(TAG, 
"received %f %f %f", 
data.x, 
data.y, 
data.z);
 
  156    ESP_LOGE(TAG, 
"failed to read data");
 
 
  162  uint8_t read_value = 0xFF;
 
  163  uint8_t expected_value = 0xFF;
 
  164  uint8_t read_status = -1;
 
  165  char read_back_str[25] = {0};
 
  169      read_status = this->
mlx_.getGainSel(read_value);
 
  170      expected_value = this->
gain_;
 
  175      uint8_t read_resolutions[3] = {0xFF};
 
  176      read_status = this->
mlx_.getResolution(read_resolutions[0], read_resolutions[1], read_resolutions[2]);
 
  177      snprintf(read_back_str, 
sizeof(read_back_str), 
"%u %u %u expected %u %u %u", read_resolutions[0],
 
  180      bool is_correct = 
true;
 
  181      for (
int i = 0; i < 3; i++) {
 
  182        is_correct &= read_resolutions[i] == this->
resolutions_[i];
 
  196      read_status = this->
mlx_.getOverSampling(read_value);
 
  201      read_status = this->
mlx_.getDigitalFiltering(read_value);
 
  202      expected_value = this->
filter_;
 
  206      read_status = this->
mlx_.getTemperatureOverSampling(read_value);
 
  211      read_status = this->
mlx_.getTemperatureCompensation(read_value);
 
  216      read_status = this->
mlx_.getHallConf(read_value);
 
  224  if (read_status != MLX90393::STATUS_OK) {
 
  225    ESP_LOGE(TAG, 
"verify error: failed to read %s", LOG_STR_ARG(
settings_to_string(which)));
 
  228  if (read_back_str[0] == 0x0) {
 
  229    snprintf(read_back_str, 
sizeof(read_back_str), 
"%u expected %u", read_value, expected_value);
 
  231  bool is_correct = read_value == expected_value;
 
  233    ESP_LOGW(TAG, 
"verify failed: read back wrong %s: got %s", LOG_STR_ARG(
settings_to_string(which)), read_back_str);
 
  236  ESP_LOGD(TAG, 
"verify succeeded for %s. got %s", LOG_STR_ARG(
settings_to_string(which)), read_back_str);
 
 
  250  if (!is_setting_ok) {
 
  251    if (this->
mlx_.checkStatus(this->mlx_.reset()) != MLX90393::STATUS_OK) {
 
  252      ESP_LOGE(TAG, 
"failed to reset device");
 
  259      ESP_LOGE(TAG, 
"failed to re-apply settings");
 
  263      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=nullptr)
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.
void status_set_error(const char *message=nullptr)
virtual bool digital_read()=0
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
ErrorCode read(uint8_t *data, size_t len) const
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()