10static const char *
const TAG =
"apds9306";
35#define APDS9306_ERROR_CHECK(func, error) \
37 ESP_LOGE(TAG, error); \
38 this->mark_failed(); \
41#define APDS9306_WARNING_CHECK(func, warning) \
43 ESP_LOGW(TAG, warning); \
44 this->status_set_warning(); \
47#define APDS9306_WRITE_BYTE(reg, value) \
48 ESP_LOGV(TAG, "Writing 0x%02x to 0x%02x", value, reg); \
49 if (!this->write_byte(reg, value)) { \
50 ESP_LOGE(TAG, "Failed writing 0x%02x to 0x%02x", value, reg); \
51 this->mark_failed(); \
63 if (
id != 0xB1 &&
id != 0xB3) {
74 uint8_t als_gain = (this->
gain_ & 0x07);
89 LOG_SENSOR(
"",
"APDS9306",
this);
93 switch (this->error_code_) {
95 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
98 ESP_LOGE(TAG,
"APDS9306 has invalid id!");
101 ESP_LOGE(TAG,
"Setting up APDS9306 registers failed!");
108 " Measurement rate: %u\n"
109 " Measurement Resolution/Bit width: %d",
111 MEASUREMENT_BIT_WIDTH_VALUES[this->
bit_width_]);
113 LOG_UPDATE_INTERVAL(
this);
123 status &= 0b00001000;
142 float lux = ((float) light_level / AMBIENT_LIGHT_GAIN_VALUES[this->
gain_]) *
145 ESP_LOGD(TAG,
"Got illuminance=%.1flx from", lux);
void mark_failed()
Mark this component as failed.
void status_clear_warning()
MeasurementBitWidth bit_width_
void dump_config() override
MeasurementRate measurement_rate_
bool read_byte(uint8_t a_register, uint8_t *data)
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
void publish_state(float state)
Publish a new state to the front-end.
@ APDS9306_ALS_THRES_LOW_1
@ APDS9306_INT_PERSISTENCE
@ APDS9306_ALS_THRES_UP_2
@ APDS9306_ALS_THRES_UP_1
@ APDS9306_ALS_THRES_UP_0
@ APDS9306_ALS_THRES_LOW_2
@ APDS9306_ALS_THRES_LOW_0
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3)
Encode a 24-bit value given three bytes in most to least significant byte order.