75void TCS34725Component::calculate_temperature_and_lux_(uint16_t r, uint16_t g, uint16_t b, uint16_t c) {
191 ESP_LOGW(TAG,
"Error reading TCS34725 sensor data");
201 ESP_LOGV(TAG,
"Raw values clear=%d red=%d green=%d blue=%d", raw_c, raw_r, raw_g, raw_b);
209 channel_c = channel_r = channel_g = channel_b = 0.0f;
213 channel_r = raw_r / sum * 100.0f;
214 channel_g = raw_g / sum * 100.0f;
215 channel_b = raw_b / sum * 100.0f;
216 channel_c = raw_c / max_count * 100.0f;
229 calculate_temperature_and_lux_(raw_r, raw_g, raw_b, raw_c);
246 "Got Red=%.1f%%,Green=%.1f%%,Blue=%.1f%%,Clear=%.1f%% Illuminance=%.1flx Color "
253 float integration_time_ideal;
255 integration_time_ideal = 60 / ((float) std::max((uint16_t) 1, raw_c) / 655.35f) * this->
integration_time_;
257 uint8_t gain_reg_val_new = this->gain_reg_;
261 if (this->gain_reg_ < 3) {
263 gain_reg_val_new = this->gain_reg_ + 1;
265 integration_time_ideal = integration_time_ideal / 4;
270 if (this->gain_reg_ > 0) {
272 gain_reg_val_new = this->gain_reg_ - 1;
274 integration_time_ideal = integration_time_ideal * 4;
279 float integration_time_next = integration_time_ideal;
280 if (integration_time_ideal > 2.4f * 256) {
281 integration_time_next = 2.4f * 256;
283 if (integration_time_ideal < 154) {
284 integration_time_next = 154;
288 uint8_t regval_atime = (uint8_t) (256.f - integration_time_next / 2.4f);
289 ESP_LOGD(TAG,
"Integration time: %.1fms, ideal: %.1fms regval_new %d Gain: %.f Clear channel raw: %d gain reg: %d",
292 if (this->integration_reg_ != regval_atime || gain_reg_val_new != this->gain_reg_) {
293 this->integration_reg_ = regval_atime;
294 this->gain_reg_ = gain_reg_val_new;
299 ESP_LOGW(TAG,
"TCS34725I update timing failed!");