ESPHome  2022.9.2
tsl2591.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace tsl2591 {
9 
22 };
23 
35 };
36 
43  TSL2591_GAIN_LOW = 0b00 << 4, // 1x
44  TSL2591_GAIN_MED = 0b01 << 4, // 25x
45  TSL2591_GAIN_HIGH = 0b10 << 4, // 400x
46  TSL2591_GAIN_MAX = 0b11 << 4, // 9500x
47 };
48 
57 };
58 
66  public:
99 
113  void set_power_save_mode(bool enable);
114 
119  void set_name(const char *name);
120 
143  void set_device_and_glass_attenuation_factors(float device_factor, float glass_attenuation_factor);
144 
150  float get_calculated_lux(uint16_t full_spectrum, uint16_t infrared);
151 
160  uint32_t get_combined_illuminance();
161 
175  uint16_t get_illuminance(TSL2591SensorChannel channel);
176 
187  uint16_t get_illuminance(TSL2591SensorChannel channel, uint32_t combined_illuminance);
188 
200  bool is_adc_valid();
201 
207  void enable();
214  void disable();
215 
221  void automatic_gain_update(uint16_t full_spectrum);
222 
223  // ========== INTERNAL METHODS ==========
224  // (In most use cases you won't need these. They're for ESPHome integration use.)
226  void set_full_spectrum_sensor(sensor::Sensor *full_spectrum_sensor);
228  void set_infrared_sensor(sensor::Sensor *infrared_sensor);
230  void set_visible_sensor(sensor::Sensor *visible_sensor);
232  void set_calculated_lux_sensor(sensor::Sensor *calculated_lux_sensor);
234  void set_integration_time(TSL2591IntegrationTime integration_time);
236  void set_gain(TSL2591ComponentGain gain);
238  void setup() override;
240  void dump_config() override;
242  void update() override;
244  float get_setup_priority() const override;
245 
246  protected:
247  const char *name_;
258  uint64_t interval_start_;
261  void process_update_();
263 };
264 
265 } // namespace tsl2591
266 } // namespace esphome
void dump_config() override
Used by ESPHome framework.
Definition: tsl2591.cpp:87
const char * name
Definition: stm32flash.h:78
sensor::Sensor * visible_sensor_
Definition: tsl2591.h:250
void set_full_spectrum_sensor(sensor::Sensor *full_spectrum_sensor)
Used by ESPHome framework.
Definition: tsl2591.cpp:202
sensor::Sensor * calculated_lux_sensor_
Definition: tsl2591.h:251
uint16_t get_illuminance(TSL2591SensorChannel channel)
Get an individual sensor channel reading.
Definition: tsl2591.cpp:310
void set_name(const char *name)
Sets the name for this instance of the device.
Definition: tsl2591.cpp:240
void set_calculated_lux_sensor(sensor::Sensor *calculated_lux_sensor)
Used by ESPHome framework.
Definition: tsl2591.cpp:206
TSL2591IntegrationTime
Enum listing all conversion/integration time settings for the TSL2591.
Definition: tsl2591.h:15
This class simplifies creating components that periodically check a state.
Definition: component.h:266
This class includes support for the TSL2591 i2c ambient light sensor.
Definition: tsl2591.h:65
sensor::Sensor * infrared_sensor_
Definition: tsl2591.h:249
void update() override
Used by ESPHome framework.
Definition: tsl2591.cpp:179
TSL2591ComponentGain component_gain_
Definition: tsl2591.h:253
void set_power_save_mode(bool enable)
Should the device be powered down between readings?
Definition: tsl2591.cpp:238
void set_integration_time_and_gain(TSL2591IntegrationTime integration_time, TSL2591Gain gain)
Set device integration time and gain.
Definition: tsl2591.cpp:221
void set_integration_time(TSL2591IntegrationTime integration_time)
Used by ESPHome framework.
Definition: tsl2591.cpp:210
void setup() override
Used by ESPHome framework.
Definition: tsl2591.cpp:45
void set_infrared_sensor(sensor::Sensor *infrared_sensor)
Used by ESPHome framework.
Definition: tsl2591.cpp:196
sensor::Sensor * full_spectrum_sensor_
Definition: tsl2591.h:248
TSL2591ComponentGain
Enum listing all gain settings for the TSL2591 component.
Definition: tsl2591.h:29
void enable()
Powers on the TSL2591 device and enables its sensors.
Definition: tsl2591.cpp:26
TSL2591Gain
Enum listing all gain settings for the TSL2591.
Definition: tsl2591.h:42
TSL2591IntegrationTime integration_time_
Definition: tsl2591.h:252
TSL2591SensorChannel
Enum listing sensor channels.
Definition: tsl2591.h:53
void set_gain(TSL2591ComponentGain gain)
Used by ESPHome framework.
Definition: tsl2591.cpp:214
void disable()
Powers off the TSL2591 device.
Definition: tsl2591.cpp:33
Definition: a4988.cpp:4
bool is_adc_valid()
Are the device ADC values valid?
Definition: tsl2591.cpp:244
float get_setup_priority() const override
Used by ESPHome framework.
Definition: tsl2591.cpp:242
Base-class for all sensors.
Definition: sensor.h:48
void automatic_gain_update(uint16_t full_spectrum)
Updates the gain setting based on the most recent full spectrum reading.
Definition: tsl2591.cpp:410
void set_visible_sensor(sensor::Sensor *visible_sensor)
Used by ESPHome framework.
Definition: tsl2591.cpp:200
void set_device_and_glass_attenuation_factors(float device_factor, float glass_attenuation_factor)
Sets the device and glass attenuation factors.
Definition: tsl2591.cpp:216
float get_calculated_lux(uint16_t full_spectrum, uint16_t infrared)
Calculates and returns a lux value based on the ADC readings.
Definition: tsl2591.cpp:345
uint32_t get_combined_illuminance()
Get the combined illuminance value.
Definition: tsl2591.cpp:253