-
Notifications
You must be signed in to change notification settings - Fork 0
/
lpm.h
76 lines (51 loc) · 1.48 KB
/
lpm.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <serial.h>
namespace device {
class lpm {
public:
device::serial io;
lpm(const device::serial &io) : io(io) { }
static lpm open(const std::string &path) {
lpm lpm(serial::open(path));
return lpm;
}
void led(uint8_t pin, uint16_t pwm) {
std::stringstream cmd;
cmd << "pwm " << pin << "," << pwm;
io.send_data(cmd.str());
}
void setPWM(std::string cmd) {
io.send_data(cmd);
}
std::string getInfo() {
std::string info = send_and_receive("info");
return info;
}
void reset() {
send_and_receive("reset");
}
void shoot() {
send_and_receive("shoot");
}
std::string send_and_receive(const std::string &data) {
io.send_data(data);
std::stringstream response;
while (true) {
std::string data = io.recv_line(1000);
if (data == "\u0004") {
break;
}
response << data << "\n";
}
return response.str();
}
void receiveArduinoOutput() {
while(1) {
std::string data = io.recv_line(1000);
std::cout << data << std::endl;
if (data == std::string("\0004")) {
break;
}
}
}
};
}