Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Digital Clock overlay option for 7-segment style clocks #1873

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion wled00/data/settings_time.htm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
{
gId("coc").style.display="none";
}
if (gId("cd").selected)
{
gId("coc").style.display="none";
gId("ccc").style.display="none";
}
}
function BTa()
{
Expand Down Expand Up @@ -119,6 +124,7 @@ <h3>Clock</h3>
<option value="1" id="ca">Analog Clock</option>
<option value="2">Single Digit Clock</option>
<option value="3" id="cc">Cronixie Clock</option>
<option value="4" id="cd">Digital Clock</option>
</select><br>
<div id="coc">
First LED: <input name="O1" type="number" min="0" max="255" required> Last LED: <input name="O2" type="number" min="0" max="255" required><br>
Expand Down Expand Up @@ -152,4 +158,4 @@ <h3>Time-controlled presets</h3>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button>
</form>
</body>
</html>
</html>
1 change: 1 addition & 0 deletions wled00/fcn_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ void handleOverlays();
void handleOverlayDraw();
void _overlayAnalogCountdown();
void _overlayAnalogClock();
void _overlayDigitalClock();

byte getSameCodeLength(char code, int index, char const cronixieDisplay[]);
void setCronixie();
Expand Down
32 changes: 16 additions & 16 deletions wled00/html_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ type="submit">Save</button></form></body></html>)=====";
// Autogenerated from wled00/data/settings_time.htm, do not edit!!
const char PAGE_settings_time[] PROGMEM = R"=====(<!DOCTYPE html><html lang="en"><head><meta name="viewport" content="width=500">
<meta charset="utf-8"><title>Time Settings</title><script>
var d=document;function H(){window.open("https://github.com/Aircoookie/WLED/wiki/Settings#time-settings")}function B(){window.open("/settings","_self")}function S(){BTa(),GetV(),Cs(),FC()}function gId(t){return d.getElementById(t)}function Cs(){gId("cac").style.display="none",gId("coc").style.display="block",gId("ccc").style.display="none",gId("ca").selected&&(gId("cac").style.display="block"),gId("cc").selected&&(gId("coc").style.display="none",gId("ccc").style.display="block"),gId("cn").selected&&(gId("coc").style.display="none")}function BTa(){var t="<tr><th>Active</th><th>Hour</th><th>Minute</th><th>Preset</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></tr>";for(i=0;i<8;i++)for(t+='<tr><td><input name="W'+i+'" id="W'+i+'" type="number" style="display:none"><input id="W'+i+'0" type="checkbox"></td><td><input name="H'+i+'" type="number" min="0" max="24"></td><td><input name="N'+i+'" type="number" min="0" max="59"></td><td><input name="T'+i+'" type="number" min="0" max="250"></td>',j=1;j<8;j++)t+='<td><input id="W'+i+j+'" type="checkbox"></td>';gId("TMT").innerHTML=t}function FC(){for(j=0;j<8;j++)for(i=0;i<8;i++)gId("W"+i+j).checked=gId("W"+i).value>>j&1}function Wd(){for(a=[0,0,0,0,0,0,0,0],i=0;i<8;i++){for(m=1,j=0;j<8;j++)a[i]+=gId("W"+i+j).checked*m,m*=2;gId("W"+i).value=a[i]}}function GetV() {
var d=document;function H(){window.open("https://github.com/Aircoookie/WLED/wiki/Settings#time-settings")}function B(){window.open("/settings","_self")}function S(){BTa(),GetV(),Cs(),FC()}function gId(t){return d.getElementById(t)}function Cs(){gId("cac").style.display="none",gId("coc").style.display="block",gId("ccc").style.display="none",gId("ca").selected&&(gId("cac").style.display="block"),gId("cc").selected&&(gId("coc").style.display="none",gId("ccc").style.display="block"),gId("cn").selected&&(gId("coc").style.display="none"),gId("cd").selected&&(gId("coc").style.display="none",gId("ccc").style.display="none")}function BTa(){var t="<tr><th>Active</th><th>Hour</th><th>Minute</th><th>Preset</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></tr>";for(i=0;i<8;i++)for(t+='<tr><td><input name="W'+i+'" id="W'+i+'" type="number" style="display:none"><input id="W'+i+'0" type="checkbox"></td><td><input name="H'+i+'" type="number" min="0" max="24"></td><td><input name="N'+i+'" type="number" min="0" max="59"></td><td><input name="T'+i+'" type="number" min="0" max="250"></td>',j=1;j<8;j++)t+='<td><input id="W'+i+j+'" type="checkbox"></td>';gId("TMT").innerHTML=t}function FC(){for(j=0;j<8;j++)for(i=0;i<8;i++)gId("W"+i+j).checked=gId("W"+i).value>>j&1}function Wd(){for(a=[0,0,0,0,0,0,0,0],i=0;i<8;i++){for(m=1,j=0;j<8;j++)a[i]+=gId("W"+i+j).checked*m,m*=2;gId("W"+i).value=a[i]}}function GetV() {
%CSS%%SCSS%</head><body onload="S()"><form
id="form_s" name="Sf" method="post" onsubmit="Wd()"><div class="helpB"><button
type="button" onclick="H()">?</button></div><button type="button" onclick="B()">
Expand All @@ -325,21 +325,21 @@ UTC offset: <input name="UO" type="number" min="-65500" max="65500" required>
</span>.<h3>Clock</h3>Clock Overlay: <select name="OL" onchange="Cs()"><option
value="0" id="cn" selected="selected">None</option><option value="1" id="ca">
Analog Clock</option><option value="2">Single Digit Clock</option><option
value="3" id="cc">Cronixie Clock</option></select><br><div id="coc">First LED:
<input name="O1" type="number" min="0" max="255" required> Last LED: <input
name="O2" type="number" min="0" max="255" required><br><div id="cac">12h LED:
<input name="OM" type="number" min="0" max="255" required><br>Show 5min marks:
<input type="checkbox" name="O5"><br></div>Seconds (as trail): <input
type="checkbox" name="OS"><br></div><div id="ccc">Cronixie Display: <input
name="CX" maxlength="6"><br>Cronixie Backlight: <input type="checkbox"
name="CB"><br></div>Countdown Mode: <input type="checkbox" name="CE"><br>
Countdown Goal:<br>Year: 20 <input name="CY" type="number" min="0" max="99"
required> Month: <input name="CI" type="number" min="1" max="12" required> Day:
<input name="CD" type="number" min="1" max="31" required><br>Hour: <input
name="CH" type="number" min="0" max="23" required> Minute: <input name="CM"
type="number" min="0" max="59" required> Second: <input name="CS" type="number"
min="0" max="59" required><br><h3>Macro presets</h3><b>Macros have moved!</b>
<br><i>
value="3" id="cc">Cronixie Clock</option><option value="4" id="cd">Digital Clock
</option></select><br><div id="coc">First LED: <input name="O1" type="number"
min="0" max="255" required> Last LED: <input name="O2" type="number" min="0"
max="255" required><br><div id="cac">12h LED: <input name="OM" type="number"
min="0" max="255" required><br>Show 5min marks: <input type="checkbox"
name="O5"><br></div>Seconds (as trail): <input type="checkbox" name="OS"><br>
</div><div id="ccc">Cronixie Display: <input name="CX" maxlength="6"><br>
Cronixie Backlight: <input type="checkbox" name="CB"><br></div>Countdown Mode:
<input type="checkbox" name="CE"><br>Countdown Goal:<br>Year: 20 <input
name="CY" type="number" min="0" max="99" required> Month: <input name="CI"
type="number" min="1" max="12" required> Day: <input name="CD" type="number"
min="1" max="31" required><br>Hour: <input name="CH" type="number" min="0"
max="23" required> Minute: <input name="CM" type="number" min="0" max="59"
required> Second: <input name="CS" type="number" min="0" max="59" required><br>
<h3>Macro presets</h3><b>Macros have moved!</b><br><i>
Presets now also can be used as macros to save both JSON and HTTP API commands.
<br>Just enter the preset id below!</i> <i>
Use 0 for the default action instead of a preset</i><br>Alexa On/Off Preset:
Expand Down
71 changes: 71 additions & 0 deletions wled00/overlay.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
#include "wled.h"

/*
* Digital clock defines and global
*/

#define NUM_DIGITS 4 // Number of connected Digits
#define NUM_PIXEL_PER_SEGMENT 2 // Number of LEDs in each Segment
#define NUM_PIXEL_PER_DOTS 2 // Number of pixel per dots

#define NUM_DOTS (NUM_DIGITS/2) - 1 //Number of "dots" between digits: 1 for 4 digits, 2 for 6 digits
//Total number of LEDs:
//#define NUM_LEDS (NUM_PIXEL_PER_SEGMENT*7)*NUM_DIGITS + NUM_PIXEL_PER_DOTS

//Digits array
byte digitsMatrix[12] = {
//abcdefg
0b1011111, // 0
0b0000110, // 1
0b1101101, // 2
0b0101111, // 3
0b0110110, // 4
0b0111011, // 5
0b1111011, // 6
0b0001110, // 7
0b1111111, // 8
0b0111111, // 9
0b1011001, // C
0b1111000, // F
};

/*
* Used to draw clock overlays over the strip
*/
Expand Down Expand Up @@ -28,10 +57,42 @@ void handleOverlays()
checkTimers();
checkCountdown();
if (overlayCurrent == 3) _overlayCronixie();//Diamex cronixie clock kit
//if (overlayCurrent == 4) _overlayDigitalClock();
overlayRefreshedTime = millis();
}
}

