From 25e9967dae14db8be623adb819651814eb5d5f6f Mon Sep 17 00:00:00 2001 From: cschwinne Date: Sat, 26 Nov 2016 19:34:05 +0100 Subject: [PATCH] nightlight dev in progress BUILD UNTESTED notifier bugs 2A no udp --- TODO.txt | 2 ++ wled00/wled00.ino | 33 ++++++++++++++++++++++++++++++--- wled00/wled03_set.ino | 1 + wled00/wled04_file.ino | 25 +++++++++++++++++++++++++ wled00/wled05_init.ino | 6 +++++- wled00/wled07_notify.ino | 1 + wled00/wled08_led.ino | 8 +++++++- 7 files changed, 71 insertions(+), 5 deletions(-) diff --git a/TODO.txt b/TODO.txt index b9f0c320..10796a25 100644 --- a/TODO.txt +++ b/TODO.txt @@ -14,6 +14,8 @@ add preferred colors to settings -> quickly t. UI, button select, use iframe for settings, seperate tabs for wifi and application confg use iframe for all adv. features? /dumpeeprom and /pusheeprom +aux trigger pin +descriptive text BUGS static ip disables mdns diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 218abf9c..7bf168fd 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -37,7 +37,7 @@ uint8_t led_amount = 16; uint8_t buttonPin = 3; //needs pull-up boolean buttonEnabled = true; String notifier_ips[]{"10.10.1.191","10.10.1.129"}; -boolean notifyDirect = true, notifyButton = true, notifyForward = true; +boolean notifyDirect = true, notifyButton = true, notifyForward = true, notifyNightlight = false; boolean receiveNotifications = true; uint8_t bri_n = 100; uint8_t nightlightDelayMins = 60; @@ -62,6 +62,9 @@ boolean buttonPressedBefore = false; int notifier_ips_count = 1; String notifier_ips_raw = ""; boolean nightlightActive = false; +boolean nightlightFade_old = false; +boolean nightlightActive_old = false; +int transitionDelay_old; NeoPixelBus strip(led_amount, 1); @@ -97,10 +100,34 @@ void handleNightlight() { if (nightlightActive) { - float nper = (millis() - nightlightStartTime)/(float)(((int)nightlightDelayMins)*60000); + if (!nightlightActive_old) //init + { + nightlightActive_old = true; + if (nightlightFade) + { + transitionDelay_old = transitionDelay; + transitionDelay = (int)(nightlightDelayMins*60000); + transitionStartTime = nightlightStartTime; + transitionActive = true; + } + } + float nper = (millis() - nightlightStartTime)/(float)transitionDelay; if (nper >= 1) { - + nightlightActive = false; + } + } + } else if (nightlightActive_old) //de-init + { + nightlightActive_old = false; + if (nightlightFade) + { + transitionDelay = transitionDelay_old; + transitionActive = false; + } else + { + bri = 0; + colorUpdated(4); } } } diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index adcef2fe..91d9c1b8 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -111,6 +111,7 @@ void handleSettingsSet() if (i > 0) nightlightDelayMins = i; } nightlightFade = server.hasArg("TLFDE"); + nightlightFade_old = nightlightFade; receiveNotifications = server.hasArg("NRCVE"); if (server.hasArg("NRBRI")) { diff --git a/wled00/wled04_file.ino b/wled00/wled04_file.ino index 968912c1..69c001f6 100644 --- a/wled00/wled04_file.ino +++ b/wled00/wled04_file.ino @@ -76,6 +76,31 @@ void handleFileDelete(){ path = String(); } +void handleFileList() { + if(!server.hasArg("dir")) {server.send(500, "text/plain", "BAD ARGS"); return;} + + String path = server.arg("dir"); + Serial.println("handleFileList: " + path); + Dir dir = SPIFFS.openDir(path); + path = String(); + + String output = "["; + while(dir.next()){ + File entry = dir.openFile("r"); + if (output != "[") output += ','; + bool isDir = false; + output += "{\"type\":\""; + output += (isDir)?"dir":"file"; + output += "\",\"name\":\""; + output += String(entry.name()).substring(1); + output += "\"}"; + entry.close(); + } + + output += "]"; + server.send(200, "text/json", output); +} + void handleFileCreate(){ if(server.args() == 0) return server.send(500, "text/plain", "BAD ARGS"); diff --git a/wled00/wled05_init.ino b/wled00/wled05_init.ino index fdbed1ea..5a8f2813 100644 --- a/wled00/wled05_init.ino +++ b/wled00/wled05_init.ino @@ -22,7 +22,7 @@ void wledInit() Serial.println("Init EEPROM"); EEPROM.begin(1024); loadSettingsFromEEPROM(); - + nightlightFade_old = nightlightFade; Serial.print("CC: SSID: "); Serial.print(clientssid); @@ -94,6 +94,7 @@ void wledInit() server.on("/edit", HTTP_POST, [](){ server.send(200, "text/plain", ""); }, handleFileUpload); server.on("/down", HTTP_GET, down); server.on("/cleareeprom", HTTP_GET, clearEEPROM); + server.on("/list", HTTP_GET, handleFileList); //init ota page httpUpdater.setup(&server); } else @@ -110,6 +111,9 @@ void wledInit() server.on("/update", HTTP_GET, [](){ server.send(500, "text/plain", "OTA lock active"); }); + server.on("/list", HTTP_GET, [](){ + server.send(500, "text/plain", "OTA lock active"); + }); } //called when the url is not defined here, ajax-in; get-settings server.onNotFound([](){ diff --git a/wled00/wled07_notify.ino b/wled00/wled07_notify.ino index ca34d42b..d016d9e7 100644 --- a/wled00/wled07_notify.ino +++ b/wled00/wled07_notify.ino @@ -5,6 +5,7 @@ void notify(int callMode) case 1: if (!notifyDirect) return; break; case 2: if (!notifyButton) return; break; case 3: if (!notifyForward) return; break; + case 4: if (!notifyNightlight) return; break; default: return; } String snd = "/ajax_inputs&N=1&A="; diff --git a/wled00/wled08_led.ino b/wled00/wled08_led.ino index ceae214a..720547a9 100644 --- a/wled00/wled08_led.ino +++ b/wled00/wled08_led.ino @@ -25,7 +25,7 @@ void setLedsStandard() void colorUpdated(int callMode) { - //call for notifier -> 0: init 1: direct change 2: button 3: notification + //call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight if (col[0] == col_it[0] && col[1] == col_it[1] && col[2] == col_it[2] && bri == bri_it) { return; //no change @@ -47,6 +47,11 @@ void colorUpdated(int callMode) } transitionActive = true; transitionStartTime = millis(); + if (nightlightActive) + { + nightlightFade_old = nightlightFade; + nightlightFade = false; + } } else { setLedsStandard(); @@ -62,6 +67,7 @@ void handleTransitions() { transitionActive = false; tper_last = 0; + nightlightFade = nightlightFade_old; setLedsStandard(); return; }