Moved Philips-Xiaomi special handling to a better location

This commit is contained in:
Stephan Hadinger 2019-05-05 18:18:20 +02:00
parent 8144402536
commit e23f933cde

View File

@ -883,12 +883,6 @@ public:
light_current_color[0] = light_current_color[1] = light_current_color[2] = 0;
light_current_color[3] = light_current_color[4] = 0;
if (PHILIPS == my_module_type) {
// Xiaomi Philips bulbs follow a different scheme:
// channel 0=intensity, channel2=temperature
light_current_color[0] = briRGB; // set brightness
light_current_color[1] = c;
} else {
switch (light_subtype) {
case LST_NONE:
light_current_color[0] = 255;
@ -916,7 +910,6 @@ public:
break;
}
}
}
void changeHSB(uint16_t hue, uint8_t sat, uint8_t briRGB) {
_state->setHS(hue, sat);
@ -1779,6 +1772,21 @@ void LightAnimate(void)
cur_col_10bits[i] = changeUIntScale(cur_col[i], 0, 255, 0, 1023);
}
if (PHILIPS == my_module_type) {
// TODO
// Xiaomi Philips bulbs follow a different scheme:
// channel 0=intensity, channel2=temperature
uint16_t pxBri = cur_col[0] + cur_col[1];
if (pxBri > 255) { pxBri = 255; }
//cur_col[1] = cur_col[0]; // get 8 bits CT from WC -- not really used
cur_col_10bits[1] = changeUIntScale(cur_col[0], 0, pxBri, 0, 1023); // get 10 bits CT from WC / (WC+WW)
if (Settings.light_correction) { // gamma correction
cur_col_10bits[0] = ledGamma(pxBri, 10); // 10 bits gamma correction
} else {
cur_col_10bits[0] = changeUIntScale(pxBri, 0, 255, 0, 1023); // no gamma, extend to 10 bits
}
} else {
// Apply gamma correction for 8 and 10 bits resolutions, if needed
if (Settings.light_correction) {
// first apply gamma correction to all channels independently, from 8 bits value
@ -1807,14 +1815,17 @@ void LightAnimate(void)
cur_col[i] = ledGamma(cur_col[i]);
}
}
}
// final adjusments for PMW, post-gamma correction
for (uint8_t i = 0; i < LST_MAX; i++) {
#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
// Fix unwanted blinking and PWM watchdog errors for values close to pwm_range (H801, Arilux and BN-SZ01)
// but keep value 1023 if full range (PWM will be deactivated in this case)
if ((cur_col_10bits[i] > 1008) && (cur_col_10bits[i] < 1023)) {
cur_col_10bits[i] = 1008;
}
#endif
// scale from 0..1023 to 0..pwm_range, but keep any non-zero value to at least 1
cur_col_10bits[i] = (cur_col_10bits[i] > 0) ? changeUIntScale(cur_col_10bits[i], 1, 1023, 1, Settings.pwm_range) : 0;
}