Added new auto white modes (related to #573 )

This commit is contained in:
cschwinne 2020-02-20 00:45:09 +01:00
parent 05f5aaaeca
commit 65a32b4166
13 changed files with 2526 additions and 2494 deletions

View File

@ -28,6 +28,7 @@
#define WS2812FX_h #define WS2812FX_h
#include "NpbWrapper.h" #include "NpbWrapper.h"
#include "const.h"
#define FASTLED_INTERNAL //remove annoying pragma messages #define FASTLED_INTERNAL //remove annoying pragma messages
#include "FastLED.h" #include "FastLED.h"
@ -426,6 +427,7 @@ class WS2812FX {
uint8_t uint8_t
mainSegment = 0, mainSegment = 0,
rgbwMode = RGBW_MODE_DUAL,
paletteFade = 0, paletteFade = 0,
paletteBlend = 0, paletteBlend = 0,
colorOrder = 0, colorOrder = 0,
@ -589,7 +591,7 @@ class WS2812FX {
void fill(uint32_t); void fill(uint32_t);
bool bool
_rgbwMode, _useRgbw = false,
_cronixieMode, _cronixieMode,
_cronixieBacklightEnabled, _cronixieBacklightEnabled,
_skipFirstMode, _skipFirstMode,

View File

@ -32,9 +32,9 @@
void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst) void WS2812FX::init(bool supportWhite, uint16_t countPixels, bool skipFirst)
{ {
if (supportWhite == _rgbwMode && countPixels == _length) return; if (supportWhite == _useRgbw && countPixels == _length) return;
RESET_RUNTIME; RESET_RUNTIME;
_rgbwMode = supportWhite; _useRgbw = supportWhite;
_skipFirstMode = skipFirst; _skipFirstMode = skipFirst;
_length = countPixels; _length = countPixels;
@ -65,6 +65,7 @@ void WS2812FX::service() {
{ {
if(nowUp > SEGENV.next_time || _triggered || (doShow && SEGMENT.mode == 0)) //last is temporary if(nowUp > SEGENV.next_time || _triggered || (doShow && SEGMENT.mode == 0)) //last is temporary
{ {
if (SEGMENT.grouping == 0) SEGMENT.grouping = 1; //sanity check
_virtualSegmentLength = SEGMENT.virtualLength(); _virtualSegmentLength = SEGMENT.virtualLength();
doShow = true; doShow = true;
handle_palette(); handle_palette();
@ -106,6 +107,20 @@ uint16_t WS2812FX::realPixelIndex(uint16_t i) {
void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w) void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w)
{ {
//auto calculate white channel value if enabled
if (_useRgbw) {
if (rgbwMode == RGBW_MODE_AUTO_BRIGHTER || (w == 0 && (rgbwMode == RGBW_MODE_DUAL || rgbwMode == RGBW_MODE_LEGACY)))
{
//white value is set to lowest RGB channel
//thank you to @Def3nder!
w = r < g ? (r < b ? r : b) : (g < b ? g : b);
} else if (rgbwMode == RGBW_MODE_AUTO_ACCURATE && w == 0)
{
w = r < g ? (r < b ? r : b) : (g < b ? g : b);
r -= w; g -= w; b -= w;
}
}
RgbwColor col; RgbwColor col;
switch (colorOrder) switch (colorOrder)
{ {
@ -256,7 +271,7 @@ void WS2812FX::show(void) {
} }
if (_rgbwMode) //RGBW led total output with white LEDs enabled is still 50mA, so each channel uses less if (_useRgbw) //RGBW led total output with white LEDs enabled is still 50mA, so each channel uses less
{ {
powerSum *= 3; powerSum *= 3;
powerSum = powerSum >> 2; //same as /= 4 powerSum = powerSum >> 2; //same as /= 4

View File

@ -3,10 +3,17 @@
//Access point behavior //Access point behavior
#define AP_BEHAVIOR_BOOT_NO_CONN 0 //Open AP when no connection after boot #define AP_BEHAVIOR_BOOT_NO_CONN 0 //Open AP when no connection after boot
#define AP_BEHAVIOR_NO_CONN 1 //Open when no connection #define AP_BEHAVIOR_NO_CONN 1 //Open when no connection (either after boot or if connection is lost)
#define AP_BEHAVIOR_ALWAYS 2 //Always open #define AP_BEHAVIOR_ALWAYS 2 //Always open
#define AP_BEHAVIOR_BUTTON_ONLY 3 //Only when button pressed for 6 sec #define AP_BEHAVIOR_BUTTON_ONLY 3 //Only when button pressed for 6 sec
//RGB to RGBW conversion mode
#define RGBW_MODE_MANUAL_ONLY 0 //No automatic white channel calculation. Manual white channel slider
#define RGBW_MODE_AUTO_BRIGHTER 1 //New algorithm. Adds as much white as the darkest RGBW channel
#define RGBW_MODE_AUTO_ACCURATE 2 //New algorithm. Adds as much white as the darkest RGBW channel and subtracts this amount from each RGB channel
#define RGBW_MODE_DUAL 3 //Manual slider + auto calculation. Automatically calculates only if manual slider is set to off (0)
#define RGBW_MODE_LEGACY 4 //Old floating algorithm. Too slow for realtime and palette support
//realtime modes //realtime modes
#define REALTIME_MODE_INACTIVE 0 #define REALTIME_MODE_INACTIVE 0
#define REALTIME_MODE_GENERIC 1 #define REALTIME_MODE_GENERIC 1

File diff suppressed because one or more lines are too long

View File

@ -118,7 +118,15 @@ LED voltage (Max. current for a single LED):<br>
<br> <br>
LEDs are 4-channel type (RGBW): <input type=checkbox name=EW onchange=UI() id=rgbw><br> LEDs are 4-channel type (RGBW): <input type=checkbox name=EW onchange=UI() id=rgbw><br>
<span class=wc> <span class=wc>
Auto-calculate white channel from RGB: <input type=checkbox name=AW><br></span> Auto-calculate white channel from RGB:<br>
<select name=AW>
<option value=0>None</option>
<option value=1>Brighter</option>
<option value=2>Accurate</option>
<option value=3>Dual</option>
<option value=4>Legacy</option>
</select>
<br></span>
Color order: Color order:
<select name=CO> <select name=CO>
<option value=0>GRB</option> <option value=0>GRB</option>

File diff suppressed because it is too large Load Diff

View File

@ -91,7 +91,7 @@
#endif #endif
//version code in format yymmddb (b = daily build) //version code in format yymmddb (b = daily build)
#define VERSION 2002191 #define VERSION 2002192
char versionString[] = "0.9.1"; char versionString[] = "0.9.1";
@ -124,7 +124,6 @@ IPAddress staticSubnet(255, 255, 255, 0); //most common subnet in home netwo
//LED CONFIG //LED CONFIG
uint16_t ledCount = 30; //overcurrent prevented by ABL uint16_t ledCount = 30; //overcurrent prevented by ABL
bool useRGBW = false; //SK6812 strips can contain an extra White channel bool useRGBW = false; //SK6812 strips can contain an extra White channel
bool autoRGBtoRGBW = false; //if RGBW enabled, calculate White channel from RGB
#define ABL_MILLIAMPS_DEFAULT 850; //auto lower brightness to stay close to milliampere limit #define ABL_MILLIAMPS_DEFAULT 850; //auto lower brightness to stay close to milliampere limit
bool turnOnAtBoot = true; //turn on LEDs at power-up bool turnOnAtBoot = true; //turn on LEDs at power-up
byte bootPreset = 0; //save preset to load after power-up byte bootPreset = 0; //save preset to load after power-up

View File

@ -218,7 +218,7 @@ void saveSettingsToEEPROM()
EEPROM.write(2200, !receiveDirect); EEPROM.write(2200, !receiveDirect);
EEPROM.write(2201, notifyMacro); //was enableRealtime EEPROM.write(2201, notifyMacro); //was enableRealtime
EEPROM.write(2203, autoRGBtoRGBW); EEPROM.write(2203, strip.rgbwMode);
EEPROM.write(2204, skipFirstLed); EEPROM.write(2204, skipFirstLed);
if (saveCurrPresetCycConf) if (saveCurrPresetCycConf)
@ -488,7 +488,7 @@ void loadSettingsFromEEPROM(bool first)
receiveDirect = !EEPROM.read(2200); receiveDirect = !EEPROM.read(2200);
notifyMacro = EEPROM.read(2201); notifyMacro = EEPROM.read(2201);
autoRGBtoRGBW = EEPROM.read(2203); strip.rgbwMode = EEPROM.read(2203);
skipFirstLed = EEPROM.read(2204); skipFirstLed = EEPROM.read(2204);
if (EEPROM.read(2210) || EEPROM.read(2211) || EEPROM.read(2212)) if (EEPROM.read(2210) || EEPROM.read(2211) || EEPROM.read(2212))

View File

@ -46,7 +46,7 @@ char* XML_response(AsyncWebServerRequest *request, char* dest = nullptr)
oappend("</ix><fp>"); oappend("</ix><fp>");
oappendi(effectPalette); oappendi(effectPalette);
oappend("</fp><wv>"); oappend("</fp><wv>");
if (useRGBW && !autoRGBtoRGBW) { if (strip.rgbwMode) {
oappendi(col[3]); oappendi(col[3]);
} else { } else {
oappend("-1"); oappend("-1");
@ -238,7 +238,7 @@ void getSettingsJS(byte subPage, char* dest)
sappend('v',"CA",briS); sappend('v',"CA",briS);
sappend('c',"EW",useRGBW); sappend('c',"EW",useRGBW);
sappend('i',"CO",strip.colorOrder); sappend('i',"CO",strip.colorOrder);
sappend('c',"AW",autoRGBtoRGBW); sappend('v',"AW",strip.rgbwMode);
sappend('c',"BO",turnOnAtBoot); sappend('c',"BO",turnOnAtBoot);
sappend('v',"BP",bootPreset); sappend('v',"BP",bootPreset);

View File

@ -77,7 +77,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
useRGBW = request->hasArg("EW"); useRGBW = request->hasArg("EW");
strip.colorOrder = request->arg("CO").toInt(); strip.colorOrder = request->arg("CO").toInt();
autoRGBtoRGBW = request->hasArg("AW"); strip.rgbwMode = request->arg("AW").toInt();
briS = request->arg("CA").toInt(); briS = request->arg("CA").toInt();

View File

@ -47,7 +47,7 @@ void setAllLeds() {
colSecT[i] = colSec[i]; colSecT[i] = colSec[i];
} }
} }
if (useRGBW && autoRGBtoRGBW) if (useRGBW && strip.rgbwMode == RGBW_MODE_LEGACY)
{ {
colorRGBtoRGBW(colT); colorRGBtoRGBW(colT);
colorRGBtoRGBW(colSecT); colorRGBtoRGBW(colSecT);

View File

@ -183,7 +183,7 @@ float maxf (float v, float w)
return v; return v;
} }
void colorRGBtoRGBW(byte* rgb) //rgb to rgbw (http://codewelt.com/rgbw) void colorRGBtoRGBW(byte* rgb) //rgb to rgbw (http://codewelt.com/rgbw). (RGBW_MODE_LEGACY)
{ {
float low = minf(rgb[0],minf(rgb[1],rgb[2])); float low = minf(rgb[0],minf(rgb[1],rgb[2]));
float high = maxf(rgb[0],maxf(rgb[1],rgb[2])); float high = maxf(rgb[0],maxf(rgb[1],rgb[2]));

View File

@ -242,7 +242,7 @@ void serializeInfo(JsonObject root)
JsonObject leds = root.createNestedObject("leds"); JsonObject leds = root.createNestedObject("leds");
leds["count"] = ledCount; leds["count"] = ledCount;
leds["rgbw"] = useRGBW; leds["rgbw"] = useRGBW;
leds["wv"] = useRGBW && !autoRGBtoRGBW; //should a white channel slider be displayed? leds["wv"] = useRGBW && (strip.rgbwMode == RGBW_MODE_MANUAL_ONLY || strip.rgbwMode == RGBW_MODE_DUAL); //should a white channel slider be displayed?
JsonArray leds_pin = leds.createNestedArray("pin"); JsonArray leds_pin = leds.createNestedArray("pin");
leds_pin.add(LEDPIN); leds_pin.add(LEDPIN);