From 5f59487a88ca85303ce6f1eaf2d6fed239603265 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Sat, 22 Sep 2018 22:49:24 +0200 Subject: [PATCH] Added basic Time Activated Macros function Fixed Cronixie overlay 512K Flash mode (temporarily) unavailable --- wled00/WS2812FX.cpp | 3 +-- wled00/data/settings_time.htm | Bin 12424 -> 15046 bytes wled00/htmls01.h | 20 ++++++++++++++++++-- wled00/wled00.ino | 13 +++++++++++-- wled00/wled01_eeprom.ino | 19 ++++++++++++++++++- wled00/wled02_xml.ino | 9 +++++++++ wled00/wled03_set.ino | 20 ++++++++++++++++++-- wled00/wled10_ntp.ino | 18 ++++++++++++++++++ wled00/wled11_ol.ino | 5 +++-- 9 files changed, 96 insertions(+), 11 deletions(-) diff --git a/wled00/WS2812FX.cpp b/wled00/WS2812FX.cpp index f3d63cd14..8473b14b0 100644 --- a/wled00/WS2812FX.cpp +++ b/wled00/WS2812FX.cpp @@ -137,7 +137,6 @@ void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w) case 7: bus->SetPixelColor((_skipFirstMode)?o+4:o+3,RgbwColor(r,g,b,w)); break; case 8: bus->SetPixelColor((_skipFirstMode)?o+10:o+9,RgbwColor(r,g,b,w)); break; case 9: bus->SetPixelColor((_skipFirstMode)?o+5:o+4,RgbwColor(r,g,b,w)); break; - default: break; } } } @@ -150,7 +149,7 @@ void WS2812FX::setReverseMode(bool b) void WS2812FX::driverModeCronixie(bool b) { _cronixieMode = b; - if (b) _segments[0].stop = 5; + _segments[0].stop = (b) ? 5 : _length-1; } void WS2812FX::setCronixieBacklight(bool b) diff --git a/wled00/data/settings_time.htm b/wled00/data/settings_time.htm index 793811727cd085ab5b6a94dec5db173285f9d89a..3c06dff4a85c7a074c8271a376c0309c60f2df2b 100644 GIT binary patch delta 710 zcmeB3JXX4aOM7#Iwi(Oh4@!LXAq<%exeTccx(v6|R9!q4b2*0QYEwK>z>% delta 82 zcmX?B+L5?{OM9}PK8LLWLo!1?Lmop3LlKb90m4*<6b1!`T!uuT3`ndP$OEa#Wyl1o XO9%3bfjp2N#mzsp+*u}HvHS!8Kn)bC diff --git a/wled00/htmls01.h b/wled00/htmls01.h index 43f11927a..b9a2b8d25 100644 --- a/wled00/htmls01.h +++ b/wled00/htmls01.h @@ -345,12 +345,28 @@ Define API macros here:
15:
16:

