8static const char *
const TAG =
"veml3235.sensor";
11 uint8_t device_id[] = {0, 0};
13 ESP_LOGE(TAG,
"Unable to write configuration");
18 ESP_LOGE(TAG,
"Unable to read ID");
21 }
else if (device_id[0] != DEVICE_ID) {
22 ESP_LOGE(TAG,
"Incorrect device ID - expected 0x%.2x, read 0x%.2x", DEVICE_ID, device_id[0]);
29 uint16_t data = this->
power_on_ || force_on ? 0 : SHUTDOWN_BITS;
33 data |= (uint16_t(this->
gain_ << CONFIG_REG_G_BIT));
36 ESP_LOGVV(TAG,
"Writing 0x%.4x to register 0x%.2x", data, CONFIG_REG);
43 ESP_LOGW(TAG,
"Turning on failed");
51 uint8_t als_regs[] = {0, 0};
59 float als_raw_value_multiplier = LUX_MULTIPLIER_BASE;
60 uint16_t als_raw_value =
encode_uint16(als_regs[1], als_regs[0]);
63 als_raw_value_multiplier *= 2;
65 switch (this->
gain_) {
67 als_raw_value_multiplier *= 4;
70 als_raw_value_multiplier *= 2;
77 als_raw_value_multiplier *= 16;
80 als_raw_value_multiplier *= 8;
83 als_raw_value_multiplier *= 4;
86 als_raw_value_multiplier *= 2;
92 float lx = float(als_raw_value) * als_raw_value_multiplier;
93 ESP_LOGVV(TAG,
"'%s': ALS raw = %u, multiplier = %.5f", this->
get_name().c_str(), als_raw_value,
94 als_raw_value_multiplier);
95 ESP_LOGD(TAG,
"'%s': Illuminance = %.4flx", this->
get_name().c_str(), lx);
99 ESP_LOGW(TAG,
"Turning off failed");
117 if (als_raw_value >= UINT16_MAX * 0.9) {
126 switch (this->
gain_) {
179 switch (this->
gain_) {
191 integration_time = 50;
209 LOG_SENSOR(
"",
"VEML3235",
this);
210 LOG_I2C_DEVICE(
this);
212 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
214 LOG_UPDATE_INTERVAL(
this);
215 ESP_LOGCONFIG(TAG,
" Auto-gain enabled: %s", YESNO(this->
auto_gain_));
218 " Auto-gain upper threshold: %f%%\n"
219 " Auto-gain lower threshold: %f%%\n"
220 " Values below will be used as initial values only",
224 " Digital gain: %uX\n"
226 " Integration time: %ums",
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message=nullptr)
void status_clear_warning()
const StringRef & get_name() const
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
optional< std::array< uint8_t, N > > read_bytes_raw()
bool write_byte_16(uint8_t a_register, uint16_t data)
VEML3235ComponentIntegrationTime integration_time_
float auto_gain_threshold_high_
float auto_gain_threshold_low_
VEML3235ComponentGain gain()
void adjust_gain_(uint16_t als_raw_value)
VEML3235ComponentIntegrationTime integration_time()
VEML3235ComponentGain gain_
void dump_config() override
VEML3235ComponentDigitalGain digital_gain()
VEML3235ComponentDigitalGain digital_gain_
bool refresh_config_reg(bool force_on=false)
@ ERROR_OK
No error found during execution of method.
@ VEML3235_DIGITAL_GAIN_2X
@ VEML3235_DIGITAL_GAIN_1X
@ VEML3235_INTEGRATION_TIME_100MS
@ VEML3235_INTEGRATION_TIME_200MS
@ VEML3235_INTEGRATION_TIME_50MS
@ VEML3235_INTEGRATION_TIME_800MS
@ VEML3235_INTEGRATION_TIME_400MS
Providing packet encoding functions for exchanging data with a remote host.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
void IRAM_ATTR HOT delay(uint32_t ms)