-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathconfigurator.cpp
146 lines (130 loc) · 4.45 KB
/
configurator.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <vector>
#include "idf/SerialDevice.hh"
#include "idf/SerialThrustMaster.hh"
#include "idf/SerialThrustMaster2.hh"
#include "idf/UsbDevice.hh"
#include "idf/UsbDacoThc.hh"
#include "idf/UsbChProPedals.hh"
#include "idf/UsbDualShock3.hh"
#include "idf/UsbDualShock4.hh"
#include "idf/UsbExtreme3dPro.hh"
#include "idf/UsbGravis.hh"
#include "idf/UsbIndustrialProducts.hh"
#include "idf/UsbIndustrialProducts2.hh"
#include "idf/UsbIndustrialProducts3.hh"
#include "idf/UsbIndustrialProducts4.hh"
#include "idf/UsbMadCatz.hh"
#include "idf/UsbSaitek.hh"
#include "idf/UsbSaitekX52.hh"
#include "idf/UsbSaitekX56Stick.hh"
#include "idf/UsbSaitekX56Throttle.hh"
#include "idf/UsbSpaceExplorer.hh"
#include "idf/UsbSpaceMouse.hh"
#include "idf/UsbSpaceNavigator.hh"
#include "idf/UsbTeensyduino.hh"
#include "idf/UsbWingMan.hh"
#include "idf/UsbXBox.hh"
#include "idf/UsbXBoxOne.hh"
namespace configurator {
static int index = -1;
bool notConnected(idf::UsbDevice* device) {
return !device->isConnected();
}
void printIndex(const std::string& text) {
std::cout << std::setw(2) << ++index << " " << text << std::endl;
}
int getSelection() {
int selection = -1;
std::cout << std::endl;
while (selection < 0 || selection > index) {
std::cout << "Select a device to configure: ";
std::cin >> selection;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
return selection;
}
void configure(idf::InputDevice& device) {
device.open();
std::cout << std::endl << "Configuring: " << device.name << std::endl << std::endl;
device.configure();
}
void run() {
idf::UsbChProPedals chProPedals;
idf::UsbDacoThc dacoThc;
idf::UsbDualShock3 dualShock3;
idf::UsbDualShock4 dualShock4;
idf::UsbExtreme3dPro extreme3dPro;
idf::UsbGravis gravis;
idf::UsbIndustrialProducts industrialProducts;
idf::UsbIndustrialProducts2 industrialProducts2;
idf::UsbIndustrialProducts3 industrialProducts3;
idf::UsbIndustrialProducts4 industrialProducts4;
idf::UsbMadCatz madcatz;
idf::UsbSaitek saitek;
idf::UsbSaitekX52 saitekX52;
idf::UsbSaitekX56Stick saitekX56Stick;
idf::UsbSaitekX56Throttle saitekX56Throttle;
idf::UsbSpaceExplorer spaceExplorer;
idf::UsbSpaceMouse spaceMouse;
idf::UsbSpaceNavigator spaceNavigator;
idf::UsbTeensyduino teensyduino;
idf::UsbWingMan wingMan;
idf::UsbXBox xBox;
idf::UsbXBoxOne xBoxOne;
std::vector<idf::UsbDevice*> devices;
devices.push_back(&chProPedals);
devices.push_back(&dacoThc);
devices.push_back(&dualShock3);
devices.push_back(&dualShock4);
devices.push_back(&extreme3dPro);
devices.push_back(&gravis);
devices.push_back(&industrialProducts);
devices.push_back(&industrialProducts2);
devices.push_back(&industrialProducts3);
devices.push_back(&industrialProducts4);
devices.push_back(&madcatz);
devices.push_back(&saitek);
devices.push_back(&saitekX52);
devices.push_back(&saitekX56Stick);
devices.push_back(&saitekX56Throttle);
devices.push_back(&spaceExplorer);
devices.push_back(&spaceMouse);
devices.push_back(&spaceNavigator);
devices.push_back(&teensyduino);
devices.push_back(&wingMan);
devices.push_back(&xBox);
devices.push_back(&xBoxOne);
devices.erase(std::remove_if(devices.begin(), devices.end(), notConnected), devices.end());
std::cout << std::endl << "NOTE: If running as non-root, you must have udev rules in place allowing access to usb devices." << std::endl << std::endl;
printIndex("Serial Device");
for (std::vector<idf::UsbDevice*>::size_type i = 0; i < devices.size(); ++i) {
printIndex(devices[i]->name);
}
int selection = getSelection();
if (selection == 0) {
std::vector<idf::SerialDevice*> devices;
idf::SerialThrustMaster shuttleThrustMaster;
idf::SerialThrustMaster2 orionThrustMaster;
devices.push_back(&shuttleThrustMaster);
devices.push_back(&orionThrustMaster);
index = -1;
std::cout << std::endl;
for (std::vector<idf::UsbDevice*>::size_type i = 0; i < devices.size(); ++i) {
printIndex(devices[i]->name);
}
configure(*devices[getSelection()]);
}
else {
configure(*devices[selection - 1]);
}
}
}
int main(int argc, char **args) {
configurator::run();
return 0;
}