ESPHome  2022.6.3
ltr390.h
Go to the documentation of this file.
1 #pragma once
2 
7 #include <tuple>
8 
9 namespace esphome {
10 namespace ltr390 {
11 
12 enum LTR390CTRL {
16 };
17 
18 // enums from https://github.com/adafruit/Adafruit_LTR390/
19 
20 static const uint8_t LTR390_MAIN_CTRL = 0x00;
21 static const uint8_t LTR390_MEAS_RATE = 0x04;
22 static const uint8_t LTR390_GAIN = 0x05;
23 static const uint8_t LTR390_PART_ID = 0x06;
24 static const uint8_t LTR390_MAIN_STATUS = 0x07;
25 static const float LTR390_SENSITIVITY = 2300.0;
26 
27 // Sensing modes
28 enum LTR390MODE {
31 };
32 
33 // Sensor gain levels
34 enum LTR390GAIN {
36  LTR390_GAIN_3, // Default
40 };
41 
42 // Sensor resolution
50 };
51 
53  public:
54  float get_setup_priority() const override { return setup_priority::DATA; }
55  void setup() override;
56  void dump_config() override;
57  void update() override;
58 
59  void set_gain_value(LTR390GAIN gain) { this->gain_ = gain; }
60  void set_res_value(LTR390RESOLUTION res) { this->res_ = res; }
61  void set_wfac_value(float wfac) { this->wfac_ = wfac; }
62 
63  void set_light_sensor(sensor::Sensor *light_sensor) { this->light_sensor_ = light_sensor; }
64  void set_als_sensor(sensor::Sensor *als_sensor) { this->als_sensor_ = als_sensor; }
65  void set_uvi_sensor(sensor::Sensor *uvi_sensor) { this->uvi_sensor_ = uvi_sensor; }
66  void set_uv_sensor(sensor::Sensor *uv_sensor) { this->uv_sensor_ = uv_sensor; }
67 
68  protected:
70 
71  void read_als_();
72  void read_uvs_();
73 
74  void read_mode_(int mode_index);
75 
76  bool reading_;
77 
78  // a list of modes and corresponding read functions
79  std::vector<std::tuple<LTR390MODE, std::function<void()>>> mode_funcs_;
80 
83  float wfac_;
84 
87 
90 };
91 
92 } // namespace ltr390
93 } // namespace esphome
void read_mode_(int mode_index)
Definition: ltr390.cpp:85
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:18
void set_als_sensor(sensor::Sensor *als_sensor)
Definition: ltr390.h:64
BedjetMode mode
BedJet operating mode.
Definition: bedjet_base.h:102
void set_res_value(LTR390RESOLUTION res)
Definition: ltr390.h:60
float get_setup_priority() const override
Definition: ltr390.h:54
void set_uvi_sensor(sensor::Sensor *uvi_sensor)
Definition: ltr390.h:65
This class simplifies creating components that periodically check a state.
Definition: component.h:266
optional< uint32_t > read_sensor_data_(LTR390MODE mode)
Definition: ltr390.cpp:26
void set_gain_value(LTR390GAIN gain)
Definition: ltr390.h:59
sensor::Sensor * uv_sensor_
Definition: ltr390.h:89
void set_wfac_value(float wfac)
Definition: ltr390.h:61
sensor::Sensor * light_sensor_
Definition: ltr390.h:85
void set_light_sensor(sensor::Sensor *light_sensor)
Definition: ltr390.h:63
LTR390RESOLUTION res_
Definition: ltr390.h:82
void set_uv_sensor(sensor::Sensor *uv_sensor)
Definition: ltr390.h:66
std::vector< std::tuple< LTR390MODE, std::function< void()> > > mode_funcs_
Definition: ltr390.h:79
Definition: a4988.cpp:4
sensor::Sensor * uvi_sensor_
Definition: ltr390.h:88
Base-class for all sensors.
Definition: sensor.h:47
sensor::Sensor * als_sensor_
Definition: ltr390.h:86