Completed serverside user presets

Added analog countdown overlay (OL=5)
Sorted overlay code into methods
Updated countdown goal to Jan 1, 2018 12AM
This commit is contained in:
cschwinne 2017-12-02 23:58:22 +01:00
parent b543753263
commit afa3a0149c
5 changed files with 270 additions and 180 deletions

View File

@ -20,7 +20,7 @@
#include "CallbackFunction.h"
//version in format yymmddb (b = daily build)
#define VERSION 1711302
#define VERSION 1712022
//If you have an RGBW strip, uncomment first line in WS2812FX.h!
@ -31,7 +31,7 @@
//#define USEFS
//overlays, needed for clocks etc.
//#define USEOVERLAYS
#define USEOVERLAYS
#ifdef USEFS
#include <FS.h>
@ -172,7 +172,7 @@ const unsigned long seventyYears = 2208988800UL;
uint8_t overlayDefault = 0;
uint8_t overlayCurrent = 0;
#ifdef USEOVERLAYS
int overlayMin = 0, overlayMax = 9;
int overlayMin = 0, overlayMax = 79;
int analogClock12pixel = 25;
boolean analogClockSecondsTrail = false;
boolean analogClock5MinuteMarks = true;
@ -187,7 +187,7 @@ int overlayDur[6];
int overlayPauseDur[6];
int nixieClockI = -1;
boolean nixiePause;
unsigned long countdownTime = 1483225200L;
unsigned long countdownTime = 1514764800L;
#endif
int arlsTimeoutMillis = 2500;

View File

@ -254,6 +254,7 @@ void loadSettingsFromEEPROM()
cc_fromStart = EEPROM.read(386);
cc_fromEnd = EEPROM.read(387);
cc_step = EEPROM.read(388);
strip.setCustomChase(cc_index1, cc_index2, cc_start, cc_numPrimary, cc_numSecondary, cc_step, cc_fromStart, cc_fromEnd);
}
@ -264,16 +265,17 @@ void loadSettingsFromEEPROM()
}
//PRESET PROTOCOL 20 bytes
//0: (0:invalid 1: just bri 2: just col 3: just fx 4: bri/col 5: bri/fx 6: col/fx 7: all 8:i_like_pancakes >8:invalid)
//1:a 2:r 3:g 4:b 5:w 6:er 7:eg 8:eb 9:ew 10:fx 11:sx | custom chase 12:numP 13:numS 14:(0:fs 1:fe 2:both) 15:step 16-19:Zeros
//0: preset purpose byte 0:invalid 1:valid preset 1.0
//1:a 2:r 3:g 4:b 5:w 6:er 7:eg 8:eb 9:ew 10:fx 11:sx | custom chase 12:numP 13:numS 14:(0:fs 1:both 2:fe) 15:step 16-19:Zeros
void applyPreset(uint8_t index)
void applyPreset(uint8_t index, bool loadBri, bool loadCol, bool loadFX)
{
if (index == 255) loadSettingsFromEEPROM();//load boot defaults
if (index > 24) return;
uint16_t i = 400 + index*20;
uint8_t m = EEPROM.read(i);
if (m == 7 || m == 1 || m == 4 || m == 5) bri = EEPROM.read(i+1);
if (m == 7 || m == 2 || m == 4 || m == 6)
if (EEPROM.read(i) == 0) return;
if (loadBri) bri = EEPROM.read(i+1);
if (loadCol)
{
col[0] = EEPROM.read(i+2);
col[1] = EEPROM.read(i+3);
@ -284,7 +286,7 @@ void applyPreset(uint8_t index)
col_sec[2] = EEPROM.read(i+8);
white_sec = EEPROM.read(i+9);
}
if (m == 3 || (m > 4 && m < 8))
if (loadFX)
{
effectCurrent = EEPROM.read(i+10);
effectSpeed = EEPROM.read(i+11);
@ -294,16 +296,34 @@ void applyPreset(uint8_t index)
cc_fromStart = (EEPROM.read(i+14)<2);
cc_step = EEPROM.read(i+15);
strip.setCustomChase(cc_index1, cc_index2, cc_start, cc_numPrimary, cc_numSecondary, cc_step, cc_fromStart, cc_fromEnd);
strip.setMode(effectCurrent);
strip.setSpeed(effectSpeed);
}
}
void savePreset(uint8_t index, uint8_t m)
void savePreset(uint8_t index)
{
if (index > 24) return;
for (int i = 0; i < 20; i++)
{
EEPROM.write(400 + index*20 + i, 0); //CHANGE!!!
}
uint16_t i = 400 + index*20;
EEPROM.write(i, 1);
EEPROM.write(i+1, bri);
EEPROM.write(i+2, col[0]);
EEPROM.write(i+3, col[1]);
EEPROM.write(i+4, col[2]);
EEPROM.write(i+5, white);
EEPROM.write(i+6, col_sec[0]);
EEPROM.write(i+7, col_sec[1]);
EEPROM.write(i+8, col_sec[2]);
EEPROM.write(i+9, white_sec);
EEPROM.write(i+10, effectCurrent);
EEPROM.write(i+11, effectSpeed);
EEPROM.write(i+12, cc_numPrimary);
EEPROM.write(i+13, cc_numSecondary);
uint8_t m = 1;
if (!cc_fromStart) m = 2;
if (!cc_fromEnd) m = 0;
EEPROM.write(i+14, m);
EEPROM.write(i+15, cc_step);
EEPROM.commit();
}

