ESPHome 2025.5.0
Loading...
Searching...
No Matches
tsl2591.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <cinttypes>
8
9namespace esphome {
10namespace tsl2591 {
11
25
38
45 TSL2591_GAIN_LOW = 0b00 << 4, // 1x
46 TSL2591_GAIN_MED = 0b01 << 4, // 25x
47 TSL2591_GAIN_HIGH = 0b10 << 4, // 400x
48 TSL2591_GAIN_MAX = 0b11 << 4, // 9500x
49};
50
60
68 public:
101
115 void set_power_save_mode(bool enable);
116
121 void set_name(const char *name);
122
145 void set_device_and_glass_attenuation_factors(float device_factor, float glass_attenuation_factor);
146
152 float get_calculated_lux(uint16_t full_spectrum, uint16_t infrared);
153
162 uint32_t get_combined_illuminance();
163
177 uint16_t get_illuminance(TSL2591SensorChannel channel);
178
189 uint16_t get_illuminance(TSL2591SensorChannel channel, uint32_t combined_illuminance);
190
202 bool is_adc_valid();
203
209 void enable();
216 void disable();
217
222 void automatic_gain_update(uint16_t full_spectrum);
223
228 float get_actual_gain();
229
230 // ========== INTERNAL METHODS ==========
231 // (In most use cases you won't need these. They're for ESPHome integration use.)
233 void set_full_spectrum_sensor(sensor::Sensor *full_spectrum_sensor);
235 void set_actual_gain_sensor(sensor::Sensor *actual_gain_sensor);
237 void set_infrared_sensor(sensor::Sensor *infrared_sensor);
239 void set_visible_sensor(sensor::Sensor *visible_sensor);
241 void set_calculated_lux_sensor(sensor::Sensor *calculated_lux_sensor);
247 void setup() override;
249 void dump_config() override;
251 void update() override;
253 float get_setup_priority() const override;
254
255 protected:
256 const char *name_;
271 void process_update_();
273};
274
275} // namespace tsl2591
276} // namespace esphome
This class simplifies creating components that periodically check a state.
Definition component.h:301
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:133
Base-class for all sensors.
Definition sensor.h:57
This class includes support for the TSL2591 i2c ambient light sensor.
Definition tsl2591.h:67
TSL2591IntegrationTime integration_time_
Definition tsl2591.h:262
void dump_config() override
Used by ESPHome framework.
Definition tsl2591.cpp:87
float get_setup_priority() const override
Used by ESPHome framework.
Definition tsl2591.cpp:253
TSL2591ComponentGain component_gain_
Definition tsl2591.h:263
void automatic_gain_update(uint16_t full_spectrum)
Updates the gain setting based on the most recent full spectrum reading.
Definition tsl2591.cpp:420
bool is_adc_valid()
Are the device ADC values valid?
Definition tsl2591.cpp:255
sensor::Sensor * infrared_sensor_
Definition tsl2591.h:258
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:356
sensor::Sensor * calculated_lux_sensor_
Definition tsl2591.h:260
void set_visible_sensor(sensor::Sensor *visible_sensor)
Used by ESPHome framework.
Definition tsl2591.cpp:207
void set_device_and_glass_attenuation_factors(float device_factor, float glass_attenuation_factor)
Sets the device and glass attenuation factors.
Definition tsl2591.cpp:227
sensor::Sensor * full_spectrum_sensor_
Definition tsl2591.h:257
void set_integration_time(TSL2591IntegrationTime integration_time)
Used by ESPHome framework.
Definition tsl2591.cpp:221
void set_calculated_lux_sensor(sensor::Sensor *calculated_lux_sensor)
Used by ESPHome framework.
Definition tsl2591.cpp:213
uint32_t get_combined_illuminance()
Get the combined illuminance value.
Definition tsl2591.cpp:264
void set_name(const char *name)
Sets the name for this instance of the device.
Definition tsl2591.cpp:251
sensor::Sensor * visible_sensor_
Definition tsl2591.h:259
void set_infrared_sensor(sensor::Sensor *infrared_sensor)
Used by ESPHome framework.
Definition tsl2591.cpp:203
sensor::Sensor * actual_gain_sensor_
Definition tsl2591.h:261
void set_actual_gain_sensor(sensor::Sensor *actual_gain_sensor)
Used by ESPHome framework.
Definition tsl2591.cpp:217
void set_gain(TSL2591ComponentGain gain)
Used by ESPHome framework.
Definition tsl2591.cpp:225
void enable()
Powers on the TSL2591 device and enables its sensors.
Definition tsl2591.cpp:26
void update() override
Used by ESPHome framework.
Definition tsl2591.cpp:186
void set_integration_time_and_gain(TSL2591IntegrationTime integration_time, TSL2591Gain gain)
Set device integration time and gain.
Definition tsl2591.cpp:232
void set_full_spectrum_sensor(sensor::Sensor *full_spectrum_sensor)
Used by ESPHome framework.
Definition tsl2591.cpp:209
void disable()
Powers off the TSL2591 device.
Definition tsl2591.cpp:33
float get_actual_gain()
Reads the actual gain used.
Definition tsl2591.cpp:465
uint16_t get_illuminance(TSL2591SensorChannel channel)
Get an individual sensor channel reading.
Definition tsl2591.cpp:321
void setup() override
Used by ESPHome framework.
Definition tsl2591.cpp:45
void set_power_save_mode(bool enable)
Should the device be powered down between readings?
Definition tsl2591.cpp:249
AlsGain501 gain
IntegrationTime501 integration_time
TSL2591Gain
Enum listing all gain settings for the TSL2591.
Definition tsl2591.h:44
TSL2591ComponentGain
Enum listing all gain settings for the TSL2591 component.
Definition tsl2591.h:31
TSL2591IntegrationTime
Enum listing all conversion/integration time settings for the TSL2591.
Definition tsl2591.h:17
@ TSL2591_INTEGRATION_TIME_500MS
Definition tsl2591.h:22
@ TSL2591_INTEGRATION_TIME_600MS
Definition tsl2591.h:23
@ TSL2591_INTEGRATION_TIME_100MS
Definition tsl2591.h:18
@ TSL2591_INTEGRATION_TIME_200MS
Definition tsl2591.h:19
@ TSL2591_INTEGRATION_TIME_300MS
Definition tsl2591.h:20
@ TSL2591_INTEGRATION_TIME_400MS
Definition tsl2591.h:21
TSL2591SensorChannel
Enum listing sensor channels.
Definition tsl2591.h:55
@ TSL2591_SENSOR_CHANNEL_INFRARED
Definition tsl2591.h:57
@ TSL2591_SENSOR_CHANNEL_VISIBLE
Definition tsl2591.h:56
@ TSL2591_SENSOR_CHANNEL_FULL_SPECTRUM
Definition tsl2591.h:58
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7