|
@@ -44,6 +44,7 @@
|
44
|
44
|
#include "memLayer.h"
|
45
|
45
|
#include "twi.h"
|
46
|
46
|
#include "strings.h"
|
|
47
|
+#include "visualizer.h"
|
47
|
48
|
|
48
|
49
|
#define NOERROR 0
|
49
|
50
|
// Audio does not answer
|
|
@@ -63,9 +64,6 @@ void sendAudioData(void);
|
63
|
64
|
void recieveAnimations(void);
|
64
|
65
|
void transmitAnimations(void);
|
65
|
66
|
uint8_t audioModeSelected(void);
|
66
|
|
-void setPixelBuffer(uint8_t x, uint8_t y, uint8_t z, uint8_t *buf);
|
67
|
|
-void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t *buf);
|
68
|
|
-void visualizeAudioData(uint8_t *audioData, uint8_t *imageData);
|
69
|
67
|
#ifdef DEBUG
|
70
|
68
|
void printErrors(uint8_t e);
|
71
|
69
|
uint8_t selfTest(void);
|
|
@@ -205,16 +203,7 @@ int main(void) {
|
205
|
203
|
if (isFinished()) {
|
206
|
204
|
audioData = getAudioData(); // Not malloc'ed => Don't free
|
207
|
205
|
if (audioData != NULL) {
|
208
|
|
- imageData = (uint8_t *)malloc(64);
|
209
|
|
- if (imageData == NULL) {
|
210
|
|
-#ifdef DEBUG
|
211
|
|
- serialWriteString(getString(24));
|
212
|
|
-#endif
|
213
|
|
- while(1); // Ran out of heap => Watchdog Reset
|
214
|
|
- }
|
215
|
|
- visualizeAudioData(audioData, imageData);
|
216
|
|
- setImage(imageData);
|
217
|
|
- free(imageData);
|
|
206
|
+ simpleVisualization(audioData);
|
218
|
207
|
}
|
219
|
208
|
}
|
220
|
209
|
} else {
|
|
@@ -724,101 +713,3 @@ uint8_t audioModeSelected(void) {
|
724
|
713
|
}
|
725
|
714
|
return lastButtonState;
|
726
|
715
|
}
|
727
|
|
-
|
728
|
|
-void setRow(uint8_t x, uint8_t z, uint8_t height, uint8_t *buf) {
|
729
|
|
- uint8_t i = 0;
|
730
|
|
- for (; i < height; i++) {
|
731
|
|
- setPixelBuffer(x, i, z, buf);
|
732
|
|
- }
|
733
|
|
-}
|
734
|
|
-
|
735
|
|
-void setPixelBuffer(uint8_t x, uint8_t y, uint8_t z, uint8_t *buf) {
|
736
|
|
- buf[(8 * z) + (7 - y)] |= (1 << x);
|
737
|
|
-}
|
738
|
|
-
|
739
|
|
-void visualizeAudioData(uint8_t *audioData, uint8_t *imageData) {
|
740
|
|
- uint8_t i;
|
741
|
|
- for (i = 0; i < 64; i++) {
|
742
|
|
- imageData[i] = 0;
|
743
|
|
- }
|
744
|
|
-
|
745
|
|
- // 8 LEDs, Max Val 255:
|
746
|
|
- // 256 / 8 = 32 => Divide by 31 (FACTOR) to get num of leds to light
|
747
|
|
- // 255 / FACTOR = 8,...
|
748
|
|
- // 127 / FACTOR = 4,...
|
749
|
|
-
|
750
|
|
- #define FACTOR 31
|
751
|
|
-
|
752
|
|
- // Could not figure out a way to represent this easily in a loop
|
753
|
|
- // without using a shitload of 'if's...
|
754
|
|
- setRow(0, 0, (audioData[0] / FACTOR), imageData);
|
755
|
|
- setRow(0, 1, (audioData[0] / FACTOR), imageData);
|
756
|
|
- setRow(1, 0, (audioData[0] / FACTOR), imageData);
|
757
|
|
-
|
758
|
|
- setRow(0, 2, (audioData[1] / FACTOR), imageData);
|
759
|
|
- setRow(0, 3, (audioData[1] / FACTOR), imageData);
|
760
|
|
- setRow(1, 1, (audioData[1] / FACTOR), imageData);
|
761
|
|
- setRow(1, 2, (audioData[1] / FACTOR), imageData);
|
762
|
|
- setRow(2, 0, (audioData[1] / FACTOR), imageData);
|
763
|
|
- setRow(2, 1, (audioData[1] / FACTOR), imageData);
|
764
|
|
-
|
765
|
|
- setRow(0, 4, (audioData[2] / FACTOR), imageData);
|
766
|
|
- setRow(0, 5, (audioData[2] / FACTOR), imageData);
|
767
|
|
- setRow(1, 3, (audioData[2] / FACTOR), imageData);
|
768
|
|
- setRow(1, 4, (audioData[2] / FACTOR), imageData);
|
769
|
|
- setRow(2, 2, (audioData[2] / FACTOR), imageData);
|
770
|
|
- setRow(2, 3, (audioData[2] / FACTOR), imageData);
|
771
|
|
- setRow(3, 0, (audioData[2] / FACTOR), imageData);
|
772
|
|
- setRow(3, 1, (audioData[2] / FACTOR), imageData);
|
773
|
|
- setRow(3, 2, (audioData[2] / FACTOR), imageData);
|
774
|
|
- setRow(4, 0, (audioData[2] / FACTOR), imageData);
|
775
|
|
- setRow(4, 1, (audioData[2] / FACTOR), imageData);
|
776
|
|
-
|
777
|
|
- setRow(0, 6, (audioData[3] / FACTOR), imageData);
|
778
|
|
- setRow(0, 7, (audioData[3] / FACTOR), imageData);
|
779
|
|
- setRow(1, 5, (audioData[3] / FACTOR), imageData);
|
780
|
|
- setRow(1, 6, (audioData[3] / FACTOR), imageData);
|
781
|
|
- setRow(2, 4, (audioData[3] / FACTOR), imageData);
|
782
|
|
- setRow(2, 5, (audioData[3] / FACTOR), imageData);
|
783
|
|
- setRow(3, 3, (audioData[3] / FACTOR), imageData);
|
784
|
|
- setRow(3, 4, (audioData[3] / FACTOR), imageData);
|
785
|
|
- setRow(4, 2, (audioData[3] / FACTOR), imageData);
|
786
|
|
- setRow(4, 3, (audioData[3] / FACTOR), imageData);
|
787
|
|
- setRow(5, 0, (audioData[3] / FACTOR), imageData);
|
788
|
|
- setRow(5, 1, (audioData[3] / FACTOR), imageData);
|
789
|
|
- setRow(5, 2, (audioData[3] / FACTOR), imageData);
|
790
|
|
- setRow(6, 0, (audioData[3] / FACTOR), imageData);
|
791
|
|
- setRow(6, 1, (audioData[3] / FACTOR), imageData);
|
792
|
|
-
|
793
|
|
- setRow(1, 7, (audioData[4] / FACTOR), imageData);
|
794
|
|
- setRow(2, 6, (audioData[4] / FACTOR), imageData);
|
795
|
|
- setRow(2, 7, (audioData[4] / FACTOR), imageData);
|
796
|
|
- setRow(3, 5, (audioData[4] / FACTOR), imageData);
|
797
|
|
- setRow(3, 6, (audioData[4] / FACTOR), imageData);
|
798
|
|
- setRow(4, 4, (audioData[4] / FACTOR), imageData);
|
799
|
|
- setRow(4, 5, (audioData[4] / FACTOR), imageData);
|
800
|
|
- setRow(5, 3, (audioData[4] / FACTOR), imageData);
|
801
|
|
- setRow(5, 4, (audioData[4] / FACTOR), imageData);
|
802
|
|
- setRow(6, 2, (audioData[4] / FACTOR), imageData);
|
803
|
|
- setRow(6, 3, (audioData[4] / FACTOR), imageData);
|
804
|
|
- setRow(7, 0, (audioData[4] / FACTOR), imageData);
|
805
|
|
- setRow(7, 1, (audioData[4] / FACTOR), imageData);
|
806
|
|
-
|
807
|
|
- setRow(3, 7, (audioData[5] / FACTOR), imageData);
|
808
|
|
- setRow(4, 6, (audioData[5] / FACTOR), imageData);
|
809
|
|
- setRow(4, 7, (audioData[5] / FACTOR), imageData);
|
810
|
|
- setRow(5, 5, (audioData[5] / FACTOR), imageData);
|
811
|
|
- setRow(5, 6, (audioData[5] / FACTOR), imageData);
|
812
|
|
- setRow(6, 4, (audioData[5] / FACTOR), imageData);
|
813
|
|
- setRow(6, 5, (audioData[5] / FACTOR), imageData);
|
814
|
|
- setRow(7, 2, (audioData[5] / FACTOR), imageData);
|
815
|
|
- setRow(7, 3, (audioData[5] / FACTOR), imageData);
|
816
|
|
- setRow(7, 4, (audioData[5] / FACTOR), imageData);
|
817
|
|
-
|
818
|
|
- setRow(5, 7, (audioData[6] / FACTOR), imageData);
|
819
|
|
- setRow(6, 6, (audioData[6] / FACTOR), imageData);
|
820
|
|
- setRow(6, 7, (audioData[6] / FACTOR), imageData);
|
821
|
|
- setRow(7, 5, (audioData[6] / FACTOR), imageData);
|
822
|
|
- setRow(7, 6, (audioData[6] / FACTOR), imageData);
|
823
|
|
- setRow(7, 7, (audioData[6] / FACTOR), imageData);
|
824
|
|
-}
|