View File

@ -246,9 +246,9 @@ boolean handleSet(String req)
}
int pos = 0;
//set brigthness
pos = req.indexOf("A=");
pos = req.indexOf("&A=");
if (pos > 0) {
bri = req.substring(pos + 2).toInt();
bri = req.substring(pos + 3).toInt();
}
//set red value
pos = req.indexOf("R=");
@ -424,14 +424,29 @@ boolean handleSet(String req)
pos = req.indexOf("CF="); if (pos > 0) {cc_fromStart = (req.substring(pos + 3).toInt()); _cc_updated = true;}
pos = req.indexOf("CE="); if (pos > 0) {cc_fromEnd = (req.substring(pos + 3).toInt()); _cc_updated = true;}
if (_cc_updated) strip.setCustomChase(cc_index1, cc_index2, cc_start, cc_numPrimary, cc_numSecondary, cc_step, cc_fromStart, cc_fromEnd);
//set presets
pos = req.indexOf("PS="); //saves current in preset
if (pos > 0) {
savePreset(req.substring(pos + 3).toInt(), 0); //CHANGE!!!
savePreset(req.substring(pos + 3).toInt());
}
pos = req.indexOf("PL="); //applies preset
pos = req.indexOf("PL="); //applies entire preset
if (pos > 0) {
applyPreset(req.substring(pos + 3).toInt());
applyPreset(req.substring(pos + 3).toInt(), true, true, true);
effectUpdated = true;
}
pos = req.indexOf("PA="); //applies brightness from preset
if (pos > 0) {
applyPreset(req.substring(pos + 3).toInt(), true, false, false);
}
pos = req.indexOf("PC="); //applies color from preset
if (pos > 0) {
applyPreset(req.substring(pos + 3).toInt(), false, true, false);
}
pos = req.indexOf("PX="); //applies effects from preset
if (pos > 0) {
applyPreset(req.substring(pos + 3).toInt(), false, false, true);
effectUpdated = true;
}
//internal call, does not send XML response

View File

@ -2,5 +2,5 @@
* foo
*/
String readFromFS(String filename){return "NI";};
String readFromFS(String filename){return "N";};
void writeToFS(String filename, String file) {};

View File

