-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.js
95 lines (86 loc) · 2.09 KB
/
clock.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const ledControl = require('./ledControl');
let currentMinute;
function getMinute(minutes) {
return minutes % 5;
}
function getPrefix(roundedMinutes) {
if (roundedMinutes > 35 || roundedMinutes === 25) {
return ledControl.VOR;
} else if (roundedMinutes >= 5 && roundedMinutes < 25 || roundedMinutes === 35) {
return ledControl.AB;
}
}
function getBundle(roundedMinutes) {
switch (roundedMinutes) {
case 5:
case 25:
case 35:
case 55:
return ledControl.FOEIF;
case 15:
case 45:
return ledControl.VIERTU;
case 10:
case 50:
return ledControl.ZAEH;
case 20:
case 40:
return ledControl.ZWAENZG;
}
}
function getHalf(roundedMinutes) {
if (roundedMinutes >= 25 && roundedMinutes < 40) {
return ledControl.HALBI;
}
}
function getHours(minutes, hours) {
const hourToShow = minutes >= 25 ? hours + 1 : hours;
switch(hourToShow % 12) {
case 1:
return ledControl.EIS;
case 2:
return ledControl.ZWOEI;
case 3:
return ledControl.DRUE;
case 4:
return ledControl.VIERI;
case 5:
return ledControl.FOEIFI;
case 6:
return ledControl.SAECHSI;
case 7:
return ledControl.SEBNI;
case 8:
return ledControl.ACHTI;
case 9:
return ledControl.NUENI;
case 10:
return ledControl.ZAEHNI;
case 11:
return ledControl.ELFI;
case 12:
return ledControl.ZWOELFI;
}
}
function updateClock(minutes, hours) {
const roundedMinutes = Math.floor(minutes / 5) * 5;
ledControl.updateChain(
[
ledControl.CONSTANT,
getBundle(roundedMinutes),
getHalf(minutes),
getPrefix(roundedMinutes),
getHours(minutes, hours),
].filter(value => value !== undefined),
getMinute(minutes)
);
}
function updateInterval() {
const currentDate = new Date();
setTimeout(updateInterval, 1000 - currentDate.getMilliseconds());
if (currentMinute !== currentDate.getMinutes()) {
currentMinute = currentDate.getMinutes();
updateClock(currentDate.getMinutes(), currentDate.getHours());
}
}
module.exports = updateInterval;