From a20d577f6c97d20b03c8715a65d5902d1aa8ee2d Mon Sep 17 00:00:00 2001 From: cschwinne Date: Wed, 28 Nov 2018 12:24:32 +0100 Subject: [PATCH] WS2812b Color Order changeable in settings Meteor effect can now use palettes --- wled00/NpbWrapper.h | 16 +++------- wled00/WS2812FX.cpp | 56 +++++++++++++++++++++++++--------- wled00/WS2812FX.h | 2 ++ wled00/data/settings_leds.htm | Bin 9734 -> 10124 bytes wled00/html_settings.h | 7 +++++ wled00/wled00.ino | 2 +- wled00/wled01_eeprom.ino | 2 ++ wled00/wled02_xml.ino | 1 + wled00/wled03_set.ino | 1 + 9 files changed, 60 insertions(+), 27 deletions(-) diff --git a/wled00/NpbWrapper.h b/wled00/NpbWrapper.h index 1bbe6d66..794f7ceb 100644 --- a/wled00/NpbWrapper.h +++ b/wled00/NpbWrapper.h @@ -12,9 +12,6 @@ #define AUXPIN 15 //unused auxiliary output pin -//uncomment this if red and green are swapped -//#define SWAPRG - //automatically uses the right driver method for each platform #ifdef ARDUINO_ARCH_ESP32 @@ -36,14 +33,11 @@ #endif #endif -//handle swapping Red and Green automatically -#ifdef SWAPRG - #define PIXELFEATURE3 NeoRgbFeature - #define PIXELFEATURE4 NeoRgbwFeature -#else - #define PIXELFEATURE3 NeoGrbFeature - #define PIXELFEATURE4 NeoGrbwFeature -#endif + +//you can now change the color order in the web settings +#define PIXELFEATURE3 NeoGrbFeature +#define PIXELFEATURE4 NeoGrbwFeature + #include diff --git a/wled00/WS2812FX.cpp b/wled00/WS2812FX.cpp index 531f6d04..a0416773 100644 --- a/wled00/WS2812FX.cpp +++ b/wled00/WS2812FX.cpp @@ -93,7 +93,7 @@ void WS2812FX::clear() bool WS2812FX::modeUsesLock(uint8_t m) { - if (m == FX_MODE_FIRE_2012 || m == FX_MODE_COLORTWINKLE) return true; + if (m == FX_MODE_FIRE_2012 || m == FX_MODE_COLORTWINKLE || m == FX_MODE_METEOR) return true; return false; } @@ -241,6 +241,7 @@ void WS2812FX::setSecondaryColor(uint32_t c) { } void WS2812FX::setBrightness(uint8_t b) { + if (_brightness == b) return; _brightness = b; bus->SetBrightness(_brightness); show(); @@ -294,7 +295,15 @@ uint32_t WS2812FX::getPixelColor(uint16_t i) } } RgbwColor lColor = bus->GetPixelColorRgbw(i); - return lColor.W*16777216 + lColor.R*65536 + lColor.G*256 + lColor.B; + byte r = lColor.R, g = lColor.G, b = lColor.B; + switch (colorOrder) + { + case 0: break; //0 = Grb + case 1: r = lColor.G; g = lColor.R; break; //1 = Rgb, common for WS2811 + case 2: g = lColor.B; b = lColor.G; break; //2 = Brg + case 3: r = lColor.B; g = lColor.R; b = lColor.G; //3 = Rbg + } + return ( (lColor.W << 24) | (r << 16) | (g << 8) | (b) ); } WS2812FX::Segment WS2812FX::getSegment(void) { @@ -2157,8 +2166,11 @@ void WS2812FX::handle_palette(void) { bool singleSegmentMode = (_segment_index == _segment_index_palette_last); _segment_index_palette_last = _segment_index; + + byte paletteIndex = SEGMENT.palette; + if (SEGMENT.mode == FX_MODE_METEOR && SEGMENT.palette == 0) paletteIndex = 4; - switch (SEGMENT.palette) + switch (paletteIndex) { case 0: {//default palette. Differs depending on effect switch (SEGMENT.mode) @@ -2566,30 +2578,44 @@ uint16_t WS2812FX::mode_lake() { return 33; } -// meteor effect -// send a meteor from begining to to the end of the strip with a trail that randomly decay. -// adapted from https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectMeteorRain +// meteor effect +// send a meteor from begining to to the end of the strip with a trail that randomly decays. +// adapted from https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectMeteorRain uint16_t WS2812FX::mode_meteor() { - byte meteorSize=1+(256-SEGMENT.intensity)/16; - uint32_t led_offset = SEGMENT_RUNTIME.counter_mode_step; - uint16_t i = SEGMENT.start + led_offset; - byte meteorTrailDecay=SEGMENT.intensity; + byte meteorSize= 1+ SEGMENT_LENGTH / 10; + uint16_t in = SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step; + + byte decayProb = 255 - SEGMENT.intensity; // fade all leds to colors[1] in LEDs one step for (uint16_t i = SEGMENT.start; i <= SEGMENT.stop; i++) { - if (random(10)>5) { - setPixelColor(i,color_blend(getPixelColor(i),SEGMENT.colors[1],meteorTrailDecay)); + if (random8() <= decayProb) + { + byte meteorTrailDecay = 128 + random8(127); + _locked[i] = scale8(_locked[i], meteorTrailDecay); + setPixelColor(i, color_from_palette(_locked[i], false, true, 255)); } } // draw meteor - for(int j = 0; j < meteorSize; j++) { - if( ( SEGMENT.start + j < SEGMENT.stop) ) { - setPixelColor(i+j, SEGMENT.colors[0]); + for(int j = 0; j < meteorSize; j++) { + uint16_t index = in + j; + if(in + j > SEGMENT.stop) { + index = SEGMENT.start + (in + j - SEGMENT.stop) -1; } + + _locked[index] = 240; + setPixelColor(index, color_from_palette(_locked[index], false, true, 255)); } SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % (SEGMENT_LENGTH); return SPEED_FORMULA_L; } + +//smooth +//front ramping (maybe from get color +//50fps +//fade each led by a certain range (even ramp possible for sparkling) +//maybe dim to color[1] at end? +//_locked 0-15 bg-last 15-240 last-first 240-255 first-bg diff --git a/wled00/WS2812FX.h b/wled00/WS2812FX.h index a15652ce..76e48e32 100644 --- a/wled00/WS2812FX.h +++ b/wled00/WS2812FX.h @@ -165,6 +165,8 @@ #define FX_MODE_COLORTWINKLE 74 #define FX_MODE_LAKE 75 #define FX_MODE_METEOR 76 +#define FX_MODE_SMOOTH_METEOR 77 +#define FX_MODE_RAILROAD_X 78 class WS2812FX { diff --git a/wled00/data/settings_leds.htm b/wled00/data/settings_leds.htm index 0573c494522ffdebe82f5558aac6f449c139ca15..a91ea5a9789b741970571eed0448b6763037a5a5 100644 GIT binary patch delta 114 zcmZqk>G9tn!Y}H~kk60<#6=7WU^0avm7!?zd_{FuX9j-;rO6AGw7Cr!lo;$7+!=xx uoF-3HvgS4f^MimQAig836Hvw-EMp9naRT$DC)X(}O}--~uvvxwkr)8M7#e~A delta 12 TcmeD2Z}Zt8!oPWzz$Y;PAYcUM diff --git a/wled00/html_settings.h b/wled00/html_settings.h index 2ccebbf2..19437e2c 100644 --- a/wled00/html_settings.h +++ b/wled00/html_settings.h @@ -96,6 +96,13 @@ const char PAGE_settings_leds1[] PROGMEM = R"=====(

