From 0ab3ba6fabd0b49834be27675ea8384a28bdeca8 Mon Sep 17 00:00:00 2001 From: Hadinger Date: Thu, 2 Jan 2020 22:36:27 +0100 Subject: [PATCH 1/4] Fix wrong gamma correction for Module 48 lights (PWM5 for CT) --- tasmota/CHANGELOG.md | 1 + tasmota/xdrv_04_light.ino | 66 +++++++++++++++++---------------------- 2 files changed, 29 insertions(+), 38 deletions(-) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 676822799..fff26d0c8 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -9,6 +9,7 @@ - Fix LCD line and column positioning (#7387) - Fix Display handling of hexadecimal escape characters (#7387) - Fix Improved fade linearity with gamma correction +- Fix wrong gamma correction for Module 48 lights (PWM5 for CT) ### 8.1.0.1 20191225 diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index 9566c4c92..600642bfe 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -1709,9 +1709,6 @@ void LightAnimate(void) calcGammaMultiChannels(cur_col_10); } else { calcGammaBulbs(cur_col_10); - if (PHILIPS == my_module_type) { - calcGammaCTPwm(cur_col_10); - } // Now see if we need to mix RGB and True White // Valid only for LST_RGBW, LST_RGBWC, rgbwwTable[4] is zero, and white is zero (see doc) @@ -1941,26 +1938,6 @@ void LightSetOutputs(const uint16_t *cur_col_10) { XdrvMailbox.topic = tmp_topic; } -// Do specific computation is SetOption73 is on, Color Temp is a separate PWM channel -void calcGammaCTPwm(uint16_t cur_col_10[5]) { - // Xiaomi Philips bulbs follow a different scheme: - uint8_t cold, warm; // channel 1 is the color tone, mapped to cold channel (0..255) - light_state.getCW(&cold, &warm); - // channels for white are always the last two channels - uint32_t cw1 = Light.subtype - 1; // address for the ColorTone PWM - uint32_t cw0 = Light.subtype - 2; // address for the White Brightness PWM - // overall brightness - uint16_t pxBri10 = cur_col_10[cw0] + cur_col_10[cw1]; - if (pxBri10 > 1023) { pxBri10 = 1023; } - cur_col_10[cw1] = changeUIntScale(cold, 0, cold + warm, 0, 1023); // - // channel 0=intensity, channel1=temperature - if (Settings.light_correction) { // gamma correction - cur_col_10[cw0] = ledGamma10_10(pxBri10); // 10 bits gamma correction - } else { - cur_col_10[cw0] = pxBri10; // no gamma, extend to 10 bits - } -} - // Just apply basic Gamma to each channel void calcGammaMultiChannels(uint16_t cur_col_10[5]) { // Apply gamma correction for 8 and 10 bits resolutions, if needed @@ -1976,22 +1953,35 @@ void calcGammaBulbs(uint16_t cur_col_10[5]) { if (Settings.light_correction) { // First apply combined correction to the overall white power if ((LST_COLDWARM == Light.subtype) || (LST_RGBWC == Light.subtype)) { - uint8_t w_idx[2] = {0, 1}; // if LST_COLDWARM, channels 0 and 1 - if (LST_RGBWC == Light.subtype) { // if LST_RGBWC, channels 3 and 4 - w_idx[0] = 3; - w_idx[1] = 4; - } - uint16_t white_bri10 = cur_col_10[w_idx[0]] + cur_col_10[w_idx[1]]; - // if sum of both channels is > 255, then channels are probablu uncorrelated - if (white_bri10 <= 1023) { - // we calculate the gamma corrected sum of CW + WW - uint16_t white_bri_10bits = ledGamma10_10(white_bri10); - // then we split the total energy among the cold and warm leds - cur_col_10[w_idx[0]] = changeUIntScale(cur_col_10[w_idx[0]], 0, white_bri10, 0, white_bri_10bits); - cur_col_10[w_idx[1]] = changeUIntScale(cur_col_10[w_idx[1]], 0, white_bri10, 0, white_bri_10bits); + // channels for white are always the last two channels + uint32_t cw1 = Light.subtype - 1; // address for the ColorTone PWM + uint32_t cw0 = Light.subtype - 2; // address for the White Brightness PWM + uint16_t white_bri10 = cur_col_10[cw0] + cur_col_10[cw1]; // cumulated brightness + uint16_t white_bri10_1023 = (white_bri10 > 1023) ? 1023 : white_bri10; // max 1023 + + if (PHILIPS == my_module_type) { // channel 1 is the color tone, mapped to cold channel (0..255) + // Xiaomi Philips bulbs follow a different scheme: + uint8_t cold, warm; + light_state.getCW(&cold, &warm); + cur_col_10[cw1] = changeUIntScale(cold, 0, cold + warm, 0, 1023); // + // channel 0=intensity, channel1=temperature + if (Settings.light_correction) { // gamma correction + cur_col_10[cw0] = ledGamma10_10(white_bri10_1023); // 10 bits gamma correction + } else { + cur_col_10[cw0] = white_bri10_1023; // no gamma, extend to 10 bits + } } else { - cur_col_10[w_idx[0]] = ledGamma10_10(cur_col_10[w_idx[0]]); - cur_col_10[w_idx[1]] = ledGamma10_10(cur_col_10[w_idx[1]]); + // if sum of both channels is > 255, then channels are probably uncorrelated + if (white_bri10 <= 1031) { // take a margin of 8 above 1023 to account for rounding errors + // we calculate the gamma corrected sum of CW + WW + uint16_t white_bri_gamma10 = ledGamma10_10(white_bri10_1023); + // then we split the total energy among the cold and warm leds + cur_col_10[cw0] = changeUIntScale(cur_col_10[cw0], 0, white_bri10_1023, 0, white_bri_gamma10); + cur_col_10[cw1] = changeUIntScale(cur_col_10[cw1], 0, white_bri10_1023, 0, white_bri_gamma10); + } else { + cur_col_10[cw0] = ledGamma10_10(cur_col_10[cw0]); + cur_col_10[cw1] = ledGamma10_10(cur_col_10[cw1]); + } } } // then apply gamma correction to RGB channels From 5895637e9ab98c13fb653e0153e67522a50d7f23 Mon Sep 17 00:00:00 2001 From: Mark Furland Date: Thu, 2 Jan 2020 19:26:34 -0500 Subject: [PATCH 2/4] fix: http-uploader.py cross platform support, espupload.py executable --- pio/espupload.py | 0 pio/http-uploader.py | 8 ++------ 2 files changed, 2 insertions(+), 6 deletions(-) mode change 100644 => 100755 pio/espupload.py diff --git a/pio/espupload.py b/pio/espupload.py old mode 100644 new mode 100755 diff --git a/pio/http-uploader.py b/pio/http-uploader.py index dd563177f..88d5a23ce 100644 --- a/pio/http-uploader.py +++ b/pio/http-uploader.py @@ -1,4 +1,5 @@ Import("env") +import os # pio < 4.0.0 # from base64 import b64decode @@ -7,11 +8,6 @@ Import("env") # env.Replace(UPLOADCMD="$UPLOADER -u " + b64decode(ARGUMENTS.get("UPLOAD_PORT")) + " -f $SOURCES") # pio >= 4.0.0 -env.Replace(UPLOADER="pio\espupload.py") +env.Replace(UPLOADER=os.path.join("pio", "espupload.py")) env.Replace(UPLOADERFLAGS="") env.Replace(UPLOADCMD="$UPLOADER -u $UPLOAD_PORT -f $SOURCES") - -''' -env.Replace(UPLOADCMD="pio\espupload.py -f $SOURCES") # Windows -env.Replace(UPLOADCMD="pio/espupload.py -f $SOURCES") # Linux -''' \ No newline at end of file From 8078939d416db992d0e8c30c90d3443dba6aab6d Mon Sep 17 00:00:00 2001 From: Mark Furland Date: Thu, 2 Jan 2020 19:49:11 -0500 Subject: [PATCH 3/4] fix(platformio_override_sample): extra_scripts doesn't deal well with commas If you put commas in the extra_scripts, it seems to just ignore the script after the comma? Newlines work fine though --- platformio_override_sample.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platformio_override_sample.ini b/platformio_override_sample.ini index 9ac4084cd..45ab66897 100644 --- a/platformio_override_sample.ini +++ b/platformio_override_sample.ini @@ -59,12 +59,14 @@ extra_scripts = ${scripts_defaults.extra_scripts} ; *** Upload file to OTA server using SCP ;upload_port = user@host:/path ;extra_scripts = ${scripts_defaults.extra_scripts} -; pio/strip-floats.py, pio/sftp-uploader.py +; pio/strip-floats.py +; pio/sftp-uploader.py ; *** Upload file to OTA server in folder api/arduino using HTTP ;upload_port = domus1:80/api/upload-arduino.php ;extra_scripts = ${scripts_defaults.extra_scripts} -; pio/strip-floats.py, pio/http-uploader.py +; pio/strip-floats.py +; pio/http-uploader.py [core_active] ; Select one core set for platform and build_flags From d15969bd1ed855035e1cb462d7c80c4749039dfa Mon Sep 17 00:00:00 2001 From: Jan Penninkhof Date: Fri, 3 Jan 2020 10:07:42 +0100 Subject: [PATCH 4/4] Reset before initialisation of the SSD1306 when OLED reset pin is set If an OLED Reset pin has been selected using the PIN configuration, it makes sense to also send a reset signal to this pin before initialization of the display. The current value 0 doesn't send this signal, not even when a reset pin has been selected. Hence the change of value 0 into reset_pin >= 0. If no reset pin was set, the value of this variable is -1. --- tasmota/xdsp_02_ssd1306.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/xdsp_02_ssd1306.ino b/tasmota/xdsp_02_ssd1306.ino index 8cf938c6c..6060686b9 100644 --- a/tasmota/xdsp_02_ssd1306.ino +++ b/tasmota/xdsp_02_ssd1306.ino @@ -83,7 +83,7 @@ void SSD1306InitDriver(void) // init renderer // oled1306 = new Adafruit_SSD1306(SSD1306_LCDWIDTH,SSD1306_LCDHEIGHT); oled1306 = new Adafruit_SSD1306(Settings.display_width, Settings.display_height, &Wire, reset_pin); - oled1306->begin(SSD1306_SWITCHCAPVCC, Settings.display_address[0], 0); + oled1306->begin(SSD1306_SWITCHCAPVCC, Settings.display_address[0], reset_pin >= 0); renderer = oled1306; renderer->DisplayInit(DISPLAY_INIT_MODE, Settings.display_size, Settings.display_rotate, Settings.display_font); renderer->setTextColor(1,0);