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

View File

@ -254,6 +254,7 @@ void loadSettingsFromEEPROM()
cc_fromStart = EEPROM.read(386); cc_fromStart = EEPROM.read(386);
cc_fromEnd = EEPROM.read(387); cc_fromEnd = EEPROM.read(387);
cc_step = EEPROM.read(388); 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 //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) //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:fe 2:both) 15:step 16-19:Zeros //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; if (index > 24) return;
uint16_t i = 400 + index*20; uint16_t i = 400 + index*20;
uint8_t m = EEPROM.read(i); if (EEPROM.read(i) == 0) return;
if (m == 7 || m == 1 || m == 4 || m == 5) bri = EEPROM.read(i+1); if (loadBri) bri = EEPROM.read(i+1);
if (m == 7 || m == 2 || m == 4 || m == 6) if (loadCol)
{ {
col[0] = EEPROM.read(i+2); col[0] = EEPROM.read(i+2);
col[1] = EEPROM.read(i+3); col[1] = EEPROM.read(i+3);
@ -284,7 +286,7 @@ void applyPreset(uint8_t index)
col_sec[2] = EEPROM.read(i+8); col_sec[2] = EEPROM.read(i+8);
white_sec = EEPROM.read(i+9); white_sec = EEPROM.read(i+9);
} }
if (m == 3 || (m > 4 && m < 8)) if (loadFX)
{ {
effectCurrent = EEPROM.read(i+10); effectCurrent = EEPROM.read(i+10);
effectSpeed = EEPROM.read(i+11); effectSpeed = EEPROM.read(i+11);
@ -294,16 +296,34 @@ void applyPreset(uint8_t index)
cc_fromStart = (EEPROM.read(i+14)<2); cc_fromStart = (EEPROM.read(i+14)<2);
cc_step = EEPROM.read(i+15); 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.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; if (index > 24) return;
for (int i = 0; i < 20; i++) uint16_t i = 400 + index*20;
{ EEPROM.write(i, 1);
EEPROM.write(400 + index*20 + i, 0); //CHANGE!!! 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(); EEPROM.commit();
} }

View File

@ -246,9 +246,9 @@ boolean handleSet(String req)
} }
int pos = 0; int pos = 0;
//set brigthness //set brigthness
pos = req.indexOf("A="); pos = req.indexOf("&A=");
if (pos > 0) { if (pos > 0) {
bri = req.substring(pos + 2).toInt(); bri = req.substring(pos + 3).toInt();
} }
//set red value //set red value
pos = req.indexOf("R="); 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("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;} 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); if (_cc_updated) strip.setCustomChase(cc_index1, cc_index2, cc_start, cc_numPrimary, cc_numSecondary, cc_step, cc_fromStart, cc_fromEnd);
//set presets //set presets
pos = req.indexOf("PS="); //saves current in preset pos = req.indexOf("PS="); //saves current in preset
if (pos > 0) { 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) { 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 //internal call, does not send XML response

View File

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

View File

@ -1,10 +1,10 @@
#ifdef USEOVERLAYS #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); strip.setRange(overlayMin, overlayMax, 0);
if (num[nixieClockI] >= 0 && !nixiePause) 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]); strip.unlock(num[nixieClockI]);
} }
if (!nixiePause) 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) if (nixieClockI < 0)
{ {
@ -97,7 +97,7 @@ void nixieNumber(int number, int dur)
DEBUG_PRINTLN(" "); DEBUG_PRINTLN(" ");
nixieClockI = 0; nixieClockI = 0;
} else { } else {
nixieDisplay(overlayArr, overlayDur, overlayPauseDur, 6); _nixieDisplay(overlayArr, overlayDur, overlayPauseDur, 6);
} }
} }
@ -105,10 +105,10 @@ void handleOverlays()
{ {
//properties: range, (color) //properties: range, (color)
//0 no overlay //0 no overlay
//1 solid color //1 solid color (NI)
//2 analog clock //2 analog clock
//3 digital nixie-style clock one digit //3 digital nixie-style clock one digit
//4 just static hour //4 just static hour (NI)
//5 analog countdown //5 analog countdown
//6 digital one digit countdown //6 digital one digit countdown
if (millis() - overlayRefreshedTime > overlayRefreshMs) if (millis() - overlayRefreshedTime > overlayRefreshMs)
@ -116,7 +116,16 @@ void handleOverlays()
overlayRefreshedTime = millis(); overlayRefreshedTime = millis();
switch (overlayCurrent) switch (overlayCurrent)
{ {
case 2: {//2 analog clock 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; int overlaySize = overlayMax - overlayMin +1;
strip.unlockAll(); strip.unlockAll();
local = TZ.toLocal(now(), &tcr); local = TZ.toLocal(now(), &tcr);
@ -149,9 +158,11 @@ void handleOverlays()
} }
strip.setIndividual(minutePixel, 0x00FF00); strip.setIndividual(minutePixel, 0x00FF00);
strip.setIndividual(hourPixel, 0xFF0000); strip.setIndividual(hourPixel, 0xFF0000);
overlayRefreshMs = 998; break; overlayRefreshMs = 998;
} }
case 3: {
void _overlayNixieClock()
{
if (nixieClockI < 0) if (nixieClockI < 0)
{ {
local = TZ.toLocal(now(), &tcr); local = TZ.toLocal(now(), &tcr);
@ -236,10 +247,57 @@ void handleOverlays()
nixieClockI = 0; nixieClockI = 0;
} else } else
{ {
nixieDisplay(overlayArr, overlayDur, overlayPauseDur, 6); _nixieDisplay(overlayArr, overlayDur, overlayPauseDur, 6);
} }
} break; }
case 5: {//countdown
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 (now() >= countdownTime)
{ {
if (effectCurrent != 8){ if (effectCurrent != 8){
@ -248,7 +306,7 @@ void handleOverlays()
strip.setSpeed(255); strip.setSpeed(255);
} }
nixieNumber(2017, 2017); _nixieNumber(2018, 2018);
} else } else
{ {
long diff = countdownTime - now(); long diff = countdownTime - now();
@ -265,10 +323,7 @@ void handleOverlays()
{ {
diff = diff/60; diff = diff/60;
} }
nixieNumber(diff, 800); _nixieNumber(diff, 800);
}
}
}
} }
} }
#endif #endif