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");
20 }
else if (device_id[0] != DEVICE_ID) {
21 ESP_LOGE(TAG,
"Incorrect device ID - expected 0x%.2x, read 0x%.2x", DEVICE_ID, device_id[0]);
27 uint16_t
data = this->
power_on_ || force_on ? 0 : SHUTDOWN_BITS;
31 data |= (uint16_t(this->
gain_ << CONFIG_REG_G_BIT));
34 ESP_LOGVV(TAG,
"Writing 0x%.4x to register 0x%.2x",
data, CONFIG_REG);
41 ESP_LOGW(TAG,
"Turning on failed");
49 uint8_t als_regs[] = {0, 0};
57 float als_raw_value_multiplier = LUX_MULTIPLIER_BASE;
58 uint16_t als_raw_value =
encode_uint16(als_regs[1], als_regs[0]);
61 als_raw_value_multiplier *= 2;
63 switch (this->
gain_) {
65 als_raw_value_multiplier *= 4;
68 als_raw_value_multiplier *= 2;
75 als_raw_value_multiplier *= 16;
78 als_raw_value_multiplier *= 8;
81 als_raw_value_multiplier *= 4;
84 als_raw_value_multiplier *= 2;
90 float lx = float(als_raw_value) * als_raw_value_multiplier;
91 ESP_LOGVV(TAG,
"'%s': ALS raw = %u, multiplier = %.5f", this->
get_name().c_str(), als_raw_value,
92 als_raw_value_multiplier);
93 ESP_LOGD(TAG,
"'%s': Illuminance = %.4flx", this->
get_name().c_str(), lx);
97 ESP_LOGW(TAG,
"Turning off failed");
115 if (als_raw_value >= UINT16_MAX * 0.9) {
124 switch (this->
gain_) {
177 switch (this->
gain_) {
189 integration_time = 50;
207 LOG_SENSOR(
"",
"VEML3235",
this);
208 LOG_I2C_DEVICE(
this);
210 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
212 LOG_UPDATE_INTERVAL(
this);
213 ESP_LOGCONFIG(TAG,
" Auto-gain enabled: %s", YESNO(this->
auto_gain_));
216 " Auto-gain upper threshold: %f%%\n"
217 " Auto-gain lower threshold: %f%%\n"
218 " Values below will be used as initial values only",
222 " Digital gain: %uX\n"
224 " 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 read_register(uint8_t a_register, uint8_t *data, size_t len)
reads an array of bytes from a specific register in the I²C device
bool write_byte_16(uint8_t a_register, uint16_t data) const
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)