74void TCS34725Component::calculate_temperature_and_lux_(uint16_t r, uint16_t g, uint16_t b, uint16_t c) {
190 ESP_LOGW(TAG,
"Error reading TCS34725 sensor data");
200 ESP_LOGV(TAG,
"Raw values clear=%d red=%d green=%d blue=%d", raw_c, raw_r, raw_g, raw_b);
208 channel_c = channel_r = channel_g = channel_b = 0.0f;
212 channel_r = raw_r / sum * 100.0f;
213 channel_g = raw_g / sum * 100.0f;
214 channel_b = raw_b / sum * 100.0f;
215 channel_c = raw_c / max_count * 100.0f;
228 calculate_temperature_and_lux_(raw_r, raw_g, raw_b, raw_c);
245 "Got Red=%.1f%%,Green=%.1f%%,Blue=%.1f%%,Clear=%.1f%% Illuminance=%.1flx Color "
252 float integration_time_ideal;
254 integration_time_ideal = 60 / ((float) std::max((uint16_t) 1, raw_c) / 655.35f) * this->
integration_time_;
256 uint8_t gain_reg_val_new = this->gain_reg_;
260 if (this->gain_reg_ < 3) {
262 gain_reg_val_new = this->gain_reg_ + 1;
264 integration_time_ideal = integration_time_ideal / 4;
269 if (this->gain_reg_ > 0) {
271 gain_reg_val_new = this->gain_reg_ - 1;
273 integration_time_ideal = integration_time_ideal * 4;
278 float integration_time_next = integration_time_ideal;
279 if (integration_time_ideal > 2.4f * 256) {
280 integration_time_next = 2.4f * 256;
282 if (integration_time_ideal < 154) {
283 integration_time_next = 154;
287 uint8_t regval_atime = (uint8_t) (256.f - integration_time_next / 2.4f);
288 ESP_LOGD(TAG,
"Integration time: %.1fms, ideal: %.1fms regval_new %d Gain: %.f Clear channel raw: %d gain reg: %d",
291 if (this->integration_reg_ != regval_atime || gain_reg_val_new != this->gain_reg_) {
292 this->integration_reg_ = regval_atime;
293 this->gain_reg_ = gain_reg_val_new;
298 ESP_LOGW(TAG,
"TCS34725I update timing failed!");