ESPHome  2024.10.2
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 
33  // overrides for MLX library
34 
35  // disable lint because it keeps suggesting const uint8_t *response.
36  // this->read() writes data into response, so it can't be const
37  bool transceive(const uint8_t *request, size_t request_size, uint8_t *response,
38  size_t response_size) override; // NOLINT
39  bool has_drdy_pin() override;
40  bool read_drdy_pin() override;
41  void sleep_millis(uint32_t millis) override;
42  void sleep_micros(uint32_t micros) override;
43 
44  protected:
45  MLX90393 mlx_;
50  uint8_t gain_;
51  uint8_t oversampling_;
53  uint8_t filter_;
54  uint8_t resolutions_[3] = {0};
55  GPIOPin *drdy_pin_{nullptr};
56 };
57 
58 } // namespace mlx90393
59 } // namespace esphome
void set_y_sensor(sensor::Sensor *y_sensor)
void set_gain(uint8_t gain_sel)
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_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