2020-03-25 09:00:55 +01:00
|
|
|
#include "wled.h"
|
2020-03-31 02:38:08 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Used to draw clock overlays over the strip
|
|
|
|
*/
|
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
|
|
|
}
|
2023-03-19 11:24:59 +01:00
|
|
|
float hourP = ((float)(hour(localTime)%12))/12.0f;
|
|
|
|
float minuteP = ((float)minute(localTime))/60.0f;
|
|
|
|
hourP = hourP + minuteP/12.0f;
|
|
|
|
float secondP = ((float)second(localTime))/60.0f;
|
|
|
|
int hourPixel = floorf(analogClock12pixel + overlaySize*hourP);
|
2017-12-28 00:37:13 +01:00
|
|
|
if (hourPixel > overlayMax) hourPixel = overlayMin -1 + hourPixel - overlayMax;
|
2023-03-19 11:24:59 +01:00
|
|
|
int minutePixel = floorf(analogClock12pixel + overlaySize*minuteP);
|
2023-01-06 09:24:29 +01:00
|
|
|
if (minutePixel > overlayMax) minutePixel = overlayMin -1 + minutePixel - overlayMax;
|
2023-03-19 11:24:59 +01:00
|
|
|
int secondPixel = floorf(analogClock12pixel + overlaySize*secondP);
|
2017-12-28 00:37:13 +01:00
|
|
|
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
|
|
|
{
|
2021-05-11 14:54:03 +02:00
|
|
|
for (byte i = 0; i <= 12; i++)
|
2018-03-14 11:41:24 +01:00
|
|
|
{
|
2023-03-19 11:24:59 +01:00
|
|
|
int pix = analogClock12pixel + roundf((overlaySize / 12.0f) *i);
|
2018-10-24 02:06:07 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _overlayAnalogCountdown()
|
|
|
|
{
|
2021-05-25 09:59:19 +02:00
|
|
|
if ((unsigned long)toki.second() < countdownTime)
|
2017-12-02 23:58:22 +01:00
|
|
|
{
|
2021-05-25 09:59:19 +02:00
|
|
|
long diff = countdownTime - toki.second();
|
2023-03-19 11:24:59 +01:00
|
|
|
float pval = 60.0f;
|
2017-12-02 23:58:22 +01:00
|
|
|
if (diff > 31557600L) //display in years if more than 365 days
|
|
|
|
{
|
2023-03-19 11:24:59 +01:00
|
|
|
pval = 315576000.0f; //10 years
|
2017-12-02 23:58:22 +01:00
|
|
|
} else if (diff > 2592000L) //display in months if more than a month
|
|
|
|
{
|
2023-03-19 11:24:59 +01:00
|
|
|
pval = 31557600.0f; //1 year
|
2017-12-02 23:58:22 +01:00
|
|
|
} else if (diff > 604800) //display in weeks if more than a week
|
|
|
|
{
|
2023-03-19 11:24:59 +01:00
|
|
|
pval = 2592000.0f; //1 month
|
2017-12-02 23:58:22 +01:00
|
|
|
} else if (diff > 86400) //display in days if more than 24 hours
|
|
|
|
{
|
2023-03-19 11:24:59 +01:00
|
|
|
pval = 604800.0f; //1 week
|
2017-12-02 23:58:22 +01:00
|
|
|
} else if (diff > 3600) //display in hours if more than 60 minutes
|
|
|
|
{
|
2023-03-19 11:24:59 +01:00
|
|
|
pval = 86400.0f; //1 day
|
2017-12-02 23:58:22 +01:00
|
|
|
} else if (diff > 60) //display in minutes if more than 60 seconds
|
|
|
|
{
|
2023-03-19 11:24:59 +01:00
|
|
|
pval = 3600.0f; //1 hour
|
2017-12-02 23:58:22 +01:00
|
|
|
}
|
|
|
|
int overlaySize = overlayMax - overlayMin +1;
|
2023-03-19 11:24:59 +01:00
|
|
|
float perc = (pval-(float)diff)/pval;
|
|
|
|
if (perc > 1.0f) perc = 1.0f;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-02 22:10:59 +01:00
|
|
|
|
|
|
|
void handleOverlayDraw() {
|
2021-09-30 05:23:32 +02:00
|
|
|
usermods.handleOverlayDraw();
|
2023-10-26 23:36:29 +02:00
|
|
|
if (analogClockSolidBlack) {
|
|
|
|
Segment* segments = strip.getSegments();
|
|
|
|
for (uint8_t i = 0; i < strip.getActiveSegmentsNum(); i++) {
|
|
|
|
Segment segment = segments[i];
|
|
|
|
if (segment.mode > 0 || segment.colors[0] > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-06 23:47:36 +01:00
|
|
|
if (overlayCurrent == 1) _overlayAnalogClock();
|
2020-01-02 22:10:59 +01:00
|
|
|
}
|
2020-03-31 02:38:08 +02:00
|
|
|
|
|
|
|
/*
|
2022-03-06 23:47:36 +01:00
|
|
|
* Support for the Cronixie clock has moved to a usermod, compile with "-D USERMOD_CRONIXIE" to enable
|
2020-03-31 02:38:08 +02:00
|
|
|
*/
|