|
| 1 | +// Thanks to Sandro for providing this swiss german version |
| 2 | +const String clockStringSwiss = "ESPESCHAFUFVIERTUBFZAAZWANZGSIVORABOHWORTUHRHAUBIANESSIEISZWOISDRUVIERIYFUFIOSACHSISEBNIACHTINUNIELZANIERBEUFIZWOUFINAGSI"; |
| 3 | + |
| 4 | +/** |
| 5 | + * @brief control the four minute indicator LEDs |
| 6 | + * |
| 7 | + * @param minutes minutes to be displayed [0 ... 59] |
| 8 | + * @param color 24bit color value |
| 9 | + */ |
| 10 | +void drawMinuteIndicator(uint8_t minutes, uint32_t color){ |
| 11 | + //separate LEDs for minutes in an additional row |
| 12 | + { |
| 13 | + switch (minutes%5) |
| 14 | + { |
| 15 | + case 0: |
| 16 | + break; |
| 17 | + |
| 18 | + case 1: |
| 19 | + ledmatrix.setMinIndicator(0b1000, color); |
| 20 | + break; |
| 21 | + |
| 22 | + case 2: |
| 23 | + ledmatrix.setMinIndicator(0b1100, color); |
| 24 | + break; |
| 25 | + |
| 26 | + case 3: |
| 27 | + ledmatrix.setMinIndicator(0b1110, color); |
| 28 | + break; |
| 29 | + |
| 30 | + case 4: |
| 31 | + ledmatrix.setMinIndicator(0b1111, color); |
| 32 | + break; |
| 33 | + } |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +/** |
| 38 | + * @brief Draw the given sentence to the word clock |
| 39 | + * |
| 40 | + * @param message sentence to be displayed |
| 41 | + * @param color 24bit color value |
| 42 | + * @return int: 0 if successful, -1 if sentence not possible to display |
| 43 | + */ |
| 44 | +int showStringOnClock(String message, uint32_t color){ |
| 45 | + String word = ""; |
| 46 | + int lastLetterClock = 0; |
| 47 | + int positionOfWord = 0; |
| 48 | + int index = 0; |
| 49 | + |
| 50 | + // add space on the end of message for splitting |
| 51 | + message = message + " "; |
| 52 | + |
| 53 | + // empty the targetgrid |
| 54 | + ledmatrix.gridFlush(); |
| 55 | + |
| 56 | + while(true){ |
| 57 | + // extract next word from message |
| 58 | + word = split(message, ' ', index); |
| 59 | + index++; |
| 60 | + |
| 61 | + if(word.length() > 0){ |
| 62 | + // find word in clock string |
| 63 | + positionOfWord = clockStringSwiss.indexOf(word, lastLetterClock); |
| 64 | + |
| 65 | + if(positionOfWord >= 0){ |
| 66 | + // word found on clock -> enable leds in targetgrid |
| 67 | + for(unsigned int i = 0; i < word.length(); i++){ |
| 68 | + int x = (positionOfWord + i)%WIDTH; |
| 69 | + int y = (positionOfWord + i)/WIDTH; |
| 70 | + ledmatrix.gridAddPixel(x, y, color); |
| 71 | + } |
| 72 | + // remember end of the word on clock |
| 73 | + lastLetterClock = positionOfWord + word.length(); |
| 74 | + } |
| 75 | + else{ |
| 76 | + // word is not possible to show on clock |
| 77 | + logger.logString("word is not possible to show on clock: " + String(word)); |
| 78 | + return -1; |
| 79 | + } |
| 80 | + }else{ |
| 81 | + // end - no more word in message |
| 82 | + break; |
| 83 | + } |
| 84 | + } |
| 85 | + // return success |
| 86 | + return 0; |
| 87 | +} |
| 88 | + |
| 89 | +/** |
| 90 | + * @brief Converts the given time as sentence (String) |
| 91 | + * |
| 92 | + * @param hours hours of the time value |
| 93 | + * @param minutes minutes of the time value |
| 94 | + * @return String time as sentence |
| 95 | + */ |
| 96 | +String timeToString(uint8_t hours, uint8_t minutes, bool puristModeActive){ |
| 97 | + |
| 98 | + //ES IST |
| 99 | + String message = ""; |
| 100 | + |
| 101 | + if(puristModeActive){ |
| 102 | + message = ""; |
| 103 | + if(minutes < 5 || (minutes >=30 && minutes < 35)){ |
| 104 | + message = "ES ESCH "; |
| 105 | + } |
| 106 | + } |
| 107 | + else{ |
| 108 | + message = "ES ESCH "; |
| 109 | + } |
| 110 | + |
| 111 | + //show minutes |
| 112 | + if(minutes >= 5 && minutes < 10) |
| 113 | + { |
| 114 | + message += "FUF AB "; |
| 115 | + } |
| 116 | + else if(minutes >= 10 && minutes < 15) |
| 117 | + { |
| 118 | + message += "ZAA AB "; |
| 119 | + } |
| 120 | + else if(minutes >= 15 && minutes < 20) |
| 121 | + { |
| 122 | + message += "VIERTU AB "; |
| 123 | + } |
| 124 | + else if(minutes >= 20 && minutes < 25) |
| 125 | + { |
| 126 | + message += "ZWANZG AB "; //Sandro |
| 127 | + } |
| 128 | + else if(minutes >= 25 && minutes < 30) |
| 129 | + { |
| 130 | + message += "FUF VOR HAUBI "; |
| 131 | + } |
| 132 | + else if(minutes >= 30 && minutes < 35) |
| 133 | + { |
| 134 | + message += "HAUBI "; |
| 135 | + } |
| 136 | + else if(minutes >= 35 && minutes < 40) |
| 137 | + { |
| 138 | + message += "FUF AB HAUBI "; |
| 139 | + } |
| 140 | + else if(minutes >= 40 && minutes < 45) |
| 141 | + { |
| 142 | + message += "ZWANZG VOR "; //Sandro |
| 143 | + } |
| 144 | + else if(minutes >= 45 && minutes < 50) |
| 145 | + { |
| 146 | + message += "VIERTU VOR "; |
| 147 | + } |
| 148 | + else if(minutes >= 50 && minutes < 55) |
| 149 | + { |
| 150 | + message += "ZAA VOR "; |
| 151 | + } |
| 152 | + else if(minutes >= 55 && minutes < 60) |
| 153 | + { |
| 154 | + message += "FUF VOR "; |
| 155 | + } |
| 156 | + |
| 157 | + //convert hours to 12h format |
| 158 | + if(hours >= 12) |
| 159 | + { |
| 160 | + hours -= 12; |
| 161 | + } |
| 162 | + if(minutes >= 25) //Sandro 20 |
| 163 | + { |
| 164 | + hours++; |
| 165 | + } |
| 166 | + if(hours == 12) |
| 167 | + { |
| 168 | + hours = 0; |
| 169 | + } |
| 170 | + |
| 171 | + // show hours |
| 172 | + switch(hours) |
| 173 | + { |
| 174 | + case 0: |
| 175 | + message += "ZWOUFI "; |
| 176 | + break; |
| 177 | + case 1: |
| 178 | + message += "EIS "; |
| 179 | + // //EIN(S) |
| 180 | + // if(minutes > 4){ // Sandro |
| 181 | + // message += "S"; |
| 182 | + // } |
| 183 | + // message += " "; |
| 184 | + break; |
| 185 | + case 2: |
| 186 | + message += "ZWOI "; |
| 187 | + break; |
| 188 | + case 3: |
| 189 | + message += "DRU "; |
| 190 | + break; |
| 191 | + case 4: |
| 192 | + message += "VIERI "; |
| 193 | + break; |
| 194 | + case 5: |
| 195 | + message += "FUFI "; |
| 196 | + break; |
| 197 | + case 6: |
| 198 | + message += "SACHSI "; |
| 199 | + break; |
| 200 | + case 7: |
| 201 | + message += "SEBNI "; |
| 202 | + break; |
| 203 | + case 8: |
| 204 | + message += "ACHTI "; |
| 205 | + break; |
| 206 | + case 9: |
| 207 | + message += "NUNI "; |
| 208 | + break; |
| 209 | + case 10: |
| 210 | + message += "ZANI "; |
| 211 | + break; |
| 212 | + case 11: |
| 213 | + message += "EUFI "; |
| 214 | + break; |
| 215 | + } |
| 216 | + if(minutes < 5) |
| 217 | + { |
| 218 | + message += "GSI "; |
| 219 | + } |
| 220 | + |
| 221 | + logger.logString("time as String: " + String(message)); |
| 222 | + |
| 223 | + return message; |
| 224 | +} |
| 225 | + |
0 commit comments