source: flair-src/trunk/tools/Controller/DualShock3/src/main.cpp@ 441

Last change on this file since 441 was 433, checked in by Sanahuja Guillaume, 3 years ago

cosmetic changes

File size: 3.1 KB
Line 
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
23using namespace TCLAP;
24using namespace std;
25using namespace flair::core;
26using namespace flair::sensor;
27
28string receiverAddress;
29int receiverPort;
30string connection;
31int port;
32uint32_t period;
33string xml_file;
34
35void parseOptions(int argc, char **argv);
36
37int 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::Usb, period, 6);
50 } else {
51 joystick = new DualShock3("dualshock3", receiverAddress,
52 receiverPort, DualShock3::Bluetooth, period, 6);
53 }
54
55 joystick->DrawUserInterface();
56
57 if (!manager->ErrorOccured()) {
58 joystick->Start();
59 joystick->Join();
60 }
61
62 delete manager;
63}
64
65void parseOptions(int argc, char **argv) {
66 try {
67 CmdLine cmd("Command description message", ' ', "0.1");
68
69 ValueArg<string> addressArg("a", "address",
70 "data receiver address (ex: uav)", true,
71 "127.0.0.1:20000", "string");
72 cmd.add(addressArg);
73
74 ValueArg<string> connectionArg("c", "connection",
75 "connection type (usb or bluetooth)", false,
76 "bluetooth", "string");
77 cmd.add(connectionArg);
78
79 ValueArg<int> portArg("p", "port",
80 "local port used to connect to the ground station",
81 false, 9000, "int");
82 cmd.add(portArg);
83
84 ValueArg<int> periodArg("t", "period", "sending data period", false, 10,
85 "int");
86 cmd.add(periodArg);
87
88 ValueArg<string> xmlArg("x", "xml", "xml file", true, "./settings.xml",
89 "string");
90 cmd.add(xmlArg);
91
92 cmd.parse(argc, argv);
93
94 // Get the value parsed by each arg.
95 string receiverAddressWithPort = addressArg.getValue();
96 int semiColonPosition = receiverAddressWithPort.find(":");
97 receiverAddress = receiverAddressWithPort.substr(0, semiColonPosition);
98 receiverPort =
99 atoi(receiverAddressWithPort.substr(semiColonPosition + 1).c_str());
100 connection = connectionArg.getValue();
101 port = portArg.getValue();
102 period = periodArg.getValue();
103 xml_file = xmlArg.getValue();
104
105 } catch (ArgException &e) { // catch any exceptions
106 cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
107 }
108}
Note: See TracBrowser for help on using the repository browser.