Browse Source

Built new LED Cube, implemented Lookup Table to compensate for shitty connections.

Thomas Buck 12 years ago
parent
commit
2b48984d79
8 changed files with 766 additions and 662 deletions
  1. 8
    8
      CubeFirmware/builtInFrames.c
  2. 32
    1
      CubeFirmware/cube.c
  3. 5
    13
      CubeFirmware/main.c
  4. 653
    636
      CubeFirmware/main.hex
  5. 2
    2
      CubeFirmware/strings.c
  6. 1
    1
      CubeFirmware/transmit.c
  7. 14
    1
      UploadTest/main.c
  8. 51
    0
      lookUp.c

+ 8
- 8
CubeFirmware/builtInFrames.c View File

51
 								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
51
 								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81,
52
 								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81 };
52
 								0x7e, 0x81, 0x81, 0x81, 0xff, 0x81, 0x81, 0x81 };
53
 
53
 
54
-uint8_t defaultImageC[64] = {	0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
55
-								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
56
-								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
57
-								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
58
-								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
59
-								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
60
-								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02,
61
-								0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02 };
54
+uint8_t defaultImageC[64] = {	0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02,
55
+								0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02,
56
+								0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02,
57
+								0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02,
58
+								0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02,
59
+								0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02,
60
+								0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02,
61
+								0x1e, 0x42, 0x42, 0x42, 0x1e, 0x02, 0x02, 0x02 };
62
 
62
 
63
 #define IDLEANIMATIONCOUNT 3
63
 #define IDLEANIMATIONCOUNT 3
64
 uint8_t *idleAnimation[IDLEANIMATIONCOUNT] = { defaultImageA, defaultImageB, defaultImageC };
64
 uint8_t *idleAnimation[IDLEANIMATIONCOUNT] = { defaultImageA, defaultImageB, defaultImageC };

+ 32
- 1
CubeFirmware/cube.c View File

64
 volatile uint32_t timesTriggered = 0;
64
 volatile uint32_t timesTriggered = 0;
65
 volatile uint8_t warningDisplayed = 0;
65
 volatile uint8_t warningDisplayed = 0;
66
 
66
 
