-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComSerial.cpp
More file actions
47 lines (40 loc) · 853 Bytes
/
ComSerial.cpp
File metadata and controls
47 lines (40 loc) · 853 Bytes
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
/*
http://www.ardumote.com
Copyright (c) 2012 Suat Özgür
http://opensource.org/licenses/MIT
*/
#include "ComSerial.h"
ComSerial::ComSerial() {
bAvailable = false;
nCommandBufferPos = 0;
sReturnCommand[0] = '\0';
}
void ComSerial::setup() {
}
bool ComSerial::available() {
if (bAvailable) {
return true;
}
if (Serial.available()) {
char c = Serial.read();
if (c == 13) {
sReturnCommand[nCommandBufferPos] = '\0';
bAvailable = true;
return true;
} else {
sReturnCommand[nCommandBufferPos++] = c;
}
}
if (nCommandBufferPos > 190) {
nCommandBufferPos = 0;
}
return false;
}
char* ComSerial::read() {
nCommandBufferPos = 0;
bAvailable = false;
return sReturnCommand;
}
bool ComSerial::send(char* sCommand) {
Serial.println(sCommand);
}