|
@@ -80,16 +80,37 @@ uint8_t lastButtonState = 0;
|
80
|
80
|
uint8_t mcusr_mirror;
|
81
|
81
|
char buffer[11];
|
82
|
82
|
|
83
|
|
-uint8_t defaultImage[64] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
84
|
|
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
85
|
|
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
86
|
|
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
87
|
|
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
88
|
|
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
89
|
|
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
90
|
|
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
91
|
|
-
|
92
|
|
-uint8_t DebugDone = 0; // Bit 0: 10s int. count, Bit 1: switch idle display
|
|
83
|
+uint8_t defaultImageA[64] = { 0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
|
|
84
|
+ 0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
|
|
85
|
+ 0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
|
|
86
|
+ 0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
|
|
87
|
+ 0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
|
|
88
|
+ 0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
|
|
89
|
+ 0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff,
|
|
90
|
+ 0xff, 0x01, 0x01, 0x01, 0xff, 0x80, 0x80, 0xff };
|
|
91
|
+
|
|
92
|
+uint8_t defaultImageB[64] = { 0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
|
|
93
|
+ 0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
|
|
94
|
+ 0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
|
|
95
|
+ 0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
|
|
96
|
+ 0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
|
|
97
|
+ 0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
|
|
98
|
+ 0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
|
|
99
|
+ 0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81 };
|
|
100
|
+
|
|
101
|
+uint8_t defaultImageC[64] = { 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
|
|
102
|
+ 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
|
|
103
|
+ 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
|
|
104
|
+ 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
|
|
105
|
+ 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
|
|
106
|
+ 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
|
|
107
|
+ 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
|
|
108
|
+ 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02 };
|
|
109
|
+
|
|
110
|
+#define IDLEANIMATIONCOUNT 3
|
|
111
|
+uint8_t *idleAnimation[IDLEANIMATIONCOUNT] = { defaultImageA, defaultImageB, defaultImageC };
|
|
112
|
+
|
|
113
|
+uint8_t DebugDone = 0; // Bit 0: 10s int. count, Bit 1: unused
|
93
|
114
|
// Bit 2: state changed, disable idle
|
94
|
115
|
|
95
|
116
|
int main(void) {
|
|
@@ -98,7 +119,10 @@ int main(void) {
|
98
|
119
|
uint8_t i, length = 0, lastMode;
|
99
|
120
|
uint16_t count;
|
100
|
121
|
uint64_t lastChecked;
|
|
122
|
+ uint8_t idleCounter = 0;
|
|
123
|
+#ifdef DEBUG
|
101
|
124
|
uint32_t temp;
|
|
125
|
+#endif
|
102
|
126
|
|
103
|
127
|
mcusr_mirror = MCUCSR;
|
104
|
128
|
MCUCSR = 0;
|
|
@@ -110,14 +134,15 @@ int main(void) {
|
110
|
134
|
initSystemTimer();
|
111
|
135
|
sei(); // Enable Interrupts
|
112
|
136
|
|
113
|
|
- wdt_enable(WDTO_500MS); // Enable watchdog reset after 500ms
|
|
137
|
+ // wdt_enable(WDTO_500MS); // Enable watchdog reset after 500ms
|
|
138
|
+ wdt_enable(WDTO_1S); // Watchdog reset after 1 second
|
114
|
139
|
|
115
|
140
|
DDRA = 0xFF; // Latch Data Bus as Output
|
116
|
141
|
DDRD = 0xFC; DDRB = 24; // Mosfets as Output
|
117
|
142
|
DDRC = 0xFC; DDRB |= 6; // Latch Enable as Output
|
118
|
143
|
DDRB &= ~(1 << PB0); // Pushbutton as Input
|
119
|
144
|
|
120
|
|
- setImage(defaultImage); // Display something
|
|
145
|
+ setImage(defaultImageA); // Display something
|
121
|
146
|
|
122
|
147
|
#ifdef DEBUG
|
123
|
148
|
// Kill animation counter in debug mode
|
|
@@ -167,14 +192,14 @@ int main(void) {
|
167
|
192
|
if(lastMode) {
|
168
|
193
|
// Get Audio Data and visualize it
|
169
|
194
|
if (isFinished()) {
|
170
|
|
- audioData = getAudioData();
|
|
195
|
+ audioData = getAudioData(); // Not malloc'ed => Don't free
|
171
|
196
|
if (audioData != NULL) {
|
172
|
197
|
imageData = (uint8_t *)malloc(64);
|
173
|
198
|
if (imageData == NULL) {
|
174
|
199
|
#ifdef DEBUG
|
175
|
200
|
serialWriteString(getString(24));
|
176
|
201
|
#endif
|
177
|
|
- while(1);
|
|
202
|
+ while(1); // Ran out of heap => Watchdog Reset
|
178
|
203
|
}
|
179
|
204
|
visualizeAudioData(audioData, imageData);
|
180
|
205
|
setImage(imageData);
|
|
@@ -204,15 +229,14 @@ int main(void) {
|
204
|
229
|
free(imageData);
|
205
|
230
|
}
|
206
|
231
|
} else {
|
207
|
|
- if (!(DebugDone & 4)) {
|
|
232
|
+ if (!(DebugDone & 4)) { // Idle animation allowed
|
208
|
233
|
if (isFinished() >= IDLELENGTH) {
|
209
|
234
|
// Should happen every half second
|
210
|
|
- if (DebugDone & 2) {
|
211
|
|
- fillBuffer(0);
|
212
|
|
- DebugDone &= ~(2);
|
|
235
|
+ setImage(idleAnimation[idleCounter]);
|
|
236
|
+ if (idleCounter < (IDLEANIMATIONCOUNT - 1)) {
|
|
237
|
+ idleCounter++;
|
213
|
238
|
} else {
|
214
|
|
- fillBuffer(0xFF);
|
215
|
|
- DebugDone |= 2;
|
|
239
|
+ idleCounter = 0;
|
216
|
240
|
}
|
217
|
241
|
}
|
218
|
242
|
}
|
|
@@ -269,8 +293,8 @@ uint8_t selfTest(void) {
|
269
|
293
|
free(data);
|
270
|
294
|
}
|
271
|
295
|
|
272
|
|
- setGeneralPurposeByte(0, 0x42);
|
273
|
|
- if (getGeneralPurposeByte(0) != 0x42) {
|
|
296
|
+ setGeneralPurposeByte(0, 0x23);
|
|
297
|
+ if (getGeneralPurposeByte(0) != 0x23) {
|
274
|
298
|
result |= MEMORYWRITEERROR;
|
275
|
299
|
}
|
276
|
300
|
|
|
@@ -321,8 +345,8 @@ void randomAnimation(void) {
|
321
|
345
|
void serialHandler(char c) {
|
322
|
346
|
// Used letters:
|
323
|
347
|
// a, c, d, e, g, i, n, q, r, s, t, v, x, y, 0, 1, 2
|
324
|
|
- uint8_t i, y, z;
|
325
|
348
|
#ifdef DEBUG
|
|
349
|
+ uint8_t i, y, z;
|
326
|
350
|
serialWrite(c);
|
327
|
351
|
serialWriteString(": ");
|
328
|
352
|
#endif
|
|
@@ -371,6 +395,11 @@ void serialHandler(char c) {
|
371
|
395
|
break;
|
372
|
396
|
|
373
|
397
|
#ifdef DEBUG
|
|
398
|
+ case 'm': case 'M':
|
|
399
|
+ lastButtonState = !lastButtonState;
|
|
400
|
+ serialWriteString(getString(40));
|
|
401
|
+ break;
|
|
402
|
+
|
374
|
403
|
case 'q': case 'Q':
|
375
|
404
|
shouldRestart = 1;
|
376
|
405
|
serialWriteString(getString(30));
|
|
@@ -434,15 +463,15 @@ void serialHandler(char c) {
|
434
|
463
|
DebugDone |= 4;
|
435
|
464
|
fillBuffer(0);
|
436
|
465
|
for (i = 0; i < 64; i++) {
|
437
|
|
- defaultImage[i] = 0;
|
|
466
|
+ defaultImageA[i] = 0;
|
438
|
467
|
}
|
439
|
468
|
while(1) {
|
440
|
469
|
for (i = 0; i < 8; i++) {
|
441
|
470
|
for (y = 0; y < 8; y++) {
|
442
|
|
- defaultImage[y + (i * 8)] = 0;
|
|
471
|
+ defaultImageA[y + (i * 8)] = 0;
|
443
|
472
|
for (z = 0; z < 8; z++) {
|
444
|
|
- defaultImage[y + (i * 8)] |= (1 << z);
|
445
|
|
- setImage(defaultImage);
|
|
473
|
+ defaultImageA[y + (i * 8)] |= (1 << z);
|
|
474
|
+ setImage(defaultImageA);
|
446
|
475
|
while (isFinished() == 0) {
|
447
|
476
|
if (serialHasChar()) {
|
448
|
477
|
goto killMeForIt; // Yes I know...
|
|
@@ -450,7 +479,7 @@ void serialHandler(char c) {
|
450
|
479
|
}
|
451
|
480
|
}
|
452
|
481
|
}
|
453
|
|
- defaultImage[y + (i * 8)] = 0;
|
|
482
|
+ defaultImageA[y + (i * 8)] = 0;
|
454
|
483
|
}
|
455
|
484
|
}
|
456
|
485
|
}
|
|
@@ -669,9 +698,11 @@ uint8_t audioModeSelected(void) {
|
669
|
698
|
}
|
670
|
699
|
|
671
|
700
|
#ifdef DEBUG
|
672
|
|
- serialWriteString("New State (");
|
673
|
|
- serialWriteString(itoa(lastButtonState, buffer, 10));
|
674
|
|
- serialWriteString(")\n");
|
|
701
|
+ if (lastButtonState) {
|
|
702
|
+ serialWriteString(getString(38));
|
|
703
|
+ } else {
|
|
704
|
+ serialWriteString(getString(39));
|
|
705
|
+ }
|
675
|
706
|
#endif
|
676
|
707
|
|
677
|
708
|
}
|
|
@@ -686,7 +717,7 @@ void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t *buf) {
|
686
|
717
|
}
|
687
|
718
|
|
688
|
719
|
void setPixelBuffer(uint8_t x, uint8_t y, uint8_t z, uint8_t *buf) {
|
689
|
|
- buf[(8 * z) + y] |= (1 << x);
|
|
720
|
+ buf[(8 * z) + (7 - y)] |= (1 << x);
|
690
|
721
|
}
|
691
|
722
|
|
692
|
723
|
void visualizeAudioData(uint8_t *audioData, uint8_t *imageData) {
|