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