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:
parent
b543753263
commit
afa3a0149c
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -2,5 +2,5 @@
|
||||
* foo
|
||||
*/
|
||||
|
||||
String readFromFS(String filename){return "NI";};
|
||||
String readFromFS(String filename){return "N";};
|
||||
void writeToFS(String filename, String 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,7 +116,16 @@ void handleOverlays()
|
||||
overlayRefreshedTime = millis();
|
||||
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;
|
||||
strip.unlockAll();
|
||||
local = TZ.toLocal(now(), &tcr);
|
||||
@ -149,9 +158,11 @@ void handleOverlays()
|
||||
}
|
||||
strip.setIndividual(minutePixel, 0x00FF00);
|
||||
strip.setIndividual(hourPixel, 0xFF0000);
|
||||
overlayRefreshMs = 998; break;
|
||||
}
|
||||
case 3: {
|
||||
overlayRefreshMs = 998;
|
||||
}
|
||||
|
||||
void _overlayNixieClock()
|
||||
{
|
||||
if (nixieClockI < 0)
|
||||
{
|
||||
local = TZ.toLocal(now(), &tcr);
|
||||
@ -236,10 +247,57 @@ void handleOverlays()
|
||||
nixieClockI = 0;
|
||||
} 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 (effectCurrent != 8){
|
||||
@ -248,7 +306,7 @@ void handleOverlays()
|
||||
strip.setSpeed(255);
|
||||
}
|
||||
|
||||
nixieNumber(2017, 2017);
|
||||
_nixieNumber(2018, 2018);
|
||||
} else
|
||||
{
|
||||
long diff = countdownTime - now();
|
||||
@ -265,10 +323,7 @@ void handleOverlays()
|
||||
{
|
||||
diff = diff/60;
|
||||
}
|
||||
nixieNumber(diff, 800);
|
||||
}
|
||||
}
|
||||
}
|
||||
_nixieNumber(diff, 800);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user