From 945e7000dd0c925c637923d4b274cbe24e11bdf2 Mon Sep 17 00:00:00 2001 From: netpok Date: Sun, 24 Feb 2019 21:03:33 +0100 Subject: [PATCH] Implement full color remapper --- sonoff/settings.ino | 4 ---- sonoff/sonoff.h | 11 ----------- sonoff/xdrv_04_light.ino | 37 +++++++++++++++++++++++++++---------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/sonoff/settings.ino b/sonoff/settings.ino index c18d60d3f..2fb9a9afa 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -587,7 +587,6 @@ void SettingsDefaultSet2(void) // Settings.flag.stop_flash_rotate = 0; Settings.save_data = SAVE_DATA; Settings.param[P_BOOT_LOOP_OFFSET] = BOOT_LOOP_OFFSET; - Settings.param[P_RGB_REMAP] = RGB_REMAP_RGB; Settings.sleep = APP_SLEEP; if (Settings.sleep < 50) { Settings.sleep = 50; // Default to 50 for sleep, for now @@ -1056,9 +1055,6 @@ void SettingsDelta(void) if (Settings.version < 0x06040110) { ModuleDefault(WEMOS); } - if (Settings.version < 0x06040112) { - Settings.param[P_RGB_REMAP] = RGB_REMAP_RGB; - } Settings.version = VERSION; SettingsSave(1); diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index aafc98615..f83e7e390 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -171,17 +171,6 @@ typedef unsigned long power_t; // Power (Relay) type #define LT_SM16716 16 // Lights that use SM16716 will have this bit set in light_type -// Remap constants are 3-digit ternary numbers, each digit tells where the corresponding color component is mapped *from* -// digit 0 = ( n % 3) tells where the red is mapped from (0=red, 1=green, 2=blue) -// digit 1 = ((n/3) % 3) tells where the green is mapped from -// digit 2 = ((n/9) % 3) tells where the blue is mapped from -#define RGB_REMAP_RGB (0*1 + 1*3 + 2*9) -#define RGB_REMAP_RBG (0*1 + 2*3 + 1*9) -#define RGB_REMAP_GRB (1*1 + 0*3 + 2*9) -#define RGB_REMAP_GBR (1*1 + 2*3 + 0*9) -#define RGB_REMAP_BRG (2*1 + 0*3 + 1*9) -#define RGB_REMAP_BGR (2*1 + 1*3 + 0*9) - #define MQTT_PUBSUBCLIENT 1 // Mqtt PubSubClient library #define MQTT_TASMOTAMQTT 2 // Mqtt TasmotaMqtt library based on esp-mqtt-arduino - soon obsolete #define MQTT_ESPMQTTARDUINO 3 // Mqtt esp-mqtt-arduino library by Ingo Randolf - obsolete but define is present for debugging purposes diff --git a/sonoff/xdrv_04_light.ino b/sonoff/xdrv_04_light.ino index 54085a4ba..10ac7253f 100644 --- a/sonoff/xdrv_04_light.ino +++ b/sonoff/xdrv_04_light.ino @@ -86,6 +86,8 @@ struct LCwColor { #define MAX_FIXED_COLD_WARM 4 const LCwColor kFixedColdWarm[MAX_FIXED_COLD_WARM] PROGMEM = { 0,0, 255,0, 0,255, 128,128 }; +uint8_t remap[5]; + uint8_t ledTable[] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -563,6 +565,26 @@ void LightInit(void) light_power = 0; light_update = 1; light_wakeup_active = 0; + + uint8_t param = Settings.param[P_RGB_REMAP]; + if(param > 119){ + param = 119; + } + std::vector tmp = {0,1,2,3,4}; + remap[0] = tmp[param / 24]; + tmp.erase(tmp.begin() + (param / 24)); + param = param % 24; + remap[1] = tmp[(param / 6)]; + tmp.erase(tmp.begin() + (param / 6)); + param = param % 6; + remap[2] = tmp[(param / 2)]; + tmp.erase(tmp.begin() + (param / 2)); + param = param % 2; + remap[3] = tmp[param]; + remap[4] = tmp[1-param]; + + //snprintf_P(log_data, sizeof(log_data), "%d colors: %d %d %d %d %d",Settings.param[P_RGB_REMAP], remap[0],remap[1],remap[2],remap[3],remap[4]); + //AddLog(LOG_LEVEL_DEBUG); } void LightSetColorTemp(uint16_t ct) @@ -964,16 +986,11 @@ void LightAnimate(void) cur_col[i] = (Settings.light_correction) ? ledTable[cur_col[i]] : cur_col[i]; } - // RGB remapping - uint8_t rgb_mapping = Settings.param[P_RGB_REMAP]; - - if (rgb_mapping != RGB_REMAP_RGB) { - uint8_t orig_col[3]; - memcpy(orig_col, cur_col, sizeof(orig_col)); - for (uint8_t i = 0; i < 3; i++) { - cur_col[i] = orig_col[rgb_mapping % 3]; - rgb_mapping /= 3; - } + // color remapping + uint8_t orig_col[5]; + memcpy(orig_col, cur_col, sizeof(orig_col)); + for (uint8_t i = 0; i < 5; i++) { + cur_col[i] = orig_col[remap[i]]; } for (uint8_t i = 0; i < light_subtype; i++) {