-
Notifications
You must be signed in to change notification settings - Fork 20
/
wordclockfunctions.ino_french
174 lines (154 loc) · 4.38 KB
/
wordclockfunctions.ino_french
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
const String clockStringFrench = "IL EST DEUXQUATRETROISNEUFUNESEPTHUITSIXCINQMIDI MINUITONZE HEURESMOINS ETDIXETQUART VINGT-CINQ ET DEMIE TRENTE-CINQ";
/**
* @brief control the four minute indicator LEDs
*
* @param minutes minutes to be displayed [0 ... 59]
* @param color 24bit color value
*/
void drawMinuteIndicator(uint8_t minutes, uint32_t color){
//separate LEDs for minutes in an additional row
{
switch (minutes%5)
{
case 0:
break;
case 1:
ledmatrix.setMinIndicator(0b1000, color);
break;
case 2:
ledmatrix.setMinIndicator(0b1100, color);
break;
case 3:
ledmatrix.setMinIndicator(0b1110, color);
break;
case 4:
ledmatrix.setMinIndicator(0b1111, color);
break;
}
}
}
/**
* @brief Draw the given sentence to the word clock
*
* @param message sentence to be displayed
* @param color 24bit color value
* @return int: 0 if successful, -1 if sentence not possible to display
*/
int showStringOnClock(String message, uint32_t color){
String word = "";
int lastLetterClock = 0;
int positionOfWord = 0;
int index = 0;
// add space on the end of message for splitting
message = message + " ";
// empty the targetgrid
ledmatrix.gridFlush();
while(true){
// extract next word from message
word = split(message, ' ', index);
index++;
if(word.length() > 0){
// find word in clock string
positionOfWord = clockStringFrench.indexOf(word, lastLetterClock);
if(positionOfWord >= 0){
// word found on clock -> enable leds in targetgrid
for(unsigned int i = 0; i < word.length(); i++){
int x = (positionOfWord + i)%WIDTH;
int y = (positionOfWord + i)/WIDTH;
ledmatrix.gridAddPixel(x, y, color);
}
// remember end of the word on clock
lastLetterClock = positionOfWord + word.length();
}
else{
// word is not possible to show on clock
logger.logString("word is not possible to show on clock: " + String(word));
return -1;
}
}else{
// end - no more word in message
break;
}
}
// return success
return 0;
}
/**
* @brief convert the given number to french
*
* @param number number to be converted
* @return String number as french
*/
String numberToFrench(uint8_t number) {
switch (number) {
case 1: return "UNE";
case 2: return "DEUX";
case 3: return "TROIS";
case 4: return "QUATRE";
case 5: return "CINQ";
case 6: return "SIX";
case 7: return "SEPT";
case 8: return "HUIT";
case 9: return "NEUF";
case 10: return "DIX";
case 11: return "ONZE";
case 12: return "DOUZE";
default: return "";
}
}
/**
* @brief Converts the given time as sentence (String)
*
* @param hours hours of the time value
* @param minutes minutes of the time value
* @return String time as sentence
*/
String timeToString(uint8_t hours, uint8_t minutes) {
// Runden der Minuten auf den nächsten 5-Minuten-Takt
minutes = minutes / 5 * 5;
// ES IST
String message = "IL EST ";
if(minutes >= 35)
{
hours++;
}
if ((hours == 0 && minutes <= 30) || (hours == 24 && minutes >= 35)) {
message += "MINUIT";
} else if (hours == 12 && minutes <= 30) {
message += "MIDI";
} else {
uint8_t hours12h = hours;
if (hours12h > 12) {
hours12h -= 12;
}
message += numberToFrench(hours12h) + " HEURE" + (hours12h > 1 ? "S" : "");
}
// Minuten formatieren
if (minutes == 0) {
// Keine Minuten, nur volle Stunde
return message;
} else if (minutes == 5) {
message += " CINQ";
} else if (minutes == 10) {
message += " DIX";
} else if (minutes == 15) {
message += " ET QUART";
} else if (minutes == 20) {
message += " VINGT";
} else if (minutes == 25) {
message += " VINGT-CINQ";
} else if (minutes == 30) {
message += " ET DEMI" + String((hours == 0 || hours == 12 || hours == 13) ? "" : "E");
} else if (minutes == 35) {
message += " MOINS VINGT-CINQ";
} else if (minutes == 40) {
message += " MOINS VINGT";
} else if (minutes == 45) {
message += " MOINS QUART";
} else if (minutes == 50) {
message += " MOINS DIX";
} else if (minutes == 55) {
message += " MOINS CINQ";
}
return message;
}