Index

auto-plow / c7eae65

A wheelchair motor-propelled battery-powered ESP32-driven remote control snow plow.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
3805 Dec 2018 19:35ffa80fdInput based eventsjoshuas31220N

Blob @ auto-plow / src / ard1 / serial.cpp

text/plain732 bytesdownload raw
1#include "Arduino.h"
2#include "ard1.h"
3#include "serial.h"
4
5void serial(void) {
6 if (!Serial) return;
7 Serial.begin(BAUD_RATE);
8 while (!Serial)
9 ;
10}
11
12int input_callback_count = 0;
13
14callback input_callbacks = (callback) malloc( sizeof( callback ) );
15
16void 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
25void 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