ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
ltr501.h
Go to the documentation of this file.
1#pragma once
2
8
10
11namespace esphome::ltr501 {
12
14
21
23 public:
24 //
25 // EspHome framework functions
26 //
27 void setup() override;
28 void dump_config() override;
29 void update() override;
30 void loop() override;
31
32 // Configuration setters : General
33 //
35
36 // Configuration setters : ALS
37 //
38 void set_als_auto_mode(bool enable) { this->automatic_mode_enabled_ = enable; }
42 void set_als_glass_attenuation_factor(float factor) { this->glass_attenuation_factor_ = factor; }
43
44 // Configuration setters : PS
45 //
46 void set_ps_high_threshold(uint16_t threshold) { this->ps_threshold_high_ = threshold; }
47 void set_ps_low_threshold(uint16_t threshold) { this->ps_threshold_low_ = threshold; }
48 void set_ps_cooldown_time_s(uint16_t time) { this->ps_cooldown_time_s_ = time; }
50
51 template<typename F> void add_on_ps_high_trigger_callback(F &&callback) {
52 this->on_ps_high_trigger_callback_.add(std::forward<F>(callback));
53 }
54
55 template<typename F> void add_on_ps_low_trigger_callback(F &&callback) {
56 this->on_ps_low_trigger_callback_.add(std::forward<F>(callback));
57 }
58
59 protected:
60 //
61 // Internal state machine, used to split all the actions into
62 // small steps in loop() to make sure we are not blocking execution
63 //
75 uint8_t tries_{0};
76
78
79 //
80 // Current measurements data
81 //
90 uint16_t ps_readings_{0xfffe};
91
92 inline bool is_als_() const {
94 }
95 inline bool is_ps_() const {
97 }
98
99 //
100 // Device interaction and data manipulation
101 //
102 bool check_part_number_();
103
104 void configure_reset_();
105 void configure_als_();
108 LtrDataAvail is_als_data_ready_(AlsReadings &data);
109 void read_sensor_data_(AlsReadings &data);
110 bool are_adjustments_required_(AlsReadings &data);
111 void apply_lux_calculation_(AlsReadings &data);
112 void publish_data_part_1_(AlsReadings &data);
113 void publish_data_part_2_(AlsReadings &data);
114
115 void configure_ps_();
116 uint16_t read_ps_data_();
118
119 //
120 // Component configuration
121 //
127
130 uint16_t ps_threshold_high_{0xffff};
131 uint16_t ps_threshold_low_{0x0000};
134
135 SUB_SENSOR(ambient_light) // calculated lux
136 SUB_SENSOR(full_spectrum_counts) // direct reading CH0, infrared + visible light
137 SUB_SENSOR(infrared_counts) // direct reading CH1, infrared only
138 SUB_SENSOR(actual_gain) // actual gain of reading
139 SUB_SENSOR(actual_integration_time) // actual integration time
140 SUB_SENSOR(proximity_counts) // proximity sensor
141
142 protected:
143 bool is_any_als_sensor_enabled_() const {
144 return this->ambient_light_sensor_ != nullptr || this->full_spectrum_counts_sensor_ != nullptr ||
145 this->infrared_counts_sensor_ != nullptr || this->actual_gain_sensor_ != nullptr ||
146 this->actual_integration_time_sensor_ != nullptr;
147 }
148 bool is_any_ps_sensor_enabled_() const { return this->proximity_counts_sensor_ != nullptr; }
149
150 CallbackManager<void()> on_ps_high_trigger_callback_;
152};
153} // namespace esphome::ltr501
This class simplifies creating components that periodically check a state.
Definition component.h:532
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:144
LtrDataAvail is_als_data_ready_(AlsReadings &data)
Definition ltr501.cpp:376
void set_ps_high_threshold(uint16_t threshold)
Definition ltr501.h:46
void configure_gain_(AlsGain501 gain)
Definition ltr501.cpp:344
SUB_SENSOR(ambient_light) SUB_SENSOR(full_spectrum_counts) SUB_SENSOR(infrared_counts) SUB_SENSOR(actual_gain) SUB_SENSOR(actual_integration_time) SUB_SENSOR(proximity_counts) protected CallbackManager< void()> on_ps_low_trigger_callback_
Definition ltr501.h:135
void set_ps_cooldown_time_s(uint16_t time)
Definition ltr501.h:48
void publish_data_part_1_(AlsReadings &data)
Definition ltr501.cpp:517
void publish_data_part_2_(AlsReadings &data)
Definition ltr501.cpp:524
void configure_integration_time_(IntegrationTime501 time)
Definition ltr501.cpp:360
void set_ps_low_threshold(uint16_t threshold)
Definition ltr501.h:47
IntegrationTime501 integration_time_
Definition ltr501.h:124
struct esphome::ltr501::LTRAlsPs501Component::AlsReadings als_readings_
void read_sensor_data_(AlsReadings &data)
Definition ltr501.cpp:390
MeasurementRepeatRate repeat_rate_
Definition ltr501.h:125
void add_on_ps_low_trigger_callback(F &&callback)
Definition ltr501.h:55
void set_als_integration_time(IntegrationTime501 time)
Definition ltr501.h:40
enum esphome::ltr501::LTRAlsPs501Component::State NOT_INITIALIZED
void set_ltr_type(LtrType type)
Definition ltr501.h:34
void apply_lux_calculation_(AlsReadings &data)
Definition ltr501.cpp:475
void set_als_auto_mode(bool enable)
Definition ltr501.h:38
void set_ps_gain(PsGain501 gain)
Definition ltr501.h:49
void set_als_glass_attenuation_factor(float factor)
Definition ltr501.h:42
bool are_adjustments_required_(AlsReadings &data)
Definition ltr501.cpp:403
void set_als_gain(AlsGain501 gain)
Definition ltr501.h:39
void add_on_ps_high_trigger_callback(F &&callback)
Definition ltr501.h:51
void set_als_meas_repeat_rate(MeasurementRepeatRate rate)
Definition ltr501.h:41
uint8_t type
AlsGain501 gain
@ LTR_TYPE_ALS_AND_PS
Definition ltr501.h:19
@ LTR_TYPE_ALS_ONLY
Definition ltr501.h:17
static void uint32_t