/*
* Support for the 7-Segment style digital clock
*/
void writeDigit(int index, int val) {
byte digit = digitsMatrix[val];
int margin;
//Choose margin for dots pixel
if (index == 0 || index == 1 ) margin = 0;
if (index == 2 || index == 3 ) margin = 1;
if (index == 4 || index == 5 ) margin = 2;
//Bit vector indexing
for (int i = 6; i >= 0; i--) {
int offset = (index * (NUM_PIXEL_PER_SEGMENT * 7)) + (i * NUM_PIXEL_PER_SEGMENT) + (margin * NUM_PIXEL_PER_DOTS);
//Pixel in a digit indexing
for (int j = offset; j < offset + NUM_PIXEL_PER_SEGMENT; j++) {
if ((digit & 0x01) == 0) {
strip.setPixelColor(j, 0x000000);
}
}
digit = digit >> 1;
}
}

void blinkDots(void) {
int dot;
for (int i = 0; i < NUM_PIXEL_PER_DOTS; i++) {
// 2 digits before first dots pixel
dot = 2 * (NUM_PIXEL_PER_SEGMENT * 7) + i;
if(second(localTime) % 2 == 0) strip.setPixelColor(dot, 0x000000);
}
}

void _overlayAnalogClock()
{
Expand Down Expand Up @@ -119,13 +180,23 @@ void _overlayAnalogCountdown()
overlayRefreshMs = 998;
}

void _overlayDigitalClock()
{
writeDigit(3, hour(localTime) / 10);
writeDigit(2, hour(localTime) % 10);
writeDigit(1, minute(localTime) / 10);
writeDigit(0, minute(localTime) % 10);
blinkDots();
//overlayRefreshMs = 998;
}

void handleOverlayDraw() {
if (!overlayCurrent) return;
switch (overlayCurrent)
{
case 1: _overlayAnalogClock(); break;
case 3: _drawOverlayCronixie(); break;
case 4: _overlayDigitalClock(); break;
}
}

Expand Down