From e710eace18403978fa69a3452c55a0ef2e760ab3 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Wed, 14 Dec 2016 21:40:09 +0100 Subject: [PATCH] Began FX implementation --- wled00/wled00.ino | 11 +++++++---- wled00/wled01_eeprom.ino | 3 ++- wled00/wled02_xml.ino | 14 +++++++++++++- wled00/wled03_set.ino | 25 +++++++++++++++++++++++++ wled00/wled07_notify.ino | 24 ++++++++++++++++-------- 5 files changed, 63 insertions(+), 14 deletions(-) diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 03e422d7..2d731dcb 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -5,7 +5,8 @@ #include #include #include -#include +//#include +#include #include #include @@ -39,12 +40,14 @@ boolean ota_lock = true; String otapass = "wledota"; boolean only_ap = false; boolean buttonEnabled = true; -boolean notifyDirect = true, notifyButton = true, notifyNightlight = false; -boolean receiveNotifications = true; +boolean notifyDirect = true, notifyButton = true, notifyNightlight = false, notifyMaster = true; +boolean receiveNotifications = true, receiveNotificationsDefault = true; uint8_t bri_n = 100; uint8_t nightlightDelayMins = 60; boolean nightlightFade = true; uint16_t udpPort = 21324; +uint8_t effectCurrent = 0; +uint8_t effectSpeed = 75; double transitionResolution = 0.011; @@ -67,7 +70,7 @@ boolean nightlightActive_old = false; int transitionDelay_old; int nightlightDelayMs; boolean udpConnected = false; -byte notifierBuffer[16]; +byte udpIn[16]; NeoPixelBus strip(led_amount, 1); diff --git a/wled00/wled01_eeprom.ino b/wled00/wled01_eeprom.ino index 52da768b..fbbf3a27 100644 --- a/wled00/wled01_eeprom.ino +++ b/wled00/wled01_eeprom.ino @@ -60,7 +60,7 @@ void saveSettingsToEEPROM() EEPROM.write(247, col[1]); EEPROM.write(248, col[2]); EEPROM.write(249, bri); - EEPROM.write(250, receiveNotifications); + EEPROM.write(250, receiveNotificationsDefault); EEPROM.write(251, fadeTransition); EEPROM.write(253, (transitionDelay >> 0) & 0xFF); EEPROM.write(254, (transitionDelay >> 8) & 0xFF); @@ -146,6 +146,7 @@ void loadSettingsFromEEPROM() col[2] = EEPROM.read(248); bri = EEPROM.read(249); receiveNotifications = EEPROM.read(250); + receiveNotificationsDefault = receiveNotifications; fadeTransition = EEPROM.read(251); transitionDelay = ((EEPROM.read(253) << 0) & 0xFF) + ((EEPROM.read(254) << 8) & 0xFF00); transitionDelay_old = transitionDelay; diff --git a/wled00/wled02_xml.ino b/wled00/wled02_xml.ino index e356e4c6..d829cdb6 100644 --- a/wled00/wled02_xml.ino +++ b/wled00/wled02_xml.ino @@ -19,9 +19,21 @@ void XML_response() resp = resp + col[i]; resp = resp + ""; } + resp = resp + ""; + resp = resp + notifyMaster; + resp = resp + ""; + resp = resp + ""; + resp = resp + receiveNotifications; + resp = resp + ""; resp = resp + ""; resp = resp + nightlightActive; resp = resp + ""; + resp = resp + ""; + resp = resp + effectCurrent; + resp = resp + ""; + resp = resp + ""; + resp = resp + effectSpeed; + resp = resp + ""; resp = resp + ""; resp = resp + serverDescription; resp = resp + ""; @@ -104,7 +116,7 @@ void XML_response_settings() resp = resp + udpPort; resp = resp + ""; resp = resp + ""; - resp = resp + bool2int(receiveNotifications); + resp = resp + bool2int(receiveNotificationsDefault); resp = resp + ""; resp = resp + bri_n; resp = resp + ""; diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index 41ac57ce..3a6f7846 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -119,6 +119,7 @@ void handleSettingsSet() udpPort = server.arg("NUDPP").toInt(); } receiveNotifications = server.hasArg("NRCVE"); + receiveNotificationsDefault = receiveNotifications; if (server.hasArg("NRBRI")) { int i = server.arg("NRBRI").toInt(); @@ -172,6 +173,30 @@ boolean handleSet(String req) if (pos > 0) { col[2] = req.substring(pos + 2).toInt(); } + pos = req.indexOf("FX="); + if (pos > 0) { + effectCurrent = req.substring(pos + 3).toInt(); + } + pos = req.indexOf("XS="); + if (pos > 0) { + effectSpeed = req.substring(pos + 3).toInt(); + } + if (req.indexOf("NS=") > 0) + { + notifyMaster = true; + if (req.indexOf("NS=0") > 0) + { + notifyMaster = false; + } + } + if (req.indexOf("NR=") > 0) + { + receiveNotifications = true; + if (req.indexOf("NR=0") > 0) + { + receiveNotifications = false; + } + } if (req.indexOf("NL=") > 0) { if (req.indexOf("NL=0") > 0) diff --git a/wled00/wled07_notify.ino b/wled00/wled07_notify.ino index 31c20eb4..3d1514cb 100644 --- a/wled00/wled07_notify.ino +++ b/wled00/wled07_notify.ino @@ -1,6 +1,6 @@ void notify(uint8_t callMode) { - if (!udpConnected) return; + if (!udpConnected || !notifyMaster) return; switch (callMode) { case 1: if (!notifyDirect) return; break; @@ -17,6 +17,9 @@ void notify(uint8_t callMode) udpOut[4] = col[1]; udpOut[5] = col[2]; udpOut[6] = nightlightActive; + udpOut[7] = nightlightDelayMins; + udpOut[8] = effectCurrent; + udpOut[9] = effectSpeed; IPAddress broadcastIp; broadcastIp = ~WiFi.subnetMask() | WiFi.gatewayIP(); @@ -32,14 +35,19 @@ void handleNotifications() int packetSize = notifierUdp.parsePacket(); if(packetSize && notifierUdp.remoteIP() != WiFi.localIP()) { - notifierUdp.read(notifierBuffer, 16); - col[0] = notifierBuffer[3]; - col[1] = notifierBuffer[4]; - col[2] = notifierBuffer[5]; - nightlightActive = notifierBuffer[6]; - if (!notifierBuffer[6]) + notifierUdp.read(udpIn, 16); + col[0] = udpIn[3]; + col[1] = udpIn[4]; + col[2] = udpIn[5]; + if (true) //always receive effects? { - bri = notifierBuffer[2]; + effectCurrent = udpIn[8]; + effectSpeed = udpIn[9]; + } + nightlightActive = udpIn[6]; + if (!udpIn[6]) + { + bri = udpIn[2]; colorUpdated(3); } }