ESPHome  2024.10.2
tcs34725.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace tcs34725 {
9 
30 };
31 
37 };
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  }
76  float integration_time_{2.4};
77  float gain_{1.0};
78  float glass_attenuation_{1.0};
79  float illuminance_;
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
void set_integration_time(TCS34725IntegrationTime integration_time)
Definition: tcs34725.cpp:307
void set_color_temperature_sensor(sensor::Sensor *color_temperature_sensor)
Definition: tcs34725.h:50
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
i2c::ErrorCode write_config_register_(uint8_t a_register, uint8_t data)
Definition: tcs34725.h:67
void set_glass_attenuation_factor(float ga)
Definition: tcs34725.cpp:344
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_clear_sensor(sensor::Sensor *clear_sensor)
Definition: tcs34725.h:45
void set_green_sensor(sensor::Sensor *green_sensor)
Definition: tcs34725.h:47
AlsGain501 gain
void set_illuminance_sensor(sensor::Sensor *illuminance_sensor)
Definition: tcs34725.h:49
void set_gain(TCS34725Gain gain)
Definition: tcs34725.cpp:323
void set_blue_sensor(sensor::Sensor *blue_sensor)
Definition: tcs34725.h:48
No error found during execution of method.
Definition: i2c_bus.h:13
sensor::Sensor * color_temperature_sensor_
Definition: tcs34725.h:75
IntegrationTime501 integration_time
void set_red_sensor(sensor::Sensor *red_sensor)
Definition: tcs34725.h:46
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
float get_setup_priority() const override
Definition: tcs34725.cpp:60
sensor::Sensor * illuminance_sensor_
Definition: tcs34725.h:74
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
i2c::ErrorCode read_data_register_(uint8_t a_register, uint16_t &data)
Definition: tcs34725.h:60
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition: i2c_bus.h:11
Base-class for all sensors.
Definition: sensor.h:57
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133