From 692c41b7c297b120f03a1abc618cd74c9e89c1e8 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Wed, 26 Apr 2017 14:04:53 +0200 Subject: [PATCH] Fixed Nightlight function added /version query updated readme --- TODO.txt | 4 ++++ readme.md | 13 +++++----- wled00/wled00.ino | 6 ++--- wled00/wled01_eeprom.ino | 1 - wled00/wled03_set.ino | 1 - wled00/wled05_init.ino | 3 +++ wled00/wled08_led.ino | 51 +++++++++++++--------------------------- 7 files changed, 31 insertions(+), 48 deletions(-) diff --git a/TODO.txt b/TODO.txt index 1d609c1e..fac2ba10 100644 --- a/TODO.txt +++ b/TODO.txt @@ -42,6 +42,10 @@ toggle nightlight toggle notifier var. brightness +auto update (get from server) + +ifLed feature -> set triggers for reqs.? + BUGS general forced reset (usually around 48h) NTP crash (1-48h) diff --git a/readme.md b/readme.md index dacf7982..1e3ff935 100644 --- a/readme.md +++ b/readme.md @@ -1,15 +1,13 @@ WLED is a basic, fast and (relatively) (ok, VERY relatively) secure implementation of a ESP8266 webserver to control Neopixel (WS2812B) leds -Uses ESP8266 Arduino libraries from 15th August 2016! Untested with newer version! +Uses ESP arduino version 2.3.0 (latest as of April 2017). Contents in the /data directory may be uploaded to SPIFFS. -Features: (V0.2) +Features: (V0.3pd) - RGB and brightness sliders - Settings page - configuration over network - Access Point and station mode - automatic failsafe AP - Edit page. Change html and other files via OTA. - -Additions for V0.3 (nearly complete!) - WS2812FX library integrated for nearly 50 special effects! - Nightlight function (gradually dims down) - Notifier function (multiple ESPs sync color via UDP broadcast) @@ -17,10 +15,11 @@ Additions for V0.3 (nearly complete!) - Full OTA software update capability - Password protected OTA page for added security (OTA lock) - Alexa smart home device server -- (not working) NTP and experimental analog clock function +- (unstable) NTP and experimental analog clock function +- better client HTML page (not yet implemented) Compile settings: -Board: WeMos D1 mini +Board: WeMos D1 mini (untested with other HW, should work if it has 4MB flash) CPU frequency: 80 MHz Flash size : 4MB (1MB SPIFFS) Upload speed: 115200 @@ -36,7 +35,7 @@ Just flash a basic HTTP OTA updater sketch and upload the bin! Connect a WS2812B RGB led strip to GPIO2. Optionally connect a NO-pushbutton to GPIO0 (internal pull-up) and ground. 2. Follow a guide to setup your Arduino client (I am using version 1.8.1) with the ESP8266 libraries. -For current compiles I use an old version from 15th August 2016. +For current compiles I use version 2.3.0. 3. You will also need the ESP8266 SPIFFS sketch data uploader. (currently working on making this step unnecessary) -> In the newest commit this step is not essential (HTML included in sketch), but recommended, since otherwise you have to upload the pictures manually to /edit SPIFFS diff --git a/wled00/wled00.ino b/wled00/wled00.ino index aae6c822..f8d9bfbe 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -22,7 +22,7 @@ #include "CallbackFunction.h" //version in format yymmddb (b = daily build) -#define VERSION 1703251 +#define VERSION 1704263 //to toggle usb serial debug (un)comment following line #define DEBUG @@ -76,9 +76,8 @@ IPAddress staticsubnet(255, 255, 255, 0); boolean turnOnAtBoot = true; byte col_s[]{255, 127, 0}; byte bri_s = 127; -uint8_t bri_nl = 0; +uint8_t bri_nl = 0, bri_nls; boolean fadeTransition = true; -boolean seqTransition = false; uint16_t transitionDelay = 1500; boolean ota_lock = true; boolean only_ap = false; @@ -135,7 +134,6 @@ boolean transitionActive = false; boolean buttonPressedBefore = false; boolean nightlightActive = false; boolean nightlightActive_old = false; -int transitionDelay_old; int nightlightDelayMs; uint8_t effectCurrent = 0; uint8_t effectSpeed = 75; diff --git a/wled00/wled01_eeprom.ino b/wled00/wled01_eeprom.ino index 964850c8..d66ea61b 100644 --- a/wled00/wled01_eeprom.ino +++ b/wled00/wled01_eeprom.ino @@ -175,7 +175,6 @@ void loadSettingsFromEEPROM() receiveNotificationsDefault = receiveNotifications; fadeTransition = EEPROM.read(251); transitionDelay = ((EEPROM.read(253) << 0) & 0xFF) + ((EEPROM.read(254) << 8) & 0xFF00); - transitionDelay_old = transitionDelay; bri_n = EEPROM.read(255); otapass = ""; for (int i = 256; i < 288; ++i) diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index 31cd66cf..cd5787f7 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -154,7 +154,6 @@ void handleSettingsSet() int i = server.arg("TDLAY").toInt(); if (i > 0){ transitionDelay = i; - transitionDelay_old = transitionDelay; } } if (server.hasArg("TLBRI")) diff --git a/wled00/wled05_init.ino b/wled00/wled05_init.ino index fe0cb46a..7744c266 100644 --- a/wled00/wled05_init.ino +++ b/wled00/wled05_init.ino @@ -90,6 +90,9 @@ void wledInit() handleSettingsSet(); if(!handleFileRead("/settingssaved.htm")) server.send(200, "text/html", PAGE_settingssaved); }); + server.on("/version", HTTP_GET, [](){ + server.send(200, "text/plain", (String)VERSION); + }); if (!ota_lock){ server.on("/edit", HTTP_GET, [](){ if(!handleFileRead("/edit.htm")) server.send(200, "text/html", PAGE_edit); diff --git a/wled00/wled08_led.ino b/wled00/wled08_led.ino index 41636fb1..9bdcf2a5 100644 --- a/wled00/wled08_led.ino +++ b/wled00/wled08_led.ino @@ -41,13 +41,19 @@ void colorUpdated(int callMode) if (callMode == 6) notify(6); return; //no change } + if (callMode != 5 && nightlightActive && nightlightFade) + { + bri_nls = bri; + nightlightDelayMs -= (millis() - nightlightStartTime); + nightlightStartTime = millis(); + } col_it[0] = col[0]; col_it[1] = col[1]; col_it[2] = col[2]; bri_it = bri; if (bri > 0) bri_last = bri; notify(callMode); - if (fadeTransition || seqTransition) + if (fadeTransition) { if (transitionActive) { @@ -55,10 +61,10 @@ void colorUpdated(int callMode) col_old[1] = col_t[1]; col_old[2] = col_t[2]; bri_old = bri_t; + tper_last = 0; } transitionActive = true; transitionStartTime = millis(); - transitionDelay = transitionDelay_old; } else { setLedsStandard(); @@ -75,10 +81,6 @@ void handleTransitions() transitionActive = false; tper_last = 0; setLedsStandard(); - if (nightlightActive && nightlightFade) - { - initNightlightFade(); - } return; } if (tper - tper_last < transitionResolution) @@ -93,29 +95,10 @@ void handleTransitions() col_t[2] = col_old[2]+((col[2] - col_old[2])*tper); bri_t = bri_old+((bri - bri_old)*tper); } - if (seqTransition) - { - - } else setAllLeds(); + setAllLeds(); } } -void initNightlightFade() -{ - float nper = (millis() - nightlightStartTime)/((float)nightlightDelayMs); - nightlightDelayMs = nightlightDelayMs*(1-nper); - if (nper >= 1) - { - return; - } - bri = bri_nl; - bri_it = bri_nl; - transitionDelay = (int)(nightlightDelayMins*60000); - transitionStartTime = nightlightStartTime; - transitionActive = true; - nightlightStartTime = millis(); -} - void handleNightlight() { if (nightlightActive) @@ -126,12 +109,14 @@ void handleNightlight() notify(4); nightlightDelayMs = (int)(nightlightDelayMins*60000); nightlightActive_old = true; - if (nightlightFade) - { - initNightlightFade(); - } + bri_nls = bri; } float nper = (millis() - nightlightStartTime)/((float)nightlightDelayMs); + if (nightlightFade) + { + bri = bri_nls+((bri_nl - bri_nls)*nper); + colorUpdated(5); + } if (nper >= 1) { nightlightActive = false; @@ -140,14 +125,10 @@ void handleNightlight() bri = bri_nl; colorUpdated(5); } + if (bri == 0) bri_last = bri_nls; } } else if (nightlightActive_old) //early de-init { nightlightActive_old = false; - if (nightlightFade) - { - transitionDelay = transitionDelay_old; - transitionActive = false; - } } }