summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerdgeist <erdgeist@bauklotz.fritz.box>2018-04-02 01:36:53 +0200
committererdgeist <erdgeist@bauklotz.fritz.box>2018-04-02 01:36:53 +0200
commitc12537f51ecd538f74efe568e9965bb79a68ddd2 (patch)
tree247d7cc97842552bcea57f601e88d2b3b5bdc3b1
parent6cb3ed41fa2cd5da825c2e03e992f590863a417c (diff)
Add support for new board revision
-rw-r--r--arduino/Laserharfe/Laserharfe.ino27
1 files changed, 21 insertions, 6 deletions
diff --git a/arduino/Laserharfe/Laserharfe.ino b/arduino/Laserharfe/Laserharfe.ino
index 107dffb..1d7adeb 100644
--- a/arduino/Laserharfe/Laserharfe.ino
+++ b/arduino/Laserharfe/Laserharfe.ino
@@ -9,8 +9,8 @@
9int led = 13; 9int led = 13;
10int g_reading_config = 0; 10int g_reading_config = 0;
11int g_writing_config = 0; 11int g_writing_config = 0;
12ConfigSource g_config_source = source_none;
13//Sd2Card card; 12//Sd2Card card;
13char g_revision;
14 14
15enum { 15enum {
16 MODE_STANDALONE = 0, 16 MODE_STANDALONE = 0,
@@ -81,7 +81,8 @@ static void set_cam_register(uint8_t r, uint8_t v) {
81} 81}
82 82
83static void setup_cam() { 83static void setup_cam() {
84 digitalWrite(19, HIGH); // turn the LED on (HIGH is the voltage level) 84 digitalWrite(g_revision == 2 ? 16 : 19, HIGH); // Alte Harfe: port 19/A5/PB02/Pin 47
85 // Neue Harfe: port 16/A2/PB09/Pin 8
85 set_cam_register(0x30, 0x01); 86 set_cam_register(0x30, 0x01);
86 set_cam_register(0x06, 0x90); 87 set_cam_register(0x06, 0x90);
87 set_cam_register(0x08, 0xc0); 88 set_cam_register(0x08, 0xc0);
@@ -128,16 +129,20 @@ void read_config() {
128} 129}
129 130
130void write_config() { 131void write_config() {
132 Serial.println("- removing config file");
131 SD.remove("laserhar.cfg"); 133 SD.remove("laserhar.cfg");
134 Serial.println("- ... done, open new config file");
132 File configfile = SD.open("laserhar.cfg", FILE_WRITE); 135 File configfile = SD.open("laserhar.cfg", FILE_WRITE);
133 if (!configfile) { 136 if (!configfile) {
134 Serial.println("opening config failed"); 137 Serial.println("- opening config failed");
135 return; 138 return;
136 } 139 }
140 Serial.println("- ... done, writing globals");
137 141
138 char text[256]; 142 char text[256];
139 size_t len = config_dumpglobals(text, sizeof(text)); 143 size_t len = config_dumpglobals(text, sizeof(text));
140 configfile.write(text, len); 144 configfile.write(text, len);
145 Serial.println("- ... done, writing globals");
141 for (int i=0; i< g_string_count; ++i) { 146 for (int i=0; i< g_string_count; ++i) {
142 len = config_dumpstring(i, text, sizeof(text)); 147 len = config_dumpstring(i, text, sizeof(text));
143 configfile.write(text, len); 148 configfile.write(text, len);
@@ -156,6 +161,11 @@ void flashy_death() {
156} 161}
157 162
158void setup() { 163void setup() {
164 pinMode(5, INPUT_PULLUP);
165 delay(10);
166 g_revision = digitalRead(5) == LOW ? 2 : 1;
167
168 Serial.begin(115200);
159 pinMode(led, OUTPUT); 169 pinMode(led, OUTPUT);
160 170
161 Wire.begin(); 171 Wire.begin();
@@ -165,8 +175,7 @@ void setup() {
165 // Let PWM settle for a bit 175 // Let PWM settle for a bit
166 delay(100); 176 delay(100);
167 setup_cam(); 177 setup_cam();
168 Serial.begin(115200); 178 delay(1000);
169 delay(5000);
170 read_config(); 179 read_config();
171 digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level) 180 digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level)
172} 181}
@@ -227,6 +236,7 @@ void handle_wire() {
227 if (p4.x!=1023) 236 if (p4.x!=1023)
228 Serial.write(text, sprintf(text, "%04d:%04d ", p4.x, p4.y)); 237 Serial.write(text, sprintf(text, "%04d:%04d ", p4.x, p4.y));
229 Serial.println(""); 238 Serial.println("");
239 delay(5);
230} 240}
231 241
232/* Do a fast nibble to hex representation conversion */ 242/* Do a fast nibble to hex representation conversion */
@@ -278,11 +288,13 @@ void handle_command(char *command) {
278// Serial.write( text, sprintf(text, "- %s\n", command)); 288// Serial.write( text, sprintf(text, "- %s\n", command));
279 289
280 if (g_reading_config ) { 290 if (g_reading_config ) {
281 if ( !strcmp(command, "-- DONE")) { 291 if ( !memcmp(command, "-- DONE", 7)) {
292 Serial.println("- finished import");
282 g_reading_config = 0; 293 g_reading_config = 0;
283 return; 294 return;
284 } 295 }
285 config_handle_line(command); 296 config_handle_line(command);
297 delay(10);
286 return; 298 return;
287 } 299 }
288 300
@@ -302,12 +314,15 @@ void handle_command(char *command) {
302 g_mode = MODE_REPORTPOINTS; 314 g_mode = MODE_REPORTPOINTS;
303 break; 315 break;
304 } 316 }
317 Serial.println(g_revision == 2 ? "revision 2" : "revision 1");
305 break; 318 break;
306 case 'C': /* Import a single config line from host */ 319 case 'C': /* Import a single config line from host */
307 config_handle_line(command+1); 320 config_handle_line(command+1);
308 break; 321 break;
309 case 'E': /* Export config from host, import here */ 322 case 'E': /* Export config from host, import here */
310 config_reset(); 323 config_reset();
324 Serial.println("- export from host triggered");
325 delay(100);
311 g_reading_config = true; 326 g_reading_config = true;
312 break; 327 break;
313 case 'I': /* Import config at host */ 328 case 'I': /* Import config at host */