ESPHome  2025.3.3
sensor_mlx90393.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include "esphome/core/hal.h"
7 #include <MLX90393.h>
8 #include <MLX90393Hal.h>
9 
10 namespace esphome {
11 namespace mlx90393 {
12 
13 class MLX90393Cls : public PollingComponent, public i2c::I2CDevice, public MLX90393Hal {
14  public:
15  void setup() override;
16  void dump_config() override;
17  float get_setup_priority() const override;
18  void update() override;
19 
20  void set_drdy_gpio(GPIOPin *pin) { drdy_pin_ = pin; }
21 
22  void set_x_sensor(sensor::Sensor *x_sensor) { x_sensor_ = x_sensor; }
23  void set_y_sensor(sensor::Sensor *y_sensor) { y_sensor_ = y_sensor; }
24  void set_z_sensor(sensor::Sensor *z_sensor) { z_sensor_ = z_sensor; }
25  void set_t_sensor(sensor::Sensor *t_sensor) { t_sensor_ = t_sensor; }
26 
27  void set_oversampling(uint8_t osr) { oversampling_ = osr; }
28  void set_t_oversampling(uint8_t osr2) { temperature_oversampling_ = osr2; }
29  void set_resolution(uint8_t xyz, uint8_t res) { resolutions_[xyz] = res; }
30  void set_filter(uint8_t filter) { filter_ = filter; }
31  void set_gain(uint8_t gain_sel) { gain_ = gain_sel; }
32  void set_temperature_compensation(bool temperature_compensation) {
33  temperature_compensation_ = temperature_compensation;
34  }
35  void set_hallconf(uint8_t hallconf) { hallconf_ = hallconf; }
36  // overrides for MLX library
37 
38  // disable lint because it keeps suggesting const uint8_t *response.
39  // this->read() writes data into response, so it can't be const
40  bool transceive(const uint8_t *request, size_t request_size, uint8_t *response,
41  size_t response_size) override; // NOLINT
42  bool has_drdy_pin() override;
43  bool read_drdy_pin() override;
44  void sleep_millis(uint32_t millis) override;
45  void sleep_micros(uint32_t micros) override;
46 
47  protected:
48  MLX90393 mlx_;
53  uint8_t gain_;
54  uint8_t oversampling_;
56  uint8_t filter_;
57  uint8_t resolutions_[3]{0};
59  uint8_t hallconf_{0xC};
60  GPIOPin *drdy_pin_{nullptr};
61 };
62 
63 } // namespace mlx90393
64 } // namespace esphome
void set_y_sensor(sensor::Sensor *y_sensor)
void set_gain(uint8_t gain_sel)
void set_hallconf(uint8_t hallconf)
void set_drdy_gpio(GPIOPin *pin)
This class simplifies creating components that periodically check a state.
Definition: component.h:283
uint32_t IRAM_ATTR HOT micros()
Definition: core.cpp:27
void sleep_millis(uint32_t millis) override
uint32_t IRAM_ATTR HOT millis()
Definition: core.cpp:25
void set_t_oversampling(uint8_t osr2)
float get_setup_priority() const override
void sleep_micros(uint32_t micros) override
bool transceive(const uint8_t *request, size_t request_size, uint8_t *response, size_t response_size) override
void set_t_sensor(sensor::Sensor *t_sensor)
void set_temperature_compensation(bool temperature_compensation)
void set_x_sensor(sensor::Sensor *x_sensor)
void set_resolution(uint8_t xyz, uint8_t res)
void set_oversampling(uint8_t osr)
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_filter(uint8_t filter)
Base-class for all sensors.
Definition: sensor.h:57
void set_z_sensor(sensor::Sensor *z_sensor)
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133