Analog clock time offset bugfix + optional hour mark feature (#2860)

* Implement optional hour marks
Time offset did not work

* removed undefined error int in hexstringtocolor

* revert cosmetic changes

* minor cosmetic changes

Co-authored-by: mdegraaf <mdegraaf@proxsys.nl>
This commit is contained in:
degraafm76 2022-11-14 02:30:18 +01:00 committed by GitHub
parent 740316ae2b
commit 75e410e4b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,8 @@ private:
// configuration (available in API and stored in flash) // configuration (available in API and stored in flash)
bool enabled = false; bool enabled = false;
Segment mainSegment; Segment mainSegment;
bool hourMarksEnabled = true;
uint32_t hourMarkColor = 0xFF0000;
uint32_t hourColor = 0x0000FF; uint32_t hourColor = 0x0000FF;
uint32_t minuteColor = 0x00FF00; uint32_t minuteColor = 0x00FF00;
bool secondsEnabled = true; bool secondsEnabled = true;
@ -87,10 +89,9 @@ private:
} }
bool hexStringToColor(String const& s, uint32_t& c, uint32_t def) { bool hexStringToColor(String const& s, uint32_t& c, uint32_t def) {
errno = 0; char *ep;
char* ep;
unsigned long long r = strtoull(s.c_str(), &ep, 16); unsigned long long r = strtoull(s.c_str(), &ep, 16);
if (*ep == 0 && errno != ERANGE) { if (*ep == 0) {
c = r; c = r;
return true; return true;
} else { } else {
@ -162,11 +163,18 @@ public:
lastOverlayDraw = millis(); lastOverlayDraw = millis();
auto time = toki.getTime(); auto time = toki.getTime();
auto localSec = tz ? tz->toLocal(time.sec) : time.sec; double secondP = second(localTime) / 60.0;
double secondP = second(localSec) / 60.0; double minuteP = minute(localTime) / 60.0;
double minuteP = minute(localSec) / 60.0; double hourP = (hour(localTime) % 12) / 12.0 + minuteP / 12.0;
double hourP = (hour(localSec) % 12) / 12.0 + minuteP / 12.0;
if (hourMarksEnabled) {
for (int Led = 0; Led <= 55; Led = Led + 5)
{
int16_t hourmarkled = adjustToSegment(Led / 60.0, mainSegment);
setPixelColor(hourmarkled, hourMarkColor);
}
}
if (secondsEnabled) { if (secondsEnabled) {
int16_t secondLed = adjustToSegment(secondP, secondsSegment); int16_t secondLed = adjustToSegment(secondP, secondsSegment);
@ -200,6 +208,8 @@ public:
top["First LED (Main Ring)"] = mainSegment.firstLed; top["First LED (Main Ring)"] = mainSegment.firstLed;
top["Last LED (Main Ring)"] = mainSegment.lastLed; top["Last LED (Main Ring)"] = mainSegment.lastLed;
top["Center/12h LED (Main Ring)"] = mainSegment.centerLed; top["Center/12h LED (Main Ring)"] = mainSegment.centerLed;
top["Hour Marks Enabled"] = hourMarksEnabled;
top["Hour Mark Color (RRGGBB)"] = colorToHexString(hourMarkColor);
top["Hour Color (RRGGBB)"] = colorToHexString(hourColor); top["Hour Color (RRGGBB)"] = colorToHexString(hourColor);
top["Minute Color (RRGGBB)"] = colorToHexString(minuteColor); top["Minute Color (RRGGBB)"] = colorToHexString(minuteColor);
top["Show Seconds"] = secondsEnabled; top["Show Seconds"] = secondsEnabled;
@ -221,6 +231,8 @@ public:
configComplete &= getJsonValue(top["First LED (Main Ring)"], mainSegment.firstLed, 0); configComplete &= getJsonValue(top["First LED (Main Ring)"], mainSegment.firstLed, 0);
configComplete &= getJsonValue(top["Last LED (Main Ring)"], mainSegment.lastLed, 59); configComplete &= getJsonValue(top["Last LED (Main Ring)"], mainSegment.lastLed, 59);
configComplete &= getJsonValue(top["Center/12h LED (Main Ring)"], mainSegment.centerLed, 0); configComplete &= getJsonValue(top["Center/12h LED (Main Ring)"], mainSegment.centerLed, 0);
configComplete &= getJsonValue(top["Hour marks Enabled"], hourMarksEnabled, false);
configComplete &= getJsonValue(top["Hour mark Color (RRGGBB)"], color, "FF0000") && hexStringToColor(color, hourMarkColor, 0x0000FF);
configComplete &= getJsonValue(top["Hour Color (RRGGBB)"], color, "0000FF") && hexStringToColor(color, hourColor, 0x0000FF); configComplete &= getJsonValue(top["Hour Color (RRGGBB)"], color, "0000FF") && hexStringToColor(color, hourColor, 0x0000FF);
configComplete &= getJsonValue(top["Minute Color (RRGGBB)"], color, "00FF00") && hexStringToColor(color, minuteColor, 0x00FF00); configComplete &= getJsonValue(top["Minute Color (RRGGBB)"], color, "00FF00") && hexStringToColor(color, minuteColor, 0x00FF00);
configComplete &= getJsonValue(top["Show Seconds"], secondsEnabled, true); configComplete &= getJsonValue(top["Show Seconds"], secondsEnabled, true);