forked from zvxryb/Linux-Virtual-Joystick
-
Notifications
You must be signed in to change notification settings - Fork 2
/
console.cpp
59 lines (44 loc) · 1.06 KB
/
console.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
#include "device.h"
#include "vjoy.h"
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
//there's no point in having a real parser here
void console() {
const char* commandIndicator = " # ";
char line[2048];
cout << "commands: pause, resume, kill" << endl;
while (true) {
cout << commandIndicator;
cin.getline(line, 2048);
char* cmd = strtok(line, " ");
if (!cmd) continue;
if (strcmp(cmd, "exit") == 0) {
device::dev->kill();
break;
}
else if (strcmp(cmd, "pause") == 0) {
if (device::dev->getState() == device::STALLED) {
cout << "already paused" << endl;
continue;
}
cout << "pausing device" << endl;
device::dev->pause();
}
else if (strcmp(cmd, "resume") == 0) {
if (device::dev->getState() == device::LIVE) {
cout << "already running" << endl;
continue;
}
cout << "resuming device" << endl;
device::dev->resume();
}
else if (strcmp(cmd, "kill") == 0){
device::dev->kill();
cout << "killed" << endl;
return;
}
else cout << "unknown command" << endl;
}
}