diff options
author | erdgeist <erdgeist@bauklotz.fritz.box> | 2016-08-13 00:02:23 +0200 |
---|---|---|
committer | erdgeist <erdgeist@bauklotz.fritz.box> | 2016-08-13 00:02:23 +0200 |
commit | 2b760eea998034ae06b2f285273a343d2a5de0bc (patch) | |
tree | 96202eae178329e80a2d3677615fc897f97f8cdc | |
parent | bd11e3abfb9a75a89cd7a9b48090d6f32b086896 (diff) |
Re-enable engine calls, add config file parser
-rw-r--r-- | arduino/Laserharfe/Laserharfe.ino | 42 |
1 files 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 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "MIDIUSB.h" | 9 | #include "MIDIUSB.h" |
10 | #include <SD.h> | ||
10 | #include <Wire.h> | 11 | #include <Wire.h> |
11 | 12 | ||
12 | #include "main.h" | 13 | #include "main.h" |
@@ -92,6 +93,42 @@ static void setup_cam() { | |||
92 | set_cam_register(0x30, 0x08); | 93 | set_cam_register(0x30, 0x08); |
93 | } | 94 | } |
94 | 95 | ||
96 | void read_config() { | ||
97 | config_reset(); | ||
98 | if (!SD.begin(4)) { | ||
99 | Serial.println("initialization failed!"); | ||
100 | return; | ||
101 | } | ||
102 | |||
103 | File configfile = SD.open("laserhar.cfg", FILE_READ); | ||
104 | if (!configfile) { | ||
105 | Serial.println("opening config failed"); | ||
106 | return; | ||
107 | } | ||
108 | |||
109 | char command[256]; | ||
110 | int command_len; | ||
111 | int skip_command; | ||
112 | |||
113 | while (configfile.available()) { | ||
114 | char c = command[command_len++] = configfile.read(); | ||
115 | if (c=='\n') { | ||
116 | if (!skip_command) { | ||
117 | command[command_len] = 0; | ||
118 | config_handle_line(command); | ||
119 | } | ||
120 | skip_command = 0; | ||
121 | command_len = 0; | ||
122 | } | ||
123 | if (command_len==sizeof(command)) { | ||
124 | // If we end up at end of buffer, ignore everying to next \n | ||
125 | skip_command = 1; | ||
126 | command_len = 0; | ||
127 | } | ||
128 | } | ||
129 | configfile.close(); | ||
130 | } | ||
131 | |||
95 | void setup() { | 132 | void setup() { |
96 | pinMode(led, OUTPUT); | 133 | pinMode(led, OUTPUT); |
97 | 134 | ||
@@ -104,6 +141,7 @@ void setup() { | |||
104 | setup_cam(); | 141 | setup_cam(); |
105 | 142 | ||
106 | Serial.begin(115200); | 143 | Serial.begin(115200); |
144 | read_config(); | ||
107 | digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level) | 145 | digitalWrite(led, LOW); // turn the LED on (HIGH is the voltage level) |
108 | } | 146 | } |
109 | 147 | ||
@@ -142,7 +180,6 @@ void handle_wire() { | |||
142 | 180 | ||
143 | uint32_t now = millis(); | 181 | uint32_t now = millis(); |
144 | if (g_mode==MODE_STANDALONE || g_mode==MODE_REPORTPOINTS_PLAY) { | 182 | if (g_mode==MODE_STANDALONE || g_mode==MODE_REPORTPOINTS_PLAY) { |
145 | /* | ||
146 | if (p1.x!=1023) | 183 | if (p1.x!=1023) |
147 | engine_handle_point(&p1, now); | 184 | engine_handle_point(&p1, now); |
148 | if (p2.x!=1023) | 185 | if (p2.x!=1023) |
@@ -151,7 +188,6 @@ void handle_wire() { | |||
151 | engine_handle_point(&p3, now); | 188 | engine_handle_point(&p3, now); |
152 | if (p4.x!=1023) | 189 | if (p4.x!=1023) |
153 | engine_handle_point(&p4, now); | 190 | engine_handle_point(&p4, now); |
154 | */ | ||
155 | } | 191 | } |
156 | 192 | ||
157 | if (g_mode==MODE_STANDALONE) | 193 | if (g_mode==MODE_STANDALONE) |
@@ -286,7 +322,7 @@ void loop() { | |||
286 | delay(1500); | 322 | delay(1500); |
287 | */ | 323 | */ |
288 | 324 | ||
289 | //engine_checksilence(millis()); | 325 | engine_checksilence(millis()); |
290 | digitalWrite(led, ++led_state & 1 ? HIGH : LOW); // turn the LED on (HIGH is the voltage level) | 326 | digitalWrite(led, ++led_state & 1 ? HIGH : LOW); // turn the LED on (HIGH is the voltage level) |
291 | } | 327 | } |
292 | 328 | ||