-
Notifications
You must be signed in to change notification settings - Fork 15
/
Razorboard.cpp
66 lines (57 loc) · 1.31 KB
/
Razorboard.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Razorboard.cpp - Reads data from razorboard
* Author: Dimitris Platis (based on the Smartcar project by Team Pegasus)
* License: GNU GPL v3 http://www.gnu.org/licenses/gpl-3.0.html
*/
#include "AndroidCar.h"
Razorboard::Razorboard(){
}
void Razorboard::attach(HardwareSerial *razorSerial){
_serial = razorSerial;
_serial->begin(9600);
_serial->setTimeout(50);
}
boolean Razorboard::available(){
return _serial->available();
}
String Razorboard::readLine(){
if (available()){
return readRawSerialLine();
}else{
return "error";
}
}
/* read whatever is in the buffer untill you reach the last available line and return it */
String Razorboard::readLastLine(){
if (available()){
String input = "";
input.reserve(32);
while (available()) input = readRawSerialLine();
return input;
}else{
return "error";
}
}
int Razorboard::getHeading(){
if (available()){
return getRawHeading();
}else {
return -1000;
}
}
int Razorboard::getLatestHeading(){
if (available()){
int heading = 0;
while (available()) heading = getRawHeading();
return heading;
}else{
return -1000;
}
}
String Razorboard::readRawSerialLine(){
return _serial->readStringUntil('\n');
}
int Razorboard::getRawHeading(){
String line = readRawSerialLine();
return line.substring(line.indexOf('=') + 1,line.indexOf(',')).toInt();
}