8 static const char *
const TAG =
"veml3235.sensor";
11 uint8_t device_id[] = {0, 0};
13 ESP_LOGCONFIG(TAG,
"Setting up VEML3235 '%s'...", this->
name_.
c_str());
16 ESP_LOGE(TAG,
"Unable to write configuration");
21 ESP_LOGE(TAG,
"Unable to read ID");
24 }
else if (device_id[0] != DEVICE_ID) {
25 ESP_LOGE(TAG,
"Incorrect device ID - expected 0x%.2x, read 0x%.2x", DEVICE_ID, device_id[0]);
32 uint16_t data = this->
power_on_ || force_on ? 0 : SHUTDOWN_BITS;
36 data |= (uint16_t(this->
gain_ << CONFIG_REG_G_BIT));
39 ESP_LOGVV(TAG,
"Writing 0x%.4x to register 0x%.2x", data, CONFIG_REG);
46 ESP_LOGW(TAG,
"Turning on failed");
54 uint8_t als_regs[] = {0, 0};
62 float als_raw_value_multiplier = LUX_MULTIPLIER_BASE;
63 uint16_t als_raw_value =
encode_uint16(als_regs[1], als_regs[0]);
66 als_raw_value_multiplier *= 2;
68 switch (this->
gain_) {
70 als_raw_value_multiplier *= 4;
73 als_raw_value_multiplier *= 2;
80 als_raw_value_multiplier *= 16;
83 als_raw_value_multiplier *= 8;
86 als_raw_value_multiplier *= 4;
89 als_raw_value_multiplier *= 2;
95 float lx = float(als_raw_value) * als_raw_value_multiplier;
96 ESP_LOGVV(TAG,
"'%s': ALS raw = %u, multiplier = %.5f", this->
get_name().c_str(), als_raw_value,
97 als_raw_value_multiplier);
98 ESP_LOGD(TAG,
"'%s': Illuminance = %.4flx", this->
get_name().c_str(), lx);
102 ESP_LOGW(TAG,
"Turning off failed");
120 if (als_raw_value >= UINT16_MAX * 0.9) {
129 switch (this->
gain_) {
182 switch (this->
gain_) {
194 integration_time = 50;
197 integration_time = 100;
200 integration_time = 200;
203 integration_time = 400;
206 integration_time = 800;
212 LOG_SENSOR(
"",
"VEML3235",
this);
213 LOG_I2C_DEVICE(
this);
215 ESP_LOGE(TAG,
"Communication failed");
217 LOG_UPDATE_INTERVAL(
this);
218 ESP_LOGCONFIG(TAG,
" Auto-gain enabled: %s", YESNO(this->
auto_gain_));
222 ESP_LOGCONFIG(TAG,
" Values below will be used as initial values only");
224 ESP_LOGCONFIG(TAG,
" Digital gain: %uX", digital_gain);
225 ESP_LOGCONFIG(TAG,
" Gain: %uX", gain);
226 ESP_LOGCONFIG(TAG,
" Integration time: %ums", integration_time);
float auto_gain_threshold_high_
void adjust_gain_(uint16_t als_raw_value)
void status_set_warning(const char *message="unspecified")
VEML3235ComponentGain gain()
optional< std::array< uint8_t, N > > read_bytes_raw()
VEML3235ComponentIntegrationTime integration_time_
VEML3235ComponentDigitalGain digital_gain_
bool refresh_config_reg(bool force_on=false)
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
void dump_config() override
No error found during execution of method.
void status_clear_warning()
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
VEML3235ComponentDigitalGain digital_gain()
constexpr const char * c_str() const
VEML3235ComponentIntegrationTime integration_time()
float auto_gain_threshold_low_
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
VEML3235ComponentGain gain_
bool write_byte_16(uint8_t a_register, uint16_t data)
const StringRef & get_name() const
void IRAM_ATTR HOT delay(uint32_t ms)