@ -1,10 +1,10 @@
#ifdef USEOVERLAYS
void nixieDisplay(int num[], int dur[], int pausedur[], int cnt)
void _nixieDisplay(int num[], int dur[], int pausedur[], int cnt)
{
strip.setRange(overlayMin, overlayMax, 0);
if (num[nixieClockI] >= 0 && !nixiePause)
{
strip.setIndividual(num[nixieClockI], ((uint32_t)col_t[0] << 16) | ((uint32_t)col_t[1] << 8) | col_t[2]);
strip.setIndividual(num[nixieClockI],((uint32_t)white << 24)| ((uint32_t)col_t[0] << 16) | ((uint32_t)col_t[1] << 8) | col_t[2]);
strip.unlock(num[nixieClockI]);
}
if (!nixiePause)
@ -29,7 +29,7 @@ void nixieDisplay(int num[], int dur[], int pausedur[], int cnt)
}
}
void nixieNumber(int number, int dur)
void _nixieNumber(int number, int dur)
{
if (nixieClockI < 0)
{
@ -97,7 +97,7 @@ void nixieNumber(int number, int dur)
DEBUG_PRINTLN(" ");
nixieClockI = 0;
} else {
nixieDisplay(overlayArr, overlayDur, overlayPauseDur, 6);
_nixieDisplay(overlayArr, overlayDur, overlayPauseDur, 6);
}
}
@ -105,10 +105,10 @@ void handleOverlays()
{
//properties: range, (color)
//0 no overlay
//1 solid color
//1 solid color (NI)
//2 analog clock
//3 digital nixie-style clock one digit
//4 just static hour
//4 just static hour (NI)
//5 analog countdown
//6 digital one digit countdown
if (millis() - overlayRefreshedTime > overlayRefreshMs)
@ -116,159 +116,214 @@ void handleOverlays()
overlayRefreshedTime = millis();
switch (overlayCurrent)
{
case 2: {//2 analog clock
int overlaySize = overlayMax - overlayMin +1;
strip.unlockAll();
local = TZ.toLocal(now(), &tcr);
double hourP = ((double)(hour(local)%12))/12;
double minuteP = ((double)minute(local))/60;
hourP = hourP + minuteP/12;
double secondP = ((double)second(local))/60;
int hourPixel = floor(overlayMin + analogClock12pixel + overlaySize*hourP);
if (hourPixel > overlayMax) hourPixel = hourPixel - overlayMax;
int minutePixel = floor(overlayMin + analogClock12pixel + overlaySize*minuteP);
if (minutePixel > overlayMax) minutePixel = minutePixel - overlayMax;
int secondPixel = floor(overlayMin + analogClock12pixel + overlaySize*secondP);
if (secondPixel > overlayMax) secondPixel = secondPixel - overlayMax;
if (analogClock5MinuteMarks)
{
int pix;
for (int i = 0; i <= 12; i++)
{
pix = overlayMin + analogClock12pixel + (overlaySize/12)*i;
if (pix > overlayMax) pix = pix - overlayMax;
strip.setIndividual(pix, 0xAAAAAA);
}
}
if (analogClockSecondsTrail)
{
strip.setRange(analogClock12pixel, secondPixel, 0x0000FF);
} else
{
strip.setIndividual(secondPixel, 0x0000FF);
}
strip.setIndividual(minutePixel, 0x00FF00);
strip.setIndividual(hourPixel, 0xFF0000);
overlayRefreshMs = 998; break;
}
case 3: {
if (nixieClockI < 0)
{
local = TZ.toLocal(now(), &tcr);
overlayArr[0] = hour(local);
if (nixieClock12HourFormat && overlayArr[0] > 12)
{
overlayArr[0] = overlayArr[0]%12;
}
overlayArr[1] = -1;
if (overlayArr[0] > 9)
{
overlayArr[1] = overlayArr[0]%10;
overlayArr[0] = overlayArr[0]/10;
}
overlayArr[2] = minute(local);
overlayArr[3] = overlayArr[2]%10;
overlayArr[2] = overlayArr[2]/10;
overlayArr[4] = -1;
overlayArr[5] = -1;
if (nixieClockDisplaySeconds)
{
overlayArr[4] = second(local);
overlayArr[5] = overlayArr[4]%10;
overlayArr[4] = overlayArr[4]/10;
}
for (int i = 0; i < 6; i++)
{
if (overlayArr[i] != -1)
{
overlayArr[i] = overlayArr[i] + overlayMin;
if (overlayReverse)
overlayArr[i] = overlayMax - overlayArr[i];
}
}
overlayDur[0] = 12 + 12*(255 - overlaySpeed);
if (overlayArr[1] == overlayArr[0])
{
overlayPauseDur[0] = 3 + 3*(255 - overlaySpeed);
} else
{
overlayPauseDur[0] = 0;
}
if (overlayArr[1] == -1)
{
overlayDur[1] = 0;
} else
{
overlayDur[1] = 12 + 12*(255 - overlaySpeed);
}
overlayPauseDur[1] = 9 + 9*(255 - overlaySpeed);
overlayDur[2] = 12 + 12*(255 - overlaySpeed);
if (overlayArr[2] == overlayArr[3])
{
overlayPauseDur[2] = 3 + 3*(255 - overlaySpeed);
} else
{
overlayPauseDur[2] = 0;
}
overlayDur[3] = 12 + 12*(255 - overlaySpeed);
overlayPauseDur[3] = 9 + 9*(255 - overlaySpeed);
if (overlayArr[4] == -1)
{
overlayDur[4] = 0;
overlayPauseDur[4] = 0;
overlayDur[5] = 0;
} else
{
overlayDur[4] = 12 + 12*(255 - overlaySpeed);
if (overlayArr[5] == overlayArr[4])
{
overlayPauseDur[4] = 3 + 3*(255 - overlaySpeed);
} else
{
overlayPauseDur[4] = 0;
}
overlayDur[5] = 12 + 12*(255 - overlaySpeed);
}
overlayPauseDur[5] = 22 + 22*(255 - overlaySpeed);
nixieClockI = 0;
} else
{
nixieDisplay(overlayArr, overlayDur, overlayPauseDur, 6);
}
} break;
case 5: {//countdown
if (now() >= countdownTime)
{
if (effectCurrent != 8){
effectCurrent = 8;
strip.setMode(8);
strip.setSpeed(255);
}
nixieNumber(2017, 2017);
} else
{
long diff = countdownTime - now();
if (diff > 86313600L) //display in years if more than 999 days
{
diff = diff/31557600L;
} else if (diff > 3596400) //display in days if more than 999 hours
{
diff = diff/86400;
} else if (diff > 59940) //display in hours if more than 999 minutes
{
diff = diff/1440;
} else if (diff > 999) //display in minutes if more than 999 seconds
{
diff = diff/60;
}
nixieNumber(diff, 800);
}
}
case 2: _overlayAnalogClock(); break;//2 analog clock
case 3: _overlayNixieClock(); break;//nixie 1-digit
case 5: _overlayAnalogCountdown(); break;//a.countdown
case 6: _overlayNixieCountdown(); break;//d.
}
}
}
void _overlayAnalogClock()
{
int overlaySize = overlayMax - overlayMin +1;
strip.unlockAll();
local = TZ.toLocal(now(), &tcr);
double hourP = ((double)(hour(local)%12))/12;
double minuteP = ((double)minute(local))/60;
hourP = hourP + minuteP/12;
double secondP = ((double)second(local))/60;
int hourPixel = floor(overlayMin + analogClock12pixel + overlaySize*hourP);
if (hourPixel > overlayMax) hourPixel = hourPixel - overlayMax;
int minutePixel = floor(overlayMin + analogClock12pixel + overlaySize*minuteP);
if (minutePixel > overlayMax) minutePixel = minutePixel - overlayMax;
int secondPixel = floor(overlayMin + analogClock12pixel + overlaySize*secondP);
if (secondPixel > overlayMax) secondPixel = secondPixel - overlayMax;
if (analogClock5MinuteMarks)
{
int pix;
for (int i = 0; i <= 12; i++)
{
pix = overlayMin + analogClock12pixel + (overlaySize/12)*i;
if (pix > overlayMax) pix = pix - overlayMax;
strip.setIndividual(pix, 0xAAAAAA);
}
}
if (analogClockSecondsTrail)
{
strip.setRange(analogClock12pixel, secondPixel, 0x0000FF);
} else
{
strip.setIndividual(secondPixel, 0x0000FF);
}
strip.setIndividual(minutePixel, 0x00FF00);
strip.setIndividual(hourPixel, 0xFF0000);
overlayRefreshMs = 998;
}
void _overlayNixieClock()
{
if (nixieClockI < 0)
{
local = TZ.toLocal(now(), &tcr);
overlayArr[0] = hour(local);
if (nixieClock12HourFormat && overlayArr[0] > 12)
{
overlayArr[0] = overlayArr[0]%12;
}
overlayArr[1] = -1;
if (overlayArr[0] > 9)
{
overlayArr[1] = overlayArr[0]%10;
overlayArr[0] = overlayArr[0]/10;
}
overlayArr[2] = minute(local);
overlayArr[3] = overlayArr[2]%10;
overlayArr[2] = overlayArr[2]/10;
overlayArr[4] = -1;
overlayArr[5] = -1;
if (nixieClockDisplaySeconds)
{
overlayArr[4] = second(local);
overlayArr[5] = overlayArr[4]%10;
overlayArr[4] = overlayArr[4]/10;
}
for (int i = 0; i < 6; i++)
{
if (overlayArr[i] != -1)
{
overlayArr[i] = overlayArr[i] + overlayMin;
if (overlayReverse)
overlayArr[i] = overlayMax - overlayArr[i];
}
}
overlayDur[0] = 12 + 12*(255 - overlaySpeed);
if (overlayArr[1] == overlayArr[0])
{
overlayPauseDur[0] = 3 + 3*(255 - overlaySpeed);
} else
{
overlayPauseDur[0] = 0;
}
if (overlayArr[1] == -1)
{
overlayDur[1] = 0;
} else
{
overlayDur[1] = 12 + 12*(255 - overlaySpeed);
}
overlayPauseDur[1] = 9 + 9*(255 - overlaySpeed);
overlayDur[2] = 12 + 12*(255 - overlaySpeed);
if (overlayArr[2] == overlayArr[3])
{
overlayPauseDur[2] = 3 + 3*(255 - overlaySpeed);
} else
{
overlayPauseDur[2] = 0;
}
overlayDur[3] = 12 + 12*(255 - overlaySpeed);
overlayPauseDur[3] = 9 + 9*(255 - overlaySpeed);
if (overlayArr[4] == -1)
{
overlayDur[4] = 0;
overlayPauseDur[4] = 0;
overlayDur[5] = 0;
} else
{
overlayDur[4] = 12 + 12*(255 - overlaySpeed);
if (overlayArr[5] == overlayArr[4])
{
overlayPauseDur[4] = 3 + 3*(255 - overlaySpeed);
} else
{
overlayPauseDur[4] = 0;
}
overlayDur[5] = 12 + 12*(255 - overlaySpeed);
}
overlayPauseDur[5] = 22 + 22*(255 - overlaySpeed);
nixieClockI = 0;
} else
{
_nixieDisplay(overlayArr, overlayDur, overlayPauseDur, 6);
}
}
void _overlayAnalogCountdown()
{
strip.unlockAll();
if (now() >= countdownTime)
{
//what to do if countdown finished
} else
{
long diff = countdownTime - now();
double pval = 60;
if (diff > 31557600L) //display in years if more than 365 days
{
pval = 315576000L; //10 years
} else if (diff > 2592000L) //display in months if more than a month
{
pval = 31557600L; //1 year
} else if (diff > 604800) //display in weeks if more than a week
{
pval = 2592000L; //1 month
} else if (diff > 86400) //display in days if more than 24 hours
{
pval = 604800; //1 week
} else if (diff > 3600) //display in hours if more than 60 minutes
{
pval = 86400; //1 day
} else if (diff > 60) //display in minutes if more than 60 seconds
{
pval = 3600; //1 hour
}
int overlaySize = overlayMax - overlayMin +1;
double perc = (pval-(double)diff)/pval;
if (perc > 1.0) perc = 1.0;
uint8_t pixelCnt = perc*overlaySize;
if (analogClock12pixel + pixelCnt > overlayMax)
{
strip.setRange(analogClock12pixel, overlayMax, ((uint32_t)white_sec << 24)| ((uint32_t)col_sec[0] << 16) | ((uint32_t)col_sec[1] << 8) | col_sec[2]);
strip.setRange(overlayMin, overlayMin +pixelCnt -(1+ overlayMax -analogClock12pixel), ((uint32_t)white_sec << 24)| ((uint32_t)col_sec[0] << 16) | ((uint32_t)col_sec[1] << 8) | col_sec[2]);
} else
{
strip.setRange(analogClock12pixel, analogClock12pixel + pixelCnt, ((uint32_t)white_sec << 24)| ((uint32_t)col_sec[0] << 16) | ((uint32_t)col_sec[1] << 8) | col_sec[2]);
}
}
overlayRefreshMs = 998;
}
void _overlayNixieCountdown()
{
if (now() >= countdownTime)
{
if (effectCurrent != 8){
effectCurrent = 8;
strip.setMode(8);
strip.setSpeed(255);
}
_nixieNumber(2018, 2018);
} else
{
long diff = countdownTime - now();
if (diff > 86313600L) //display in years if more than 999 days
{
diff = diff/31557600L;
} else if (diff > 3596400) //display in days if more than 999 hours
{
diff = diff/86400;
} else if (diff > 59940) //display in hours if more than 999 minutes
{
diff = diff/1440;
} else if (diff > 999) //display in minutes if more than 999 seconds
{
diff = diff/60;
}
_nixieNumber(diff, 800);
}
}
#endif