2020-03-28 13:30:51 +01:00
|
|
|
#include "overlay.h"
|
2020-03-25 09:00:55 +01:00
|
|
|
#include "wled.h"
|
2020-03-28 13:30:51 +01:00
|
|
|
#include "cronixie.h"
|
|
|
|
#include "ntp.h"
|
2020-01-02 22:10:59 +01:00
|
|
|
|
2018-03-06 23:47:08 +01:00
|
|
|
void initCronixie()
|
|
|
|
{
|
2018-09-22 22:49:24 +02:00
|
|
|
if (overlayCurrent == 3 && !cronixieInit)
|
2018-03-06 23:47:08 +01:00
|
|
|
{
|
2018-03-14 00:25:54 +01:00
|
|
|
setCronixie();
|
2020-03-22 17:45:09 +01:00
|
|
|
strip.getSegment(0).grouping = 10; //10 LEDs per digit
|
2018-03-06 23:47:08 +01:00
|
|
|
cronixieInit = true;
|
2018-09-22 22:49:24 +02:00
|
|
|
} else if (cronixieInit && overlayCurrent != 3)
|
2018-03-06 23:47:08 +01:00
|
|
|
{
|
2020-03-22 17:45:09 +01:00
|
|
|
strip.getSegment(0).grouping = 1;
|
2018-03-06 23:47:08 +01:00
|
|
|
cronixieInit = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-17 11:15:08 +02:00
|
|
|
|
2016-12-31 00:38:51 +01:00
|
|
|
void handleOverlays()
|
|
|
|
{
|
|
|
|
if (millis() - overlayRefreshedTime > overlayRefreshMs)
|
|
|
|
{
|
2018-03-06 23:47:08 +01:00
|
|
|
initCronixie();
|
|
|
|
updateLocalTime();
|
2018-09-22 22:49:24 +02:00
|
|
|
checkTimers();
|
2020-01-02 22:10:59 +01:00
|
|
|
checkCountdown();
|
|
|
|
if (overlayCurrent == 3) _overlayCronixie();//Diamex cronixie clock kit
|
2018-03-06 23:47:08 +01:00
|
|
|
overlayRefreshedTime = millis();
|
2017-12-02 23:58:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-11 00:59:15 +01:00
|
|
|
|
2017-12-02 23:58:22 +01:00
|
|
|
void _overlayAnalogClock()
|
|
|
|
{
|
|
|
|
int overlaySize = overlayMax - overlayMin +1;
|
2018-03-14 00:25:54 +01:00
|
|
|
if (countdownMode)
|
2017-12-28 00:37:13 +01:00
|
|
|
{
|
2018-03-06 23:47:08 +01:00
|
|
|
_overlayAnalogCountdown(); return;
|
2017-12-28 00:37:13 +01:00
|
|
|
}
|
2017-12-02 23:58:22 +01:00
|
|
|
double hourP = ((double)(hour(local)%12))/12;
|
|
|
|
double minuteP = ((double)minute(local))/60;
|
|
|
|
hourP = hourP + minuteP/12;
|
|
|
|
double secondP = ((double)second(local))/60;
|
2017-12-28 00:37:13 +01:00
|
|
|
int hourPixel = floor(analogClock12pixel + overlaySize*hourP);
|
|
|
|
if (hourPixel > overlayMax) hourPixel = overlayMin -1 + hourPixel - overlayMax;
|
|
|
|
int minutePixel = floor(analogClock12pixel + overlaySize*minuteP);
|
|
|
|
if (minutePixel > overlayMax) minutePixel = overlayMin -1 + minutePixel - overlayMax;
|
|
|
|
int secondPixel = floor(analogClock12pixel + overlaySize*secondP);
|
|
|
|
if (secondPixel > overlayMax) secondPixel = overlayMin -1 + secondPixel - overlayMax;
|
2017-12-02 23:58:22 +01:00
|
|
|
if (analogClockSecondsTrail)
|
|
|
|
{
|
2018-03-06 23:47:08 +01:00
|
|
|
if (secondPixel < analogClock12pixel)
|
|
|
|
{
|
2018-03-14 11:41:24 +01:00
|
|
|
strip.setRange(analogClock12pixel, overlayMax, 0xFF0000);
|
|
|
|
strip.setRange(overlayMin, secondPixel, 0xFF0000);
|
2018-03-06 23:47:08 +01:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
strip.setRange(analogClock12pixel, secondPixel, 0xFF0000);
|
|
|
|
}
|
2018-03-14 11:41:24 +01:00
|
|
|
}
|
|
|
|
if (analogClock5MinuteMarks)
|
2017-12-02 23:58:22 +01:00
|
|
|
{
|
2018-03-14 11:41:24 +01:00
|
|
|
int pix;
|
|
|
|
for (int i = 0; i <= 12; i++)
|
|
|
|
{
|
2018-10-24 02:06:07 +02:00
|
|
|
pix = analogClock12pixel + round((overlaySize / 12.0) *i);
|
|
|
|
if (pix > overlayMax) pix -= overlaySize;
|
2020-01-02 22:10:59 +01:00
|
|
|
strip.setPixelColor(pix, 0x00FFAA);
|
2018-03-14 11:41:24 +01:00
|
|
|
}
|
2017-12-02 23:58:22 +01:00
|
|
|
}
|
2020-01-02 22:10:59 +01:00
|
|
|
if (!analogClockSecondsTrail) strip.setPixelColor(secondPixel, 0xFF0000);
|
|
|
|
strip.setPixelColor(minutePixel, 0x00FF00);
|
|
|
|
strip.setPixelColor(hourPixel, 0x0000FF);
|
2017-12-02 23:58:22 +01:00
|
|
|
overlayRefreshMs = 998;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _overlayAnalogCountdown()
|
|
|
|
{
|
2020-01-02 22:10:59 +01:00
|
|
|
if (now() < countdownTime)
|
2017-12-02 23:58:22 +01:00
|
|
|
{
|
|
|
|
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;
|
2018-03-14 13:16:28 +01:00
|
|
|
byte pixelCnt = perc*overlaySize;
|
2017-12-02 23:58:22 +01:00
|
|
|
if (analogClock12pixel + pixelCnt > overlayMax)
|
|
|
|
{
|
2019-02-05 21:53:39 +01:00
|
|
|
strip.setRange(analogClock12pixel, overlayMax, ((uint32_t)colSec[3] << 24)| ((uint32_t)colSec[0] << 16) | ((uint32_t)colSec[1] << 8) | colSec[2]);
|
|
|
|
strip.setRange(overlayMin, overlayMin +pixelCnt -(1+ overlayMax -analogClock12pixel), ((uint32_t)colSec[3] << 24)| ((uint32_t)colSec[0] << 16) | ((uint32_t)colSec[1] << 8) | colSec[2]);
|
2017-12-02 23:58:22 +01:00
|
|
|
} else
|
|
|
|
{
|
2019-02-05 21:53:39 +01:00
|
|
|
strip.setRange(analogClock12pixel, analogClock12pixel + pixelCnt, ((uint32_t)colSec[3] << 24)| ((uint32_t)colSec[0] << 16) | ((uint32_t)colSec[1] << 8) | colSec[2]);
|
2017-12-02 23:58:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
overlayRefreshMs = 998;
|
|
|
|
}
|
2020-01-02 22:10:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
void handleOverlayDraw() {
|
2020-03-22 17:45:09 +01:00
|
|
|
if (!overlayCurrent) return;
|
|
|
|
switch (overlayCurrent)
|
|
|
|
{
|
|
|
|
case 1: _overlayAnalogClock(); break;
|
|
|
|
case 3: _drawOverlayCronixie(); break;
|
|
|
|
}
|
2020-01-02 22:10:59 +01:00
|
|
|
}
|