From 53f09c0630385049e0d1bad125513c707e493b78 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Sun, 22 Mar 2020 17:45:09 +0100 Subject: [PATCH] Moved Cronixie driver from FX library to drawOverlay handler --- CHANGELOG.md | 4 ++ wled00/FX.h | 7 --- wled00/FX_fcn.cpp | 117 +++++++------------------------------ wled00/wled00.ino | 2 +- wled00/wled03_set.ino | 6 -- wled00/wled11_ol.ino | 13 +++-- wled00/wled13_cronixie.ino | 43 +++++++++++--- 7 files changed, 69 insertions(+), 123 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 631162c7..321eea8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ### Development versions after 0.9.1 release +#### Build 2003221 + +- Moved Cronixie driver from FX library to drawOverlay handler + #### Build 2003211 - Added custom mapping compile define to FX_fcn.h diff --git a/wled00/FX.h b/wled00/FX.h index abb8c6f0..d24250f9 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -407,9 +407,6 @@ class WS2812FX { setColor(uint8_t slot, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0), setColor(uint8_t slot, uint32_t c), setBrightness(uint8_t b), - driverModeCronixie(bool b), - setCronixieDigits(byte* d), - setCronixieBacklight(bool b), setRange(uint16_t i, uint16_t i2, uint32_t col), setShowCallback(show_callback cb), setTransitionMode(bool t), @@ -597,13 +594,9 @@ class WS2812FX { bool _useRgbw = false, - _cronixieMode, - _cronixieBacklightEnabled, _skipFirstMode, _triggered; - byte _cronixieDigits[6]; - mode_ptr _mode[MODE_COUNT]; // SRAM footprint: 4 bytes per element show_callback _callback = nullptr; diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 7bc02def..05568623 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -147,90 +147,32 @@ void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w) } col.W = w; - if (!_cronixieMode) - { - uint16_t skip = _skipFirstMode ? LED_SKIP_AMOUNT : 0; - if (SEGLEN) {//from segment - /* Set all the pixels in the group, ensuring _skipFirstMode is honored */ - bool reversed = reverseMode ^ IS_REVERSE; - uint16_t realIndex = realPixelIndex(i); + uint16_t skip = _skipFirstMode ? LED_SKIP_AMOUNT : 0; + if (SEGLEN) {//from segment + /* Set all the pixels in the group, ensuring _skipFirstMode is honored */ + bool reversed = reverseMode ^ IS_REVERSE; + uint16_t realIndex = realPixelIndex(i); - for (uint16_t j = 0; j < SEGMENT.grouping; j++) { - int16_t indexSet = realIndex + (reversed ? -j : j); - int16_t indexSetRev = indexSet; - if (reverseMode) indexSetRev = _length - 1 - indexSet; - #ifdef WLED_CUSTOM_LED_MAPPING - if (indexSet < customMappingSize) indexSet = customMappingTable[indexSet]; - #endif - if (indexSetRev >= SEGMENT.start && indexSetRev < SEGMENT.stop) bus->SetPixelColor(indexSet + skip, col); - } - } else { //live data, etc. - if (reverseMode) i = _length - 1 - i; + for (uint16_t j = 0; j < SEGMENT.grouping; j++) { + int16_t indexSet = realIndex + (reversed ? -j : j); + int16_t indexSetRev = indexSet; + if (reverseMode) indexSetRev = _length - 1 - indexSet; #ifdef WLED_CUSTOM_LED_MAPPING - if (i < customMappingSize) i = customMappingTable[i]; + if (indexSet < customMappingSize) indexSet = customMappingTable[indexSet]; #endif - bus->SetPixelColor(i + skip, col); + if (indexSetRev >= SEGMENT.start && indexSetRev < SEGMENT.stop) bus->SetPixelColor(indexSet + skip, col); } - if (skip && i == 0) { - for (uint16_t j = 0; j < skip; j++) { - bus->SetPixelColor(j, RgbwColor(0, 0, 0, 0)); - } - } - return; + } else { //live data, etc. + if (reverseMode) i = _length - 1 - i; + #ifdef WLED_CUSTOM_LED_MAPPING + if (i < customMappingSize) i = customMappingTable[i]; + #endif + bus->SetPixelColor(i + skip, col); } - - //CRONIXIE - if(i>6)return; - byte o = 10*i; - if (_cronixieBacklightEnabled && _cronixieDigits[i] <11) - { - byte r2 = _segments[0].colors[1] >>16; - byte g2 = _segments[0].colors[1] >> 8; - byte b2 = _segments[0].colors[1]; - byte w2 = _segments[0].colors[1] >>24; - for (int j=o; j< o+19; j++) - { - bus->SetPixelColor(j, RgbwColor(r2,g2,b2,w2)); + if (skip && i == 0) { + for (uint16_t j = 0; j < skip; j++) { + bus->SetPixelColor(j, RgbwColor(0, 0, 0, 0)); } - } else - { - for (int j=o; j< o+19; j++) - { - bus->SetPixelColor(j, RgbwColor(0,0,0,0)); - } - } - if (_skipFirstMode) o += LED_SKIP_AMOUNT; - switch(_cronixieDigits[i]) - { - case 0: bus->SetPixelColor(o+5, col); break; - case 1: bus->SetPixelColor(o+0, col); break; - case 2: bus->SetPixelColor(o+6, col); break; - case 3: bus->SetPixelColor(o+1, col); break; - case 4: bus->SetPixelColor(o+7, col); break; - case 5: bus->SetPixelColor(o+2, col); break; - case 6: bus->SetPixelColor(o+8, col); break; - case 7: bus->SetPixelColor(o+3, col); break; - case 8: bus->SetPixelColor(o+9, col); break; - case 9: bus->SetPixelColor(o+4, col); break; - } -} - -void WS2812FX::driverModeCronixie(bool b) -{ - _cronixieMode = b; - _segments[0].stop = (b) ? 6 : _length; -} - -void WS2812FX::setCronixieBacklight(bool b) -{ - _cronixieBacklightEnabled = b; -} - -void WS2812FX::setCronixieDigits(byte d[]) -{ - for (int i = 0; i<6; i++) - { - _cronixieDigits[i] = d[i]; } } @@ -461,25 +403,6 @@ uint32_t WS2812FX::getPixelColor(uint16_t i) if (_skipFirstMode) i += LED_SKIP_AMOUNT; - if (_cronixieMode) - { - if(i>6)return 0; - byte o = 10*i; - switch(_cronixieDigits[i]) - { - case 0: i=o+5; break; - case 1: i=o+0; break; - case 2: i=o+6; break; - case 3: i=o+1; break; - case 4: i=o+7; break; - case 5: i=o+2; break; - case 6: i=o+8; break; - case 7: i=o+3; break; - case 8: i=o+9; break; - case 9: i=o+4; break; - default: return 0; - } - } if (i >= _lengthRaw) return 0; RgbwColor col = bus->GetPixelColorRgbw(i); diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 80f9d79b..55f714f5 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -119,7 +119,7 @@ #endif //version code in format yymmddb (b = daily build) -#define VERSION 2003211 +#define VERSION 2003221 char versionString[] = "0.9.1"; diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index 5a7f4db6..fc82256d 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -217,12 +217,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) analogClockSecondsTrail = request->hasArg("OS"); strcpy(cronixieDisplay,request->arg("CX").c_str()); - bool cbOld = cronixieBacklight; cronixieBacklight = request->hasArg("CB"); - if (cbOld != cronixieBacklight && overlayCurrent == 3) - { - strip.setCronixieBacklight(cronixieBacklight); overlayRefreshedTime = 0; - } countdownMode = request->hasArg("CE"); countdownYear = request->arg("CY").toInt(); countdownMonth = request->arg("CI").toInt(); @@ -656,7 +651,6 @@ bool handleSet(AsyncWebServerRequest *request, const String& req) if (pos > 0) //sets backlight { cronixieBacklight = (req.charAt(pos+3) != '0'); - if (overlayCurrent == 3) strip.setCronixieBacklight(cronixieBacklight); overlayRefreshedTime = 0; } #endif diff --git a/wled00/wled11_ol.ino b/wled00/wled11_ol.ino index cfe8a1f9..93f7b96d 100644 --- a/wled00/wled11_ol.ino +++ b/wled00/wled11_ol.ino @@ -6,13 +6,12 @@ void initCronixie() { if (overlayCurrent == 3 && !cronixieInit) { - strip.driverModeCronixie(true); - strip.setCronixieBacklight(cronixieBacklight); setCronixie(); + strip.getSegment(0).grouping = 10; //10 LEDs per digit cronixieInit = true; } else if (cronixieInit && overlayCurrent != 3) { - strip.driverModeCronixie(false); + strip.getSegment(0).grouping = 1; cronixieInit = false; } } @@ -120,6 +119,10 @@ void _overlayAnalogCountdown() void handleOverlayDraw() { - if (overlayCurrent != 1) return; //only analog clock - _overlayAnalogClock(); + if (!overlayCurrent) return; + switch (overlayCurrent) + { + case 1: _overlayAnalogClock(); break; + case 3: _drawOverlayCronixie(); break; + } } diff --git a/wled00/wled13_cronixie.ino b/wled00/wled13_cronixie.ino index 897c94f9..dd687ca1 100644 --- a/wled00/wled13_cronixie.ino +++ b/wled00/wled13_cronixie.ino @@ -1,6 +1,10 @@ /* * Support for the Cronixie clock */ +#ifndef WLED_DISABLE_CRONIXIE +byte _digitOut[6] = {10,10,10,10,10,10}; +#endif + byte getSameCodeLength(char code, int index, char const cronixieDisplay[]) { byte counter = 0; @@ -161,7 +165,6 @@ void _overlayCronixie() if (h>12) h-=12; else if (h==0) h+=12; } - byte _digitOut[]{10,10,10,10,10,10}; for (int i = 0; i < 6; i++) { if (dP[i] < 12) _digitOut[i] = dP[i]; @@ -184,8 +187,8 @@ void _overlayCronixie() case 37: _digitOut[i] = y/10; _digitOut[i+1] = y- _digitOut[i]*10; i++; break; //YY case 39: _digitOut[i] = 2; _digitOut[i+1] = 0; _digitOut[i+2] = y/10; _digitOut[i+3] = y- _digitOut[i+2]*10; i+=3; break; //YYYY - case 16: _digitOut[i+2] = ((h0/3)&1)?1:0; i++; //BBB (BBBB NI) - case 15: _digitOut[i+1] = (h0>17 || (h0>5 && h0<12))?1:0; i++; //BB + //case 16: _digitOut[i+2] = ((h0/3)&1)?1:0; i++; //BBB (BBBB NI) + //case 15: _digitOut[i+1] = (h0>17 || (h0>5 && h0<12))?1:0; i++; //BB case 14: _digitOut[i] = (h0>11)?1:0; break; //B } } else @@ -195,8 +198,8 @@ void _overlayCronixie() case 71: _digitOut[i] = h/10; _digitOut[i+1] = h- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //hh case 75: _digitOut[i] = m/10; _digitOut[i+1] = m- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //mm case 81: _digitOut[i] = s/10; _digitOut[i+1] = s- _digitOut[i]*10; if(_digitOut[i] == 0) _digitOut[i]=10; i++; break; //ss - case 66: _digitOut[i+2] = ((h0/3)&1)?1:10; i++; //bbb (bbbb NI) - case 65: _digitOut[i+1] = (h0>17 || (h0>5 && h0<12))?1:10; i++; //bb + //case 66: _digitOut[i+2] = ((h0/3)&1)?1:10; i++; //bbb (bbbb NI) + //case 65: _digitOut[i+1] = (h0>17 || (h0>5 && h0<12))?1:10; i++; //bb case 64: _digitOut[i] = (h0>11)?1:10; break; //b case 93: _digitOut[i] = weekday(local); _digitOut[i]--; if (_digitOut[i]<1) _digitOut[i]= 7; break; //d @@ -208,7 +211,33 @@ void _overlayCronixie() } } } - strip.setCronixieDigits(_digitOut); - //strip.trigger(); //this has a drawback, no effects slower than RefreshMs. advantage: Quick update, not dependant on effect time + #endif +} + +void _drawOverlayCronixie() +{ + #ifndef WLED_DISABLE_CRONIXIE + byte offsets[] = {5, 0, 6, 1, 7, 2, 8, 3, 9, 4}; + + for (uint16_t i = 0; i < 6; i++) + { + byte o = 10*i; + byte excl = 10; + if(_digitOut[i] < 10) excl = offsets[_digitOut[i]]; + excl += o; + + if (cronixieBacklight && _digitOut[i] <11) + { + uint32_t col = strip.gamma32(strip.getSegment(0).colors[1]); + for (uint16_t j=o; j< o+10; j++) { + if (j != excl) strip.setPixelColor(j, col); + } + } else + { + for (uint16_t j=o; j< o+10; j++) { + if (j != excl) strip.setPixelColor(j, 0); + } + } + } #endif }