1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | // created: 2011/10/20
|
---|
6 | // filename: main.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 6599
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: main dual shock 3
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 |
|
---|
18 | #include "FrameworkManager.h"
|
---|
19 | #include "DualShock3.h"
|
---|
20 | #include <stdio.h>
|
---|
21 | #include <tclap/CmdLine.h>
|
---|
22 |
|
---|
23 | using namespace TCLAP;
|
---|
24 | using namespace std;
|
---|
25 | using namespace flair::core;
|
---|
26 | using namespace flair::sensor;
|
---|
27 |
|
---|
28 | string receiverAddress;
|
---|
29 | int receiverPort;
|
---|
30 | string connection;
|
---|
31 | int port;
|
---|
32 | uint32_t period;
|
---|
33 | string xml_file;
|
---|
34 |
|
---|
35 | void parseOptions(int argc, char **argv);
|
---|
36 |
|
---|
37 | int main(int argc, char *argv[]) {
|
---|
38 | parseOptions(argc, argv);
|
---|
39 |
|
---|
40 | DualShock3 *joystick;
|
---|
41 | FrameworkManager *manager;
|
---|
42 |
|
---|
43 | manager = new FrameworkManager("dualshock3");
|
---|
44 | manager->SetupConnection("127.0.0.1", port);
|
---|
45 | manager->SetupUserInterface(xml_file);
|
---|
46 |
|
---|
47 | if (connection == "usb") {
|
---|
48 | joystick = new DualShock3("dualshock3", receiverAddress,
|
---|
49 | receiverPort, DualShock3::UsbEvent, period, 6);
|
---|
50 | } else if (connection == "usb_hidraw") {
|
---|
51 | joystick = new DualShock3("dualshock3", receiverAddress,
|
---|
52 | receiverPort, DualShock3::UsbHidRaw, period, 6);
|
---|
53 | } else if (connection == "bluetooth") {
|
---|
54 | joystick = new DualShock3("dualshock3", receiverAddress,
|
---|
55 | receiverPort, DualShock3::Bluetooth, period, 6);
|
---|
56 | } else {
|
---|
57 | manager->Err("unknown connection type\n");
|
---|
58 | delete manager;
|
---|
59 | return -1;
|
---|
60 | }
|
---|
61 |
|
---|
62 | joystick->DrawUserInterface();
|
---|
63 |
|
---|
64 | if (!manager->ErrorOccured()) {
|
---|
65 | joystick->Start();
|
---|
66 | joystick->Join();
|
---|
67 | }
|
---|
68 |
|
---|
69 | delete manager;
|
---|
70 | }
|
---|
71 |
|
---|
72 | void parseOptions(int argc, char **argv) {
|
---|
73 | try {
|
---|
74 | CmdLine cmd("Command description message", ' ', "0.1");
|
---|
75 |
|
---|
76 | ValueArg<string> addressArg("a", "address",
|
---|
77 | "data receiver address (ex: uav)", true,
|
---|
78 | "127.0.0.1:20000", "string");
|
---|
79 | cmd.add(addressArg);
|
---|
80 |
|
---|
81 | ValueArg<string> connectionArg("c", "connection",
|
---|
82 | "connection type (usb, usb_hidraw or bluetooth)", false,
|
---|
83 | "bluetooth", "string");
|
---|
84 | cmd.add(connectionArg);
|
---|
85 |
|
---|
86 | ValueArg<int> portArg("p", "port",
|
---|
87 | "local port used to connect to the ground station",
|
---|
88 | false, 9000, "int");
|
---|
89 | cmd.add(portArg);
|
---|
90 |
|
---|
91 | ValueArg<int> periodArg("t", "period", "sending data period", false, 10,
|
---|
92 | "int");
|
---|
93 | cmd.add(periodArg);
|
---|
94 |
|
---|
95 | ValueArg<string> xmlArg("x", "xml", "xml file", true, "./settings.xml",
|
---|
96 | "string");
|
---|
97 | cmd.add(xmlArg);
|
---|
98 |
|
---|
99 | cmd.parse(argc, argv);
|
---|
100 |
|
---|
101 | // Get the value parsed by each arg.
|
---|
102 | string receiverAddressWithPort = addressArg.getValue();
|
---|
103 | int semiColonPosition = receiverAddressWithPort.find(":");
|
---|
104 | receiverAddress = receiverAddressWithPort.substr(0, semiColonPosition);
|
---|
105 | receiverPort =
|
---|
106 | atoi(receiverAddressWithPort.substr(semiColonPosition + 1).c_str());
|
---|
107 | connection = connectionArg.getValue();
|
---|
108 | port = portArg.getValue();
|
---|
109 | period = periodArg.getValue();
|
---|
110 | xml_file = xmlArg.getValue();
|
---|
111 |
|
---|
112 | } catch (ArgException &e) { // catch any exceptions
|
---|
113 | cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
|
---|
114 | }
|
---|
115 | }
|
---|