|
@@ -34,6 +34,7 @@
|
34
|
34
|
#include <avr/pgmspace.h>
|
35
|
35
|
#include <stdint.h>
|
36
|
36
|
#include <stdlib.h>
|
|
37
|
+#include <avr/wdt.h>
|
37
|
38
|
|
38
|
39
|
#include "serial.h"
|
39
|
40
|
#include "cube.h"
|
|
@@ -73,8 +74,10 @@ void printTime(void);
|
73
|
74
|
#include "snake.c"
|
74
|
75
|
#endif
|
75
|
76
|
|
|
77
|
+uint8_t shouldRestart = 0;
|
76
|
78
|
uint8_t refreshAnimationCount = 1;
|
77
|
79
|
uint8_t lastButtonState = 0;
|
|
80
|
+uint8_t mcusr_mirror;
|
78
|
81
|
char buffer[11];
|
79
|
82
|
|
80
|
83
|
uint8_t defaultImage[64] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
|
@@ -97,12 +100,18 @@ int main(void) {
|
97
|
100
|
uint64_t lastChecked;
|
98
|
101
|
uint32_t temp;
|
99
|
102
|
|
|
103
|
+ mcusr_mirror = MCUCSR;
|
|
104
|
+ MCUCSR = 0;
|
|
105
|
+ wdt_disable();
|
|
106
|
+
|
100
|
107
|
initCube();
|
101
|
108
|
serialInit(25, 8, NONE, 1);
|
102
|
109
|
i2c_init();
|
103
|
110
|
initSystemTimer();
|
104
|
111
|
sei(); // Enable Interrupts
|
105
|
112
|
|
|
113
|
+ wdt_enable(WDTO_500MS); // Enable watchdog reset after 500ms
|
|
114
|
+
|
106
|
115
|
DDRD = 0xFC; // Mosfets as Output
|
107
|
116
|
DDRB = 0xFE;
|
108
|
117
|
DDRC = 0xFF; // Latch Enable
|
|
@@ -122,14 +131,26 @@ int main(void) {
|
122
|
131
|
serialWrite('\n');
|
123
|
132
|
printErrors(i);
|
124
|
133
|
}
|
125
|
|
-#endif
|
126
|
134
|
|
127
|
|
-#ifdef DEBUG
|
128
|
135
|
serialWriteString(getString(2));
|
129
|
136
|
serialWriteString(getString(0));
|
130
|
137
|
serialWriteString("Took ");
|
131
|
138
|
serialWriteString(itoa(getSystemTime(), buffer, 10));
|
132
|
139
|
serialWriteString(" ms!\n");
|
|
140
|
+
|
|
141
|
+ if (mcusr_mirror & WDRF) {
|
|
142
|
+ serialWriteString(getString(31));
|
|
143
|
+ } else if (mcusr_mirror & BORF) {
|
|
144
|
+ serialWriteString(getString(32));
|
|
145
|
+ } else if (mcusr_mirror & EXTRF) {
|
|
146
|
+ serialWriteString(getString(34));
|
|
147
|
+ } else if (mcusr_mirror & JTRF) {
|
|
148
|
+ serialWriteString(getString(35));
|
|
149
|
+ } else if (mcusr_mirror & PORF) {
|
|
150
|
+ serialWriteString(getString(36));
|
|
151
|
+ } else {
|
|
152
|
+ serialWriteString(getString(33));
|
|
153
|
+ }
|
133
|
154
|
#endif
|
134
|
155
|
|
135
|
156
|
lastMode = audioModeSelected();
|
|
@@ -138,6 +159,11 @@ int main(void) {
|
138
|
159
|
i = 0;
|
139
|
160
|
count = getAnimationCount();
|
140
|
161
|
while (1) {
|
|
162
|
+ // Reset if requested
|
|
163
|
+ if (!shouldRestart) {
|
|
164
|
+ wdt_reset();
|
|
165
|
+ }
|
|
166
|
+
|
141
|
167
|
if(lastMode) {
|
142
|
168
|
// Get Audio Data and visualize it
|
143
|
169
|
if (isFinished()) {
|
|
@@ -197,6 +223,8 @@ int main(void) {
|
197
|
223
|
serialHandler((char)(serialGet()));
|
198
|
224
|
}
|
199
|
225
|
|
|
226
|
+#ifdef DEBUG
|
|
227
|
+ // Print frames per second
|
200
|
228
|
if ((getSystemTime() >= 1000) && ((DebugDone & 1) == 0)) {
|
201
|
229
|
temp = getTriggerCount();
|
202
|
230
|
serialWriteString(ltoa(temp, buffer, 10));
|
|
@@ -206,6 +234,13 @@ int main(void) {
|
206
|
234
|
DebugDone |= 1;
|
207
|
235
|
}
|
208
|
236
|
|
|
237
|
+ // Show how stable we are running :)
|
|
238
|
+ if (((getSystemTime() % 60000) == 0) && (getSystemTime() > 0)) {
|
|
239
|
+ serialWriteString(getString(37));
|
|
240
|
+ printTime();
|
|
241
|
+ }
|
|
242
|
+#endif
|
|
243
|
+
|
209
|
244
|
if ((getSystemTime() - lastChecked) > 150) {
|
210
|
245
|
lastMode = audioModeSelected();
|
211
|
246
|
lastChecked = getSystemTime();
|
|
@@ -285,7 +320,7 @@ void randomAnimation(void) {
|
285
|
320
|
|
286
|
321
|
void serialHandler(char c) {
|
287
|
322
|
// Used letters:
|
288
|
|
- // a, c, d, e, g, i, n, r, s, t, v, x, y, 0, 1, 2
|
|
323
|
+ // a, c, d, e, g, i, n, q, r, s, t, v, x, y, 0, 1, 2
|
289
|
324
|
uint8_t i, y, z;
|
290
|
325
|
#ifdef DEBUG
|
291
|
326
|
serialWrite(c);
|
|
@@ -336,6 +371,11 @@ void serialHandler(char c) {
|
336
|
371
|
break;
|
337
|
372
|
|
338
|
373
|
#ifdef DEBUG
|
|
374
|
+ case 'q': case 'Q':
|
|
375
|
+ shouldRestart = 1;
|
|
376
|
+ serialWriteString(getString(30));
|
|
377
|
+ break;
|
|
378
|
+
|
339
|
379
|
case 'r': case 'R':
|
340
|
380
|
randomAnimation();
|
341
|
381
|
break;
|
|
@@ -438,6 +478,11 @@ void printTime(void) {
|
438
|
478
|
serialWriteString(getString(14));
|
439
|
479
|
serialWriteString(ltoa(getSystemTime(), buffer, 10));
|
440
|
480
|
serialWriteString("ms");
|
|
481
|
+ if (getSystemTime() > 60000) {
|
|
482
|
+ serialWriteString(" (");
|
|
483
|
+ serialWriteString(itoa(getSystemTime() / 60000, buffer, 10));
|
|
484
|
+ serialWriteString(" min)");
|
|
485
|
+ }
|
441
|
486
|
if (getSystemTime() > 1000) {
|
442
|
487
|
serialWriteString(" (");
|
443
|
488
|
serialWriteString(itoa(getSystemTime() / 1000, buffer, 10));
|