LED setup

LED count:
LEDs are 4-channel type (RGBW):
+Color order: +

Apply preset at boot (0 uses defaults)
Turn on after power up/reset:
diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 1e986d48..20268837 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -74,7 +74,7 @@ //version code in format yymmddb (b = daily build) -#define VERSION 1811241 +#define VERSION 1811253 char versionString[] = "0.8.2-dev"; diff --git a/wled00/wled01_eeprom.ino b/wled00/wled01_eeprom.ino index 3edcf2e0..66a127c5 100644 --- a/wled00/wled01_eeprom.ino +++ b/wled00/wled01_eeprom.ino @@ -142,6 +142,7 @@ void saveSettingsToEEPROM() EEPROM.write(380, colSecS[2]); EEPROM.write(381, whiteSecS); EEPROM.write(382, strip.paletteBlend); + EEPROM.write(383, strip.colorOrder); EEPROM.write(385, irEnabled); @@ -452,6 +453,7 @@ void loadSettingsFromEEPROM(bool first) readStringFromEEPROM(2300, mqttServer, 32); readStringFromEEPROM(2333, mqttDeviceTopic, 32); readStringFromEEPROM(2366, mqttGroupTopic, 32); + strip.colorOrder = EEPROM.read(383); } receiveDirect = !EEPROM.read(2200); diff --git a/wled00/wled02_xml.ino b/wled00/wled02_xml.ino index 1730a6ef..2fef1d72 100644 --- a/wled00/wled02_xml.ino +++ b/wled00/wled02_xml.ino @@ -196,6 +196,7 @@ void getSettingsJS(byte subPage) sappend('v',"CB",colS[2]); sappend('v',"CA",briS); sappend('c',"EW",useRGBW); + sappend('i',"CO",strip.colorOrder); sappend('c',"AW",autoRGBtoRGBW); sappend('v',"CW",whiteS); sappend('v',"SR",colSecS[0]); diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index c0a662a7..0967aed7 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -60,6 +60,7 @@ void handleSettingsSet(byte subPage) if (ledCount > 600) ledCount = 600; #endif useRGBW = server.hasArg("EW"); + strip.colorOrder = server.arg("CO").toInt(); autoRGBtoRGBW = server.hasArg("AW"); //ignore settings and save current brightness, colors and fx as default