/
TextStream.h
48 lines (44 loc) · 1.06 KB
/
TextStream.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
#ifndef TextStream_h
#define TextStream_h
#include <SoftwareSerial.h>
class TextStream : public SoftwareSerial {
public:
TextStream (int pin) : SoftwareSerial (pin,20) {
begin (9600);
};
TextStream (int rxPin, int txPin) : SoftwareSerial (rxPin,txPin) {
begin (9600);
};
TextStream() : SoftwareSerial (20,20) {
useSerial = true;
}
void update (void) {
//bool debug = false;
ch = 0;
if (useSerial) {
if (Serial.available()) {
ch = Serial.read();
/*
if (debug) {
if (ch == 10) {
Serial.println ( "Ch == LF");
} else if (ch == 13) {
Serial.println ( "Ch == CR");
} else {
Serial.print ( "Ch =" );
Serial.println (ch);
}
}
*/
}
} else {
if (available()) {
ch = read();
}
}
};
char ch;
private:
bool useSerial = false;
};
#endif