ESPHome 2025.5.2
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
tcs34725.h
Go to the documentation of this file.
1#pragma once
2
6
7namespace esphome {
8namespace tcs34725 {
9
31
38
40 public:
43 void set_glass_attenuation_factor(float ga);
44
45 void set_clear_sensor(sensor::Sensor *clear_sensor) { clear_sensor_ = clear_sensor; }
46 void set_red_sensor(sensor::Sensor *red_sensor) { red_sensor_ = red_sensor; }
47 void set_green_sensor(sensor::Sensor *green_sensor) { green_sensor_ = green_sensor; }
48 void set_blue_sensor(sensor::Sensor *blue_sensor) { blue_sensor_ = blue_sensor; }
49 void set_illuminance_sensor(sensor::Sensor *illuminance_sensor) { illuminance_sensor_ = illuminance_sensor; }
50 void set_color_temperature_sensor(sensor::Sensor *color_temperature_sensor) {
51 color_temperature_sensor_ = color_temperature_sensor;
52 }
53
54 void setup() override;
55 float get_setup_priority() const override;
56 void update() override;
57 void dump_config() override;
58
59 protected:
60 i2c::ErrorCode read_data_register_(uint8_t a_register, uint16_t &data) {
61 uint8_t buffer[2];
62 auto retval = this->read_register(a_register, buffer, 2);
63 if (retval == i2c::ERROR_OK)
64 data = (uint16_t(buffer[1]) << 8) | (uint16_t(buffer[0]) & 0xFF);
65 return retval;
66 }
67 i2c::ErrorCode write_config_register_(uint8_t a_register, uint8_t data) {
68 return this->write_register(a_register, &data, 1);
69 }
77 float gain_{1.0};
82
83 private:
84 void calculate_temperature_and_lux_(uint16_t r, uint16_t g, uint16_t b, uint16_t c);
85 uint16_t integration_reg_;
86 uint8_t gain_reg_{TCS34725_GAIN_1X};
87};
88
89} // namespace tcs34725
90} // namespace esphome
This class simplifies creating components that periodically check a state.
Definition component.h:301
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:133
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a specific register in the I²C device
Definition i2c.cpp:25
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len, bool stop=true)
reads an array of bytes from a specific register in the I²C device
Definition i2c.cpp:10
Base-class for all sensors.
Definition sensor.h:57
float get_setup_priority() const override
Definition tcs34725.cpp:60
void set_color_temperature_sensor(sensor::Sensor *color_temperature_sensor)
Definition tcs34725.h:50
void set_red_sensor(sensor::Sensor *red_sensor)
Definition tcs34725.h:46
i2c::ErrorCode read_data_register_(uint8_t a_register, uint16_t &data)
Definition tcs34725.h:60
void set_green_sensor(sensor::Sensor *green_sensor)
Definition tcs34725.h:47
void set_blue_sensor(sensor::Sensor *blue_sensor)
Definition tcs34725.h:48
sensor::Sensor * illuminance_sensor_
Definition tcs34725.h:74
i2c::ErrorCode write_config_register_(uint8_t a_register, uint8_t data)
Definition tcs34725.h:67
void set_illuminance_sensor(sensor::Sensor *illuminance_sensor)
Definition tcs34725.h:49
void set_integration_time(TCS34725IntegrationTime integration_time)
Definition tcs34725.cpp:307
void set_gain(TCS34725Gain gain)
Definition tcs34725.cpp:323
sensor::Sensor * color_temperature_sensor_
Definition tcs34725.h:75
void set_clear_sensor(sensor::Sensor *clear_sensor)
Definition tcs34725.h:45
AlsGain501 gain
IntegrationTime501 integration_time
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition i2c_bus.h:11
@ ERROR_OK
No error found during execution of method.
Definition i2c_bus.h:13
@ 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
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7