ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
tcs34725.h
Go to the documentation of this file.
1#pragma once
2
7
8namespace esphome::tcs34725 {
9
31
38
40 SUB_SENSOR(clear)
41 SUB_SENSOR(red)
42 SUB_SENSOR(green)
43 SUB_SENSOR(blue)
44 SUB_SENSOR(illuminance)
45 SUB_SENSOR(color_temperature)
46
47 public:
48 void set_integration_time(TCS34725IntegrationTime integration_time);
49 void set_gain(TCS34725Gain gain);
50 void set_glass_attenuation_factor(float ga);
51
52 void setup() override;
53 void update() override;
54 void dump_config() override;
55
56 protected:
57 i2c::ErrorCode read_data_register_(uint8_t a_register, uint16_t &data) {
58 uint8_t buffer[2];
59 auto retval = this->read_register(a_register, buffer, 2);
60 if (retval == i2c::ERROR_OK)
61 data = encode_uint16(buffer[1], buffer[0]);
62 return retval;
63 }
64 i2c::ErrorCode write_config_register_(uint8_t a_register, uint8_t data) {
65 return this->write_register(a_register, &data, 1);
66 }
68 float gain_{1.0};
73
74 private:
75 void calculate_temperature_and_lux_(uint16_t r, uint16_t g, uint16_t b, uint16_t c);
76 uint16_t integration_reg_;
77 uint8_t gain_reg_{TCS34725_GAIN_1X};
78};
79
80} // namespace esphome::tcs34725
This class simplifies creating components that periodically check a state.
Definition component.h:532
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:144
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
Definition i2c.cpp:54
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
Definition i2c.cpp:45
i2c::ErrorCode read_data_register_(uint8_t a_register, uint16_t &data)
Definition tcs34725.h:57
i2c::ErrorCode write_config_register_(uint8_t a_register, uint8_t data)
Definition tcs34725.h:64
uint32_t buffer
Definition gif.cpp:50
AlsGain501 gain
IntegrationTime501 integration_time
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition i2c_bus.h:13
@ ERROR_OK
No error found during execution of method.
Definition i2c_bus.h:15
@ TCS34725_INTEGRATION_TIME_154MS
Definition tcs34725.h:16
@ TCS34725_INTEGRATION_TIME_120MS
Definition tcs34725.h:15
@ TCS34725_INTEGRATION_TIME_480MS
Definition tcs34725.h:24
@ TCS34725_INTEGRATION_TIME_540MS
Definition tcs34725.h:26
@ TCS34725_INTEGRATION_TIME_614MS
Definition tcs34725.h:28
@ TCS34725_INTEGRATION_TIME_600MS
Definition tcs34725.h:27
@ TCS34725_INTEGRATION_TIME_499MS
Definition tcs34725.h:25
@ TCS34725_INTEGRATION_TIME_360MS
Definition tcs34725.h:21
@ TCS34725_INTEGRATION_TIME_199MS
Definition tcs34725.h:18
@ TCS34725_INTEGRATION_TIME_300MS
Definition tcs34725.h:20
@ TCS34725_INTEGRATION_TIME_401MS
Definition tcs34725.h:22
@ TCS34725_INTEGRATION_TIME_AUTO
Definition tcs34725.h:29
@ TCS34725_INTEGRATION_TIME_101MS
Definition tcs34725.h:14
@ TCS34725_INTEGRATION_TIME_240MS
Definition tcs34725.h:19
@ TCS34725_INTEGRATION_TIME_180MS
Definition tcs34725.h:17
@ TCS34725_INTEGRATION_TIME_420MS
Definition tcs34725.h:23
@ TCS34725_INTEGRATION_TIME_50MS
Definition tcs34725.h:13
@ TCS34725_INTEGRATION_TIME_2_4MS
Definition tcs34725.h:11
@ TCS34725_INTEGRATION_TIME_24MS
Definition tcs34725.h:12
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
Definition helpers.h:1043