ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
ltr_als_ps.h
Go to the documentation of this file.
1#pragma once
2
8
9#include "ltr_definitions.h"
10
11namespace esphome::ltr_als_ps {
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; }
39 void set_als_gain(AlsGain gain) { this->gain_ = gain; }
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; }
49 void set_ps_gain(PsGain gain) { this->ps_gain_ = gain; }
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
77
78 //
79 // Current measurements data
80 //
89 uint16_t ps_readings_{0xfffe};
90
91 inline bool is_als_() const {
93 }
94 inline bool is_ps_() const {
96 }
97
98 //
99 // Device interaction and data manipulation
100 //
101 bool check_part_number_();
102
103 void configure_reset_();
104 void configure_als_();
107 LtrDataAvail is_als_data_ready_(AlsReadings &data);
108 void read_sensor_data_(AlsReadings &data);
109 bool are_adjustments_required_(AlsReadings &data);
110 void apply_lux_calculation_(AlsReadings &data);
111 void publish_data_part_1_(AlsReadings &data);
112 void publish_data_part_2_(AlsReadings &data);
113
114 void configure_ps_();
115 uint16_t read_ps_data_();
117
118 //
119 // Component configuration
120 //
126
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::ltr_als_ps
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
void publish_data_part_2_(AlsReadings &data)
void configure_integration_time_(IntegrationTime time)
enum esphome::ltr_als_ps::LTRAlsPsComponent::State NOT_INITIALIZED
LtrDataAvail is_als_data_ready_(AlsReadings &data)
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 ltr_als_ps.h:135
void set_als_meas_repeat_rate(MeasurementRepeatRate rate)
Definition ltr_als_ps.h:41
void read_sensor_data_(AlsReadings &data)
void add_on_ps_high_trigger_callback(F &&callback)
Definition ltr_als_ps.h:51
void set_ps_cooldown_time_s(uint16_t time)
Definition ltr_als_ps.h:48
void set_ps_low_threshold(uint16_t threshold)
Definition ltr_als_ps.h:47
void add_on_ps_low_trigger_callback(F &&callback)
Definition ltr_als_ps.h:55
void set_ps_high_threshold(uint16_t threshold)
Definition ltr_als_ps.h:46
void publish_data_part_1_(AlsReadings &data)
bool are_adjustments_required_(AlsReadings &data)
struct esphome::ltr_als_ps::LTRAlsPsComponent::AlsReadings als_readings_
void set_als_glass_attenuation_factor(float factor)
Definition ltr_als_ps.h:42
void apply_lux_calculation_(AlsReadings &data)
void set_als_integration_time(IntegrationTime time)
Definition ltr_als_ps.h:40
uint8_t type
AlsGain501 gain
static void uint32_t