1 | #include "Arduino.h" |
2 | #include "ard1.h" |
3 | #include "serial.h" |
4 |
|
5 | void serial(void) { |
6 | if (!Serial) return; |
7 | Serial.begin(BAUD_RATE); |
8 | while (!Serial) |
9 | ; |
10 | } |
11 |
|
12 | int input_callback_count = 0; |
13 |
|
14 | callback input_callbacks = (callback) malloc( sizeof( callback ) ); |
15 |
|
16 | void input(callback callback_function) { |
17 | input_callback_count ++; |
18 | callback input_callbacks_tmp = (callback) realloc(&input_callbacks, input_callback_count * sizeof( callback )); |
19 | if (!input_callbacks_tmp) { |
20 | exit(1); |
21 | } |
22 | input_callbacks = input_callbacks_tmp; |
23 | } |
24 |
|
25 | void input_update(void) { |
26 | if (Serial.available() > 0) { |
27 | String line = Serial.readStringUntil(';'); |
28 | for (int x = 0; x < input_callback_count; x++) { |
29 | input_callbacks[x](line); |
30 | } |
31 | } |
32 | } |
33 |
|