-
Notifications
You must be signed in to change notification settings - Fork 5
/
SerialBridge.h
51 lines (43 loc) · 1.34 KB
/
SerialBridge.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
SerialBridge.h - mcu <=> mpu serial bridge
Created by Luca Paolini, April 3, 2019.
*/
#ifndef SerialBridge_h
#define SerialBridge_h
#define BLINK_RATE_MS 500
#define BLINK_DURATION_MS 100
#include <Arduino.h>
class SerialBridge {
private:
long linkSpeed;
int statusLed;
char enableChar;
char disableChar;
unsigned long enableGraceMillis;
void (*enableHandler)(HardwareSerial serial, char enableChar, boolean justEnabled);
void (*disableHandler)(HardwareSerial serial, char disableChar, boolean justDisabled);
void (*readHandler)(HardwareSerial serial, char readChar);
boolean enabled = false;
unsigned long lastEnabled;
int ledState = LOW;
unsigned long lastBlink = 0;
void start();
void stop();
void resetBlink();
void blink();
void read();
public:
SerialBridge(
HardwareSerial &serial, long linkSpeed, int statusLed,
char enableChar, char disableChar, unsigned long enableGraceMillis,
void (*enableHandler)(HardwareSerial serial, char enableChar, boolean justEnabled),
void (*disableHandler)(HardwareSerial serial, char disableChar, boolean justEnabled),
void (*readHandler)(HardwareSerial serial, char readChar)
);
HardwareSerial &serial;
boolean isEnabled();
void begin();
void end();
void loop();
};
#endif