-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriver.cpp
More file actions
56 lines (44 loc) · 1.33 KB
/
Driver.cpp
File metadata and controls
56 lines (44 loc) · 1.33 KB
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
// "serial/serial.h" has to be above "InputManager.h" and <ncurses.h> because
// <ncurses.h> has a macro named timeout.
#include "serial/serial.h"
#include "InputManager.h"
#include <ncurses.h>
#include <string>
// ./ControlServo <serialPort>
int main (int argc, char *argv [])
{
InputManager inputManager;
if (argc < 2) {
inputManager.PrintToScreen("Usage: ./ControlServo <serialPort> [baudRate]" "\n");
return 1;
}
std::string const serialPort = argv [1];
unsigned const serialBaudRate = (argc >= 3) ? std::stoi (argv [2]) : 9600;
auto const timeout = serial::Timeout::simpleTimeout(1000);
serial::Serial arduino (serialPort, serialBaudRate, timeout);
if (!arduino.isOpen()) {
inputManager.PrintToScreen("Could not open serial port." "\n");
return 2;
}
inputManager.PrintToScreen(
"Hello! "
"Use the left and right arrow keys to control the servo motor." "\n"
);
while(true)
{
auto key = inputManager.GetKey();
if (key == KEY_LEFT)
{
arduino.write("L");
}
else if (key == KEY_RIGHT)
{
arduino.write("R");
}
else if (key == 'q' || key == 'Q')
{
inputManager.PrintToScreen("Quitting, good bye!" "\n");
break;
}
}
}