From 2b760eea998034ae06b2f285273a343d2a5de0bc Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sat, 13 Aug 2016 00:02:23 +0200 Subject: Re-enable engine calls, add config file parser --- arduino/Laserharfe/Laserharfe.ino | 42 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/arduino/Laserharfe/Laserharfe.ino b/arduino/Laserharfe/Laserharfe.ino index d8a7c6f..a0e8d07 100644 --- a/arduino/Laserharfe/Laserharfe.ino +++ b/arduino/Laserharfe/Laserharfe.ino @@ -7,6 +7,7 @@ */ #include "MIDIUSB.h" +#include #include #include "main.h" @@ -92,6 +93,42 @@ static void setup_cam() { set_cam_register(0x30, 0x08); } +void read_config() { + config_reset(); + if (!SD.begin(4)) { + Serial.println("initialization failed!"); + return; + } + + File configfile = SD.open("laserhar.cfg", FILE_READ); + if (!configfile) { + Serial.println("opening config failed"); + return; + } + + char command[256]; + int command_len; + int skip_command; + + while (configfile.available()) { + char c = command[command_len++] = configfile.read(); + if (c=='\n') { + if (!skip_command) { + command[command_len] = 0; + config_handle_line(command); + } + skip_command = 0; + command_len = 0; + } + if (command_len==sizeof(command)) { + // If we end up at end of buffer, ignore everying to next \n + skip_command = 1; + command_len = 0; + } + } + configfile.close(); +} + void setup() { pinMode(led, OUTPUT); @@ -104,6 +141,7 @@ void setup() { setup_cam(); Serial.begin(115200); + read_config(); digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level) } @@ -142,7 +180,6 @@ void handle_wire() { uint32_t now = millis(); if (g_mode==MODE_STANDALONE || g_mode==MODE_REPORTPOINTS_PLAY) { -/* if (p1.x!=1023) engine_handle_point(&p1, now); if (p2.x!=1023) @@ -151,7 +188,6 @@ void handle_wire() { engine_handle_point(&p3, now); if (p4.x!=1023) engine_handle_point(&p4, now); -*/ } if (g_mode==MODE_STANDALONE) @@ -286,7 +322,7 @@ void loop() { delay(1500); */ - //engine_checksilence(millis()); + engine_checksilence(millis()); digitalWrite(led, ++led_state & 1 ? HIGH : LOW); // turn the LED on (HIGH is the voltage level) } -- cgit v1.2.3