ESPHome 2026.5.0-dev
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 {
12namespace ltr_als_ps {
13
15
22
24 public:
25 //
26 // EspHome framework functions
27 //
28 void setup() override;
29 void dump_config() override;
30 void update() override;
31 void loop() override;
32
33 // Configuration setters : General
34 //
36
37 // Configuration setters : ALS
38 //
39 void set_als_auto_mode(bool enable) { this->automatic_mode_enabled_ = enable; }
40 void set_als_gain(AlsGain gain) { this->gain_ = gain; }
43 void set_als_glass_attenuation_factor(float factor) { this->glass_attenuation_factor_ = factor; }
44
45 // Configuration setters : PS
46 //
47 void set_ps_high_threshold(uint16_t threshold) { this->ps_threshold_high_ = threshold; }
48 void set_ps_low_threshold(uint16_t threshold) { this->ps_threshold_low_ = threshold; }
49 void set_ps_cooldown_time_s(uint16_t time) { this->ps_cooldown_time_s_ = time; }
50 void set_ps_gain(PsGain gain) { this->ps_gain_ = gain; }
51
52 // Sensors setters
53 //
60
61 template<typename F> void add_on_ps_high_trigger_callback(F &&callback) {
62 this->on_ps_high_trigger_callback_.add(std::forward<F>(callback));
63 }
64
65 template<typename F> void add_on_ps_low_trigger_callback(F &&callback) {
66 this->on_ps_low_trigger_callback_.add(std::forward<F>(callback));
67 }
68
69 protected:
70 //
71 // Internal state machine, used to split all the actions into
72 // small steps in loop() to make sure we are not blocking execution
73 //
85
87
88 //
89 // Current measurements data
90 //
99 uint16_t ps_readings_{0xfffe};
100
101 inline bool is_als_() const {
103 }
104 inline bool is_ps_() const {
106 }
107
108 //
109 // Device interaction and data manipulation
110 //
111 bool check_part_number_();
112
113 void configure_reset_();
114 void configure_als_();
117 LtrDataAvail is_als_data_ready_(AlsReadings &data);
118 void read_sensor_data_(AlsReadings &data);
119 bool are_adjustments_required_(AlsReadings &data);
120 void apply_lux_calculation_(AlsReadings &data);
121 void publish_data_part_1_(AlsReadings &data);
122 void publish_data_part_2_(AlsReadings &data);
123
124 void configure_ps_();
125 uint16_t read_ps_data_();
127
128 //
129 // Component configuration
130 //
136
140 uint16_t ps_threshold_high_{0xffff};
141 uint16_t ps_threshold_low_{0x0000};
144
145 //
146 // Sensors for publishing data
147 //
148 sensor::Sensor *infrared_counts_sensor_{nullptr}; // direct reading CH1, infrared only
149 sensor::Sensor *full_spectrum_counts_sensor_{nullptr}; // direct reading CH0, infrared + visible light
150 sensor::Sensor *ambient_light_sensor_{nullptr}; // calculated lux
151 sensor::Sensor *actual_gain_sensor_{nullptr}; // actual gain of reading
152 sensor::Sensor *actual_integration_time_sensor_{nullptr}; // actual integration time
153 sensor::Sensor *proximity_counts_sensor_{nullptr}; // proximity sensor
154
156 return this->ambient_light_sensor_ != nullptr || this->full_spectrum_counts_sensor_ != nullptr ||
157 this->infrared_counts_sensor_ != nullptr || this->actual_gain_sensor_ != nullptr ||
158 this->actual_integration_time_sensor_ != nullptr;
159 }
160 bool is_any_ps_sensor_enabled_() const { return this->proximity_counts_sensor_ != nullptr; }
161
164};
165} // namespace ltr_als_ps
166} // namespace esphome
This class simplifies creating components that periodically check a state.
Definition component.h:602
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:132
void set_actual_gain_sensor(sensor::Sensor *sensor)
Definition ltr_als_ps.h:57
void publish_data_part_2_(AlsReadings &data)
void set_ambient_light_sensor(sensor::Sensor *sensor)
Definition ltr_als_ps.h:54
void configure_integration_time_(IntegrationTime time)
enum esphome::ltr_als_ps::LTRAlsPsComponent::State NOT_INITIALIZED
sensor::Sensor * full_spectrum_counts_sensor_
Definition ltr_als_ps.h:149
LtrDataAvail is_als_data_ready_(AlsReadings &data)
void set_als_meas_repeat_rate(MeasurementRepeatRate rate)
Definition ltr_als_ps.h:42
CallbackManager< void()> on_ps_low_trigger_callback_
Definition ltr_als_ps.h:163
void read_sensor_data_(AlsReadings &data)
CallbackManager< void()> on_ps_high_trigger_callback_
Definition ltr_als_ps.h:162
void add_on_ps_high_trigger_callback(F &&callback)
Definition ltr_als_ps.h:61
void set_actual_integration_time_sensor(sensor::Sensor *sensor)
Definition ltr_als_ps.h:58
void set_full_spectrum_counts_sensor(sensor::Sensor *sensor)
Definition ltr_als_ps.h:55
void set_ps_cooldown_time_s(uint16_t time)
Definition ltr_als_ps.h:49
void set_infrared_counts_sensor(sensor::Sensor *sensor)
Definition ltr_als_ps.h:56
void set_ps_low_threshold(uint16_t threshold)
Definition ltr_als_ps.h:48
void add_on_ps_low_trigger_callback(F &&callback)
Definition ltr_als_ps.h:65
void set_ps_high_threshold(uint16_t threshold)
Definition ltr_als_ps.h:47
void publish_data_part_1_(AlsReadings &data)
bool are_adjustments_required_(AlsReadings &data)
void set_proximity_counts_sensor(sensor::Sensor *sensor)
Definition ltr_als_ps.h:59
struct esphome::ltr_als_ps::LTRAlsPsComponent::AlsReadings als_readings_
void set_als_glass_attenuation_factor(float factor)
Definition ltr_als_ps.h:43
sensor::Sensor * actual_integration_time_sensor_
Definition ltr_als_ps.h:152
void apply_lux_calculation_(AlsReadings &data)
void set_als_integration_time(IntegrationTime time)
Definition ltr_als_ps.h:41
Base-class for all sensors.
Definition sensor.h:47
uint16_t type
AlsGain501 gain
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
static void uint32_t