67
+uint8_t lookUp[] = { 	0,  64,  128,  192,  16,  80,  144,  208,  32,  96,  160,
68
+					224,  48,  112,  176,  240,  4,  68,  132,  196,  20,
69
+					84,  148,  212,  36,  100,  164,  228,  52,  116,  180,
70
+					244,  8,  72,  136,  200,  24,  88,  152,  216,  40,
71
+					104,  168,  232,  56,  120,  184,  248,  12,  76,  140,
72
+					204,  28,  92,  156,  220,  44,  108,  172,  236,  60,
73
+					124,  188,  252,  1,  65,  129,  193,  17,  81,  145,
74
+					209,  33,  97,  161,  225,  49,  113,  177,  241,  5,
75
+					69,  133,  197,  21,  85,  149,  213,  37,  101,  165,
76
+					229,  53,  117,  181,  245,  9,  73,  137,  201,  25,
77
+					89,  153,  217,  41,  105,  169,  233,  57,  121,  185,
78
+					249,  13,  77,  141,  205,  29,  93,  157,  221,  45,
79
+					109,  173,  237,  61,  125,  189,  253,  2,  66,  130,
80
+					194,  18,  82,  146,  210,  34,  98,  162,  226,  50,
81
+					114,  178,  242,  6,  70,  134,  198,  22,  86,  150,
82
+					214,  38,  102,  166,  230,  54,  118,  182,  246,  10,
83
+					74,  138,  202,  26,  90,  154,  218,  42,  106,  170,
84
+					234,  58,  122,  186,  250,  14,  78,  142,  206,  30,
85
+					94,  158,  222,  46,  110,  174,  238,  62,  126,  190,
86
+					254,  3,  67,  131,  195,  19,  83,  147,  211,  35,
87
+					99,  163,  227,  51,  115,  179,  243,  7,  71,  135,
88
+					199,  23,  87,  151,  215,  39,  103,  167,  231,  55,
89
+					119,  183,  247,  11,  75,  139,  203,  27,  91,  155,
90
+					219,  43,  107,  171,  235,  59,  123,  187,  251,  15,
91
+					79,  143,  207,  31,  95,  159,  223,  47,  111,  175,
92
+					239,  63,  127,  191,  255 };
93
+
67
 ISR(TIMER1_COMPA_vect) {
94
 ISR(TIMER1_COMPA_vect) {
68
 	if (toggleFlag >= COUNT2) {
95
 	if (toggleFlag >= COUNT2) {
69
 		isrCall();
96
 		isrCall();
78
 	return timesTriggered;
105
 	return timesTriggered;
79
 }
106
 }
80
 
107
 
108
+uint8_t bitSwitch(uint8_t d) {
109
+	return lookUp[d];
110
+}
111
+
81
 void setImage(uint8_t *img) {
112
 void setImage(uint8_t *img) {
82
 	uint8_t i, j;
113
 	uint8_t i, j;
83
 	ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
114
 	ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
86
 		toggleFlag = 0;
117
 		toggleFlag = 0;
87
 		for (i = 0; i < 8; i++) {
118
 		for (i = 0; i < 8; i++) {
88
 			for (j = 0; j < 8; j++) {
119
 			for (j = 0; j < 8; j++) {
89
-				imgBuffer[j][i] = ~(img[j + (i * 8)]);
120
+				imgBuffer[j][i] = ~(bitSwitch(img[j + (i * 8)]));
90
 			}
121
 			}
91
 		}
122
 		}
92
 	}
123
 	}

+ 5
- 13
CubeFirmware/main.c View File

109
 	initSystemTimer();
109
 	initSystemTimer();
110
 	sei(); // Enable Interrupts
110
 	sei(); // Enable Interrupts
111
 
111
 
112
-	wdt_enable(WDTO_1S); // Watchdog reset after 1 second
113
-
114
 	setImage(defaultImageCube); // Display something
112
 	setImage(defaultImageCube); // Display something
115
 
113
 
114
+	wdt_enable(WDTO_1S); // Watchdog reset after 1 second
115
+
116
 #ifdef DEBUG
116
 #ifdef DEBUG
117
 	// Kill animation counter in debug mode
117
 	// Kill animation counter in debug mode
118
 	// => Don't preserve animations while power down
118
 	// => Don't preserve animations while power down
119
 	setAnimationCount(0);
119
 	setAnimationCount(0);
120
 
120
 
121
+	serialWriteString(getString(2));
122
+
121
 	i = selfTest();
123
 	i = selfTest();
122
 	if (i) {
124
 	if (i) {
123
 		serialWriteString(getString(1));
125
 		serialWriteString(getString(1));
126
 		printErrors(i);
128
 		printErrors(i);
127
 	}
129
 	}
128
 
130
 
129
-	serialWriteString(getString(2));
130
 	serialWriteString(getString(0));
131
 	serialWriteString(getString(0));
131
-	
132
-	/* serialWriteString("Took ");
133
-	serialWriteString(itoa(getSystemTime(), buffer, 10));
134
-	serialWriteString(" ms!\n"); */
135
 
132
 
136
 	if (mcusr_mirror & WDRF) {
133
 	if (mcusr_mirror & WDRF) {
137
 		serialWriteString(getString(31));
134
 		serialWriteString(getString(31));
232
 			serialWriteString(getString(28));
229
 			serialWriteString(getString(28));
233
 			DebugDone |= 1;
230
 			DebugDone |= 1;
234
 		}
231
 		}
235
-
236
-		// Show how stable we are running :)
237
-		if (((getSystemTime() % 60000) == 0) && (getSystemTime() > 0)) {
238
-			// serialWriteString(getString(37));
239
-			printTime();
240
-		}
241
 #endif
232
 #endif
242
 
233
 
243
 		if ((getSystemTime() - lastChecked) > 150) { // Check button state every 150ms
234
 		if ((getSystemTime() - lastChecked) > 150) { // Check button state every 150ms
480
 						defaultImageA[y + (i * 8)] |= (1 << z);
471
 						defaultImageA[y + (i * 8)] |= (1 << z);
481
 						setImage(defaultImageA);
472
 						setImage(defaultImageA);
482
 						while (isFinished() == 0) {
473
 						while (isFinished() == 0) {
474
+							wdt_reset();
483
 							if (serialHasChar()) {
475
 							if (serialHasChar()) {
484
 								goto killMeForIt; // Yes I know...
476
 								goto killMeForIt; // Yes I know...
485
 								// But I need to break out of 2 while Loops...
477
 								// But I need to break out of 2 while Loops...

+ 653
- 636
CubeFirmware/main.hex
File diff suppressed because it is too large
View File


+ 2
- 2
CubeFirmware/strings.c View File

30
 const char stringVersion[] PROGMEM = "v2.3 Release\n"; // 0
30
 const char stringVersion[] PROGMEM = "v2.3 Release\n"; // 0
31
 #endif
31
 #endif
32
 
32
 
33
-const char stringInit[] PROGMEM = "Initialized: "; // 1
34
-const char stringSelfTestError[] PROGMEM = "Self-Test Error: 0b"; // 2
33
+const char stringSelfTestError[] PROGMEM = "Self-Test Error: 0b"; // 1
34
+const char stringInit[] PROGMEM = "Initialized: "; // 2
35
 const char stringAudioError[] PROGMEM = " => No answer from Audio!\n"; // 3
35
 const char stringAudioError[] PROGMEM = " => No answer from Audio!\n"; // 3
36
 const char stringMemError[] PROGMEM = " => No answer from Memory!\n"; // 4
36
 const char stringMemError[] PROGMEM = " => No answer from Memory!\n"; // 4
37
 const char stringMemWriteError[] PROGMEM = " => Can't write to Memory!\n"; // 5
37
 const char stringMemWriteError[] PROGMEM = " => Can't write to Memory!\n"; // 5

+ 1
- 1
CubeFirmware/transmit.c View File

34
 #define OK 0x42
34
 #define OK 0x42
35
 #define ERROR 0x23
35
 #define ERROR 0x23
36
 
36
 
37
-#define TRANSTIMEOUT 1500
37
+#define TRANSTIMEOUT 2500
38
 
38
 
39
 // These are global variables from main.c
39
 // These are global variables from main.c
40
 extern char buffer[11];
40
 extern char buffer[11];

+ 14
- 1
UploadTest/main.c View File

25
 	int frameCount = 2;
25
 	int frameCount = 2;
26
 	int duration = 3;
26
 	int duration = 3;
27
 	int data = -1;
27
 	int data = -1;
28
+	char command = -1;
28
 
29
 
29
 	if (argc < 2) {
30
 	if (argc < 2) {
30
 		printf("Usage:\n%s /dev/port [-d 0xff]\n", argv[0]);
31
 		printf("Usage:\n%s /dev/port [-d 0xff]\n", argv[0]);
41
 		frameCount = 1;
42
 		frameCount = 1;
42
 	}
43
 	}
43
 
44
 
45
+	if (argc == 3) {
46
+		command = argv[2][0];
47
+	}
48
+
44
 	signal(SIGINT, intHandler);
49
 	signal(SIGINT, intHandler);
45
 	signal(SIGQUIT, intHandler);
50
 	signal(SIGQUIT, intHandler);
46
 
51
 
47
 	printf("Port opened. Sending test data:\n");
52
 	printf("Port opened. Sending test data:\n");
48
 
53
 
49
 	printf("\tSending command 's'...");
54
 	printf("\tSending command 's'...");
50
-	c = 's';
55
+	if (command != -1) {
56
+		c = command;
57
+	} else {
58
+		c = 's';
59
+	}
51
 	if (serialWriteTry(&c, 1) != 0) {
60
 	if (serialWriteTry(&c, 1) != 0) {
52
 		printf(" Could not send it!\n");
61
 		printf(" Could not send it!\n");
53
 		suicide;
62
 		suicide;
54
 	}
63
 	}
55
 	printf(" Success!\n");
64
 	printf(" Success!\n");
56
 
65
 
66
+	if (command != -1) {
67
+		suicide;
68
+	}
69
+
57
 	readAck();
70
 	readAck();
58
 
71
 
59
 	printf("\tSending anim count (1)...");
72
 	printf("\tSending anim count (1)...");

+ 51
- 0
lookUp.c View File

1
+#include <stdio.h>
2
+
3
+int flip(int d) {
4
+	int n;
5
+	int converted = 0;
6
+	for (n = 0; n < 8; n++) {
7
+		if (d & (1 << (7 - n))) {
8
+			converted |= (1 << n);
9
+		}
10
+	}
11
+	return converted;
12
+}
13
+
14
+int flipAdjacent(int d) {
15
+	int n;
16
+	int converted = 0;
17
+
18
+	for (n = 0; n < 7; n+= 2) {
19
+		if (d & (1 << n)) {
20
+			converted |= (1 << (n + 1));
21
+		} else {
22
+			converted &= ~(1 << (n + 1));
23
+		}
24
+		if (d & (1 << (n + 1))) {
25
+			converted |= (1 << n);
26
+		} else {
27
+			converted &= ~(1 << n);
28
+		}
29
+	}
30
+	return converted;
31
+}
32
+
33
+void main() {
34
+	int byte;
35
+	int converted;
36
+
37
+	printf("penis = {");
38
+	
39
+	for (byte = 0; byte < 256; byte++) {
40
+		converted = flip(byte);
41
+		converted = flipAdjacent(converted);
42
+
43
+		printf(" %d", converted);
44
+		if (((byte % 10) == 0) && (byte > 0)) {
45
+			printf(",\n");
46
+		} else if (byte < 255) {
47
+			printf(", ");
48
+		}
49
+	}
50
+	printf(" }\n");
51
+}

Loading…
Cancel
Save