Use 0 for the default action instead of a macro
-Time controlled macros coming soon!
Boot Macro:
Alexa On/Off Macros:
Button Macro: Long Press:
Countdown-Over Macro:
-Timed-Light-Over Macro:
+Timed-Light-Over Macro:
+Time-Controlled Macros (Hours/Minutes > Macro):
+ +>
+ +>
+ +>
+ +>
+ +>
+ +>
+ +>
+ +>
diff --git a/wled00/wled00.ino b/wled00/wled00.ino index f383d0a69..508a980fe 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -9,7 +9,8 @@ //ESP8266-01 got too little storage space to work with all features of WLED. To use it, you must use ESP8266 Arduino Core v2.3.0 and the setting 512K(64K SPIFFS). //Uncomment the following line to disable some features (currently Mobile UI, welcome page and single digit + cronixie overlays) to compile for ESP8266-01 -#define WLED_FLASH_512K_MODE +//#define WLED_FLASH_512K_MODE +//CURRENTLY NOT WORKING //library inclusions @@ -43,7 +44,7 @@ //version code in format yymmddb (b = daily build) -#define VERSION 1809162 +#define VERSION 1809222 char versionString[] = "0.8.0-a"; @@ -299,6 +300,14 @@ bool cronixieInit = false; unsigned long countdownTime = 1514764800L; bool countdownOverTriggered = true; +//timer +byte lastTimerMinute = 0; +byte timerHours[] = {0,0,0,0,0,0,0,0}; +byte timerMinutes[] = {0,0,0,0,0,0,0,0}; +byte timerMacro[] = {0,0,0,0,0,0,0,0}; +byte timerWeekday[] = {255,255,255,255,255,255,255,255}; //weekdays to activate on +//bit pattern of arr elem: 0b11111111: sat,fri,thu,wed,tue,mon,sun,validity + //blynk bool blynkEnabled = false; diff --git a/wled00/wled01_eeprom.ino b/wled00/wled01_eeprom.ino index 161b87de0..235a2b36b 100644 --- a/wled00/wled01_eeprom.ino +++ b/wled00/wled01_eeprom.ino @@ -234,6 +234,14 @@ void saveSettingsToEEPROM() { EEPROM.write(i, blynkApiKey[i-2220]); } + + for (int i = 0; i < 8; ++i) + { + EEPROM.write(2260 + i, timerHours[i] ); + EEPROM.write(2270 + i, timerMinutes[i]); + EEPROM.write(2280 + i, timerWeekday[i]); + EEPROM.write(2290 + i, timerMacro[i] ); + } EEPROM.commit(); } @@ -448,8 +456,17 @@ void loadSettingsFromEEPROM(bool first) if (lastEEPROMversion > 7) { - strip.paletteFade = EEPROM.read(374); + strip.paletteFade = EEPROM.read(374); strip.paletteBlend = EEPROM.read(382); + + for (int i = 0; i < 8; ++i) + { + timerHours[i] = EEPROM.read(2260 + i); + timerMinutes[i] = EEPROM.read(2270 + i); + timerWeekday[i] = EEPROM.read(2280 + i); + if (timerWeekday[i] == 0) timerWeekday[i] = 255; + timerMacro[i] = EEPROM.read(2290 + i); + } } receiveDirect = !EEPROM.read(2200); diff --git a/wled00/wled02_xml.ino b/wled00/wled02_xml.ino index 8bb76bc93..9dfc24511 100644 --- a/wled00/wled02_xml.ino +++ b/wled00/wled02_xml.ino @@ -292,6 +292,15 @@ void getSettingsJS(byte subPage) //get values for settings form in javascript sappend('v',"ML",macroLongPress); sappend('v',"MC",macroCountdown); sappend('v',"MN",macroNl); + + k[2] = 0; //Time macros + for (int i = 0; i<8; i++) + { + k[1] = 48+i; //ascii 0,1,2,3 + k[0] = 'H'; sappend('v',k,timerHours[i]); + k[0] = 'N'; sappend('v',k,timerMinutes[i]); + k[0] = 'T'; sappend('v',k,timerMacro[i]); + } } if (subPage == 6) diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index cae759eb0..714c8f5a0 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -219,7 +219,7 @@ void handleSettingsSet(byte subPage) strcpy(cronixieDisplay,server.arg("CX").c_str()); bool cbOld = cronixieBacklight; cronixieBacklight = server.hasArg("CB"); - if (cbOld != cronixieBacklight && overlayCurrent == 4) + if (cbOld != cronixieBacklight && overlayCurrent == 3) { strip.setCronixieBacklight(cronixieBacklight); overlayRefreshedTime = 0; } @@ -236,6 +236,7 @@ void handleSettingsSet(byte subPage) String a = "M"+String(i); if (server.hasArg(a)) saveMacro(i,server.arg(a),false); } + macroBoot = server.arg("MB").toInt(); macroAlexaOn = server.arg("A0").toInt(); macroAlexaOff = server.arg("A1").toInt(); @@ -243,6 +244,21 @@ void handleSettingsSet(byte subPage) macroLongPress = server.arg("ML").toInt(); macroCountdown = server.arg("MC").toInt(); macroNl = server.arg("MN").toInt(); + + char k[3]; k[2] = 0; + for (int i = 0; i<8; i++) + { + k[1] = i+48;//ascii 0,1,2,3 + + k[0] = 'H'; //timer hours + timerHours[i] = server.arg(k).toInt(); + + k[0] = 'N'; //minutes + timerMinutes[i] = server.arg(k).toInt(); + + k[0] = 'T'; //macros + timerMacro[i] = server.arg(k).toInt(); + } } //SECURITY @@ -687,7 +703,7 @@ bool handleSet(String req) { cronixieBacklight = false; } - if (overlayCurrent == 4) strip.setCronixieBacklight(cronixieBacklight); + if (overlayCurrent == 3) strip.setCronixieBacklight(cronixieBacklight); overlayRefreshedTime = 0; } pos = req.indexOf("U0="); //user var 0 diff --git a/wled00/wled10_ntp.ino b/wled00/wled10_ntp.ino index 2656a1062..31f335810 100644 --- a/wled00/wled10_ntp.ino +++ b/wled00/wled10_ntp.ino @@ -166,3 +166,21 @@ bool checkCountdown() return false; } +void checkTimers() +{ + if (lastTimerMinute != minute(local)) //only check once a new minute begins + { + lastTimerMinute = minute(local); + for (uint8_t i = 0; i < 8; i++) + { + if (timerMacro[i] != 0 + && (timerHours[i] == hour(local) || timerHours[i] == 24) //if hour is set to 24, activate every hour + && timerMinutes[i] == minute(local) + && timerWeekday[i] >> weekday(local) & 0x01) //timer should activate at current day of week + { + applyMacro(timerMacro[i]); + } + } + } +} + diff --git a/wled00/wled11_ol.ino b/wled00/wled11_ol.ino index 969a3e1a3..a3ac6d166 100644 --- a/wled00/wled11_ol.ino +++ b/wled00/wled11_ol.ino @@ -3,13 +3,13 @@ */ void initCronixie() { - if (overlayCurrent == 4 && !cronixieInit) + if (overlayCurrent == 3 && !cronixieInit) { strip.driverModeCronixie(true); strip.setCronixieBacklight(cronixieBacklight); setCronixie(); cronixieInit = true; - } else if (cronixieInit && overlayCurrent != 4) + } else if (cronixieInit && overlayCurrent != 3) { strip.driverModeCronixie(false); cronixieInit = false; @@ -124,6 +124,7 @@ void handleOverlays() { initCronixie(); updateLocalTime(); + checkTimers(); switch (overlayCurrent) { case 0: break;//no overlay