73void TCS34725Component::calculate_temperature_and_lux_(uint16_t r, uint16_t g, uint16_t b, uint16_t c) {
189 ESP_LOGW(TAG,
"Error reading TCS34725 sensor data");
199 ESP_LOGV(TAG,
"Raw values clear=%d red=%d green=%d blue=%d", raw_c, raw_r, raw_g, raw_b);
207 channel_c = channel_r = channel_g = channel_b = 0.0f;
211 channel_r = raw_r / sum * 100.0f;
212 channel_g = raw_g / sum * 100.0f;
213 channel_b = raw_b / sum * 100.0f;
214 channel_c = raw_c / max_count * 100.0f;
227 calculate_temperature_and_lux_(raw_r, raw_g, raw_b, raw_c);
244 "Got Red=%.1f%%,Green=%.1f%%,Blue=%.1f%%,Clear=%.1f%% Illuminance=%.1flx Color "
251 float integration_time_ideal;
253 integration_time_ideal = 60 / ((float) std::max((uint16_t) 1, raw_c) / 655.35f) * this->
integration_time_;
255 uint8_t gain_reg_val_new = this->gain_reg_;
259 if (this->gain_reg_ < 3) {
261 gain_reg_val_new = this->gain_reg_ + 1;
263 integration_time_ideal = integration_time_ideal / 4;
268 if (this->gain_reg_ > 0) {
270 gain_reg_val_new = this->gain_reg_ - 1;
272 integration_time_ideal = integration_time_ideal * 4;
277 float integration_time_next = integration_time_ideal;
278 if (integration_time_ideal > 2.4f * 256) {
279 integration_time_next = 2.4f * 256;
281 if (integration_time_ideal < 154) {
282 integration_time_next = 154;
286 uint8_t regval_atime = (uint8_t) (256.f - integration_time_next / 2.4f);
287 ESP_LOGD(TAG,
"Integration time: %.1fms, ideal: %.1fms regval_new %d Gain: %.f Clear channel raw: %d gain reg: %d",
290 if (this->integration_reg_ != regval_atime || gain_reg_val_new != this->gain_reg_) {
291 this->integration_reg_ = regval_atime;
292 this->gain_reg_ = gain_reg_val_new;
297 ESP_LOGW(TAG,
"TCS34725I update timing failed!");