From c12537f51ecd538f74efe568e9965bb79a68ddd2 Mon Sep 17 00:00:00 2001 From: erdgeist Date: Mon, 2 Apr 2018 01:36:53 +0200 Subject: Add support for new board revision --- arduino/Laserharfe/Laserharfe.ino | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'arduino') 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 @@ int led = 13; int g_reading_config = 0; int g_writing_config = 0; -ConfigSource g_config_source = source_none; //Sd2Card card; +char g_revision; enum { MODE_STANDALONE = 0, @@ -81,7 +81,8 @@ static void set_cam_register(uint8_t r, uint8_t v) { } static void setup_cam() { - digitalWrite(19, HIGH); // turn the LED on (HIGH is the voltage level) + digitalWrite(g_revision == 2 ? 16 : 19, HIGH); // Alte Harfe: port 19/A5/PB02/Pin 47 + // Neue Harfe: port 16/A2/PB09/Pin 8 set_cam_register(0x30, 0x01); set_cam_register(0x06, 0x90); set_cam_register(0x08, 0xc0); @@ -128,16 +129,20 @@ void read_config() { } void write_config() { + Serial.println("- removing config file"); SD.remove("laserhar.cfg"); + Serial.println("- ... done, open new config file"); File configfile = SD.open("laserhar.cfg", FILE_WRITE); if (!configfile) { - Serial.println("opening config failed"); + Serial.println("- opening config failed"); return; } + Serial.println("- ... done, writing globals"); char text[256]; size_t len = config_dumpglobals(text, sizeof(text)); configfile.write(text, len); + Serial.println("- ... done, writing globals"); for (int i=0; i< g_string_count; ++i) { len = config_dumpstring(i, text, sizeof(text)); configfile.write(text, len); @@ -156,6 +161,11 @@ void flashy_death() { } void setup() { + pinMode(5, INPUT_PULLUP); + delay(10); + g_revision = digitalRead(5) == LOW ? 2 : 1; + + Serial.begin(115200); pinMode(led, OUTPUT); Wire.begin(); @@ -165,8 +175,7 @@ void setup() { // Let PWM settle for a bit delay(100); setup_cam(); - Serial.begin(115200); - delay(5000); + delay(1000); read_config(); digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level) } @@ -227,6 +236,7 @@ void handle_wire() { if (p4.x!=1023) Serial.write(text, sprintf(text, "%04d:%04d ", p4.x, p4.y)); Serial.println(""); + delay(5); } /* Do a fast nibble to hex representation conversion */ @@ -278,11 +288,13 @@ void handle_command(char *command) { // Serial.write( text, sprintf(text, "- %s\n", command)); if (g_reading_config ) { - if ( !strcmp(command, "-- DONE")) { + if ( !memcmp(command, "-- DONE", 7)) { + Serial.println("- finished import"); g_reading_config = 0; return; } config_handle_line(command); + delay(10); return; } @@ -302,12 +314,15 @@ void handle_command(char *command) { g_mode = MODE_REPORTPOINTS; break; } + Serial.println(g_revision == 2 ? "revision 2" : "revision 1"); break; case 'C': /* Import a single config line from host */ config_handle_line(command+1); break; case 'E': /* Export config from host, import here */ config_reset(); + Serial.println("- export from host triggered"); + delay(100); g_reading_config = true; break; case 'I': /* Import config at host */ -- cgit v1.2.3