ESPHome 2026.5.1
Loading...
Searching...
No Matches
tcs34725.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace esphome::tcs34725 {
8
30
37
39 public:
42 void set_glass_attenuation_factor(float ga);
43
44 void set_clear_sensor(sensor::Sensor *clear_sensor) { clear_sensor_ = clear_sensor; }
45 void set_red_sensor(sensor::Sensor *red_sensor) { red_sensor_ = red_sensor; }
46 void set_green_sensor(sensor::Sensor *green_sensor) { green_sensor_ = green_sensor; }
47 void set_blue_sensor(sensor::Sensor *blue_sensor) { blue_sensor_ = blue_sensor; }
48 void set_illuminance_sensor(sensor::Sensor *illuminance_sensor) { illuminance_sensor_ = illuminance_sensor; }
49 void set_color_temperature_sensor(sensor::Sensor *color_temperature_sensor) {
50 color_temperature_sensor_ = color_temperature_sensor;
51 }
52
53 void setup() override;
54 void update() override;
55 void dump_config() override;
56
57 protected:
58 i2c::ErrorCode read_data_register_(uint8_t a_register, uint16_t &data) {
59 uint8_t buffer[2];
60 auto retval = this->read_register(a_register, buffer, 2);
61 if (retval == i2c::ERROR_OK)
62 data = (uint16_t(buffer[1]) << 8) | (uint16_t(buffer[0]) & 0xFF);
63 return retval;
64 }
65 i2c::ErrorCode write_config_register_(uint8_t a_register, uint8_t data) {
66 return this->write_register(a_register, &data, 1);
67 }
75 float gain_{1.0};
80
81 private:
82 void calculate_temperature_and_lux_(uint16_t r, uint16_t g, uint16_t b, uint16_t c);
83 uint16_t integration_reg_;
84 uint8_t gain_reg_{TCS34725_GAIN_1X};
85};
86
87} // namespace esphome::tcs34725
This class simplifies creating components that periodically check a state.
Definition component.h:602
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:132
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:34
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:25
Base-class for all sensors.
Definition sensor.h:47
void set_color_temperature_sensor(sensor::Sensor *color_temperature_sensor)
Definition tcs34725.h:49
void set_red_sensor(sensor::Sensor *red_sensor)
Definition tcs34725.h:45
i2c::ErrorCode read_data_register_(uint8_t a_register, uint16_t &data)
Definition tcs34725.h:58
void set_green_sensor(sensor::Sensor *green_sensor)
Definition tcs34725.h:46
void set_blue_sensor(sensor::Sensor *blue_sensor)
Definition tcs34725.h:47
sensor::Sensor * illuminance_sensor_
Definition tcs34725.h:72
i2c::ErrorCode write_config_register_(uint8_t a_register, uint8_t data)
Definition tcs34725.h:65
void set_illuminance_sensor(sensor::Sensor *illuminance_sensor)
Definition tcs34725.h:48
void set_integration_time(TCS34725IntegrationTime integration_time)
Definition tcs34725.cpp:304
void set_gain(TCS34725Gain gain)
Definition tcs34725.cpp:320
sensor::Sensor * color_temperature_sensor_
Definition tcs34725.h:73
void set_clear_sensor(sensor::Sensor *clear_sensor)
Definition tcs34725.h:44
AlsGain501 gain
IntegrationTime501 integration_time
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition i2c_bus.h:12
@ ERROR_OK
No error found during execution of method.
Definition i2c_bus.h:14
@ TCS34725_INTEGRATION_TIME_154MS
Definition tcs34725.h:15
@ TCS34725_INTEGRATION_TIME_120MS
Definition tcs34725.h:14
@ TCS34725_INTEGRATION_TIME_480MS
Definition tcs34725.h:23
@ TCS34725_INTEGRATION_TIME_540MS
Definition tcs34725.h:25
@ TCS34725_INTEGRATION_TIME_614MS
Definition tcs34725.h:27
@ TCS34725_INTEGRATION_TIME_600MS
Definition tcs34725.h:26
@ TCS34725_INTEGRATION_TIME_499MS
Definition tcs34725.h:24
@ TCS34725_INTEGRATION_TIME_360MS
Definition tcs34725.h:20
@ TCS34725_INTEGRATION_TIME_199MS
Definition tcs34725.h:17
@ TCS34725_INTEGRATION_TIME_300MS
Definition tcs34725.h:19
@ TCS34725_INTEGRATION_TIME_401MS
Definition tcs34725.h:21
@ TCS34725_INTEGRATION_TIME_AUTO
Definition tcs34725.h:28
@ TCS34725_INTEGRATION_TIME_101MS
Definition tcs34725.h:13
@ TCS34725_INTEGRATION_TIME_240MS
Definition tcs34725.h:18
@ TCS34725_INTEGRATION_TIME_180MS
Definition tcs34725.h:16
@ TCS34725_INTEGRATION_TIME_420MS
Definition tcs34725.h:22
@ TCS34725_INTEGRATION_TIME_50MS
Definition tcs34725.h:12
@ TCS34725_INTEGRATION_TIME_2_4MS
Definition tcs34725.h:10
@ TCS34725_INTEGRATION_TIME_24MS
Definition tcs34725.h:11