8static const char *
const TAG =
"ltr390";
10static const uint8_t LTR390_WAKEUP_TIME = 10;
11static const uint8_t LTR390_SETTLE_TIME = 5;
13static const uint8_t LTR390_MAIN_CTRL = 0x00;
14static const uint8_t LTR390_MEAS_RATE = 0x04;
15static const uint8_t LTR390_GAIN = 0x05;
16static const uint8_t LTR390_PART_ID = 0x06;
17static const uint8_t LTR390_MAIN_STATUS = 0x07;
19static const float GAINVALUES[5] = {1.0, 3.0, 6.0, 9.0, 18.0};
20static const float RESOLUTIONVALUE[6] = {4.0, 2.0, 1.0, 0.5, 0.25, 0.125};
21static const uint8_t RESOLUTION_BITS[6] = {20, 19, 18, 17, 16, 13};
24static const float RESOLUTION_SETTING[6] = {0x00, 0x10, 0x20, 0x30, 0x40, 0x50};
25static const uint32_t MODEADDRESSES[2] = {0x0D, 0x10};
27static const float SENSITIVITY_MAX = 2300;
28static const float INTG_MAX = RESOLUTIONVALUE[0] * 100;
29static const int GAIN_MAX = GAINVALUES[4];
34 for (
int i = 0; i < num_bytes; i++) {
36 value |= buffer[num_bytes - i - 1];
43 const uint8_t num_bytes = 3;
44 uint8_t buffer[num_bytes];
50 std::bitset<8>
status = this->
reg(LTR390_MAIN_STATUS).
get();
51 bool available =
status[3];
55 if (
millis() - now > max_wait_ms) {
56 ESP_LOGW(TAG,
"Sensor didn't return any data, aborting");
59 ESP_LOGV(TAG,
"Waiting for data");
64 ESP_LOGW(TAG,
"Reading data from sensor failed!");
95 float gain_scale_uv = GAINVALUES[this->
gain_uv_] / GAIN_MAX;
96 float intg_scale_uv = (RESOLUTIONVALUE[this->
res_uv_] * 100) / INTG_MAX;
97 float sensitivity_uv = SENSITIVITY_MAX * gain_scale_uv * intg_scale_uv;
108 std::bitset<8> ctrl = this->
reg(LTR390_MAIN_CTRL).
get();
110 this->
reg(LTR390_MAIN_CTRL) = ctrl.to_ulong();
116 std::bitset<8> ctrl = this->
reg(LTR390_MAIN_CTRL).
get();
119 this->
reg(LTR390_MAIN_CTRL) = ctrl.to_ulong();
126 this->
reg(LTR390_MEAS_RATE) = RESOLUTION_SETTING[this->
res_als_];
131 this->
reg(LTR390_MEAS_RATE) = RESOLUTION_SETTING[this->
res_uv_];
137 this->
set_timeout(int_time + LTR390_WAKEUP_TIME + LTR390_SETTLE_TIME, [
this,
mode]() {
154 std::bitset<8> ctrl = this->
reg(LTR390_MAIN_CTRL).
get();
156 this->
reg(LTR390_MAIN_CTRL) = ctrl.to_ulong();
160 ctrl = this->
reg(LTR390_MAIN_CTRL).
get();
162 this->
reg(LTR390_MAIN_CTRL) = ctrl.to_ulong();
165 ctrl = this->
reg(LTR390_MAIN_CTRL).
get();
169 ESP_LOGW(TAG,
"Sensor didn't respond with enabled state");
187 LOG_I2C_DEVICE(
this);
190 " ALS Resolution: %u-bit\n"
192 " UV Resolution: %u-bit",
194 RESOLUTION_BITS[this->
res_uv_]);
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_timeout(const std voi set_timeout)(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.