12static constexpr uint8_t CONFIG_REG = 0x00;
13static constexpr uint8_t R_DATA_REG = 0x08;
14static constexpr uint8_t G_DATA_REG = 0x09;
15static constexpr uint8_t B_DATA_REG = 0x0A;
16static constexpr uint8_t W_DATA_REG = 0x0B;
18static constexpr uint8_t CONFIG_REG_IT_BIT = 4;
20static constexpr uint16_t MAX_COUNTS = 0xFFFF;
23static constexpr float LUX_PER_COUNT_40MS = 0.25168f;
28static constexpr float CCT_A = 4278.6f;
29static constexpr float CCT_EXPONENT = -1.2455f;
34 const uint8_t config[] = {
static_cast<uint8_t
>(this->
integration_time_ << CONFIG_REG_IT_BIT), 0x00};
49 " Integration time: %" PRIu32
" ms\n"
50 " Glass attenuation factor: %.2f\n"
51 " Color temperature offset: %.3f",
54 LOG_UPDATE_INTERVAL(
this);
75 uint16_t red, green, blue, white;
83 ESP_LOGV(TAG,
"Counts: red=%u green=%u blue=%u white=%u", red, green, blue, white);
94 const bool saturated = red == MAX_COUNTS || green == MAX_COUNTS || blue == MAX_COUNTS;
96 ESP_LOGW(TAG,
"Sensor saturated; use a shorter integration time");
101 if (green != MAX_COUNTS) {
102 const float lux_per_count = LUX_PER_COUNT_40MS /
static_cast<float>(1u << this->
integration_time_);
110 if (!saturated && green != 0) {
114 cct = CCT_A * powf(index, CCT_EXPONENT);
void mark_failed()
Mark this component as failed.
void status_set_warning()
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void status_clear_warning()
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len) const
writes an array of bytes to a specific register in the I²C device
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
void publish_state(float state)
Publish a new state to the front-end.
bool read_channel_(uint8_t reg, uint16_t &counts)
sensor::Sensor * illuminance_sensor_
sensor::Sensor * red_sensor_
sensor::Sensor * blue_sensor_
const float color_temperature_offset_
uint32_t integration_time_ms_() const
const float glass_attenuation_factor_
void dump_config() override
sensor::Sensor * white_sensor_
const VEML6040IntegrationTime integration_time_
sensor::Sensor * color_temperature_sensor_
sensor::Sensor * green_sensor_
@ ERROR_OK
No error found during execution of method.
ESPHOME_LOG_TAG(TAG, "veml6040")
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.