Implement full color remapper

This commit is contained in:
netpok 2019-02-24 21:03:33 +01:00
parent 0a4a21a038
commit 945e7000dd
3 changed files with 27 additions and 25 deletions

View File

@ -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);

View File

@ -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

View File

@ -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<uint8_t> 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++) {