35#define APDS9306_ERROR_CHECK(func, error) \
37 this->mark_failed(LOG_STR(error)); \
40#define APDS9306_WARNING_CHECK(func, warning) \
42 ESP_LOGW(TAG, warning); \
43 this->status_set_warning(); \
46#define APDS9306_WRITE_BYTE(reg, value) \
47 ESP_LOGV(TAG, "Writing 0x%02x to 0x%02x", value, reg); \
48 if (!this->write_byte(reg, value)) { \
49 ESP_LOGE(TAG, "Failed writing 0x%02x to 0x%02x", value, reg); \
50 this->mark_failed(LOG_STR(ESP_LOG_MSG_COMM_FAIL)); \
64 uint8_t als_gain = (this->
gain_ & 0x07);
79 LOG_SENSOR(
"",
"APDS9306",
this);
84 " Measurement rate: %u\n"
85 " Measurement Resolution/Bit width: %d",
87 MEASUREMENT_BIT_WIDTH_VALUES[this->
bit_width_]);
89 LOG_UPDATE_INTERVAL(
this);
118 float lux = ((float) light_level / AMBIENT_LIGHT_GAIN_VALUES[this->
gain_]) *
121 ESP_LOGD(TAG,
"Got illuminance=%.1flx from", lux);
void status_clear_warning()
MeasurementBitWidth bit_width_
void dump_config() override
MeasurementRate measurement_rate_
bool check_chip_id(Component *component, uint8_t a_register, uint8_t expected, uint8_t mask=0xFF)
Read the 8-bit ID at a_register and accept it when it matches expected in the bits set in mask.
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
ESPHOME_LOG_TAG(TAG, "apds9306")
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.