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

Last change on this file since 290 was 137, checked in by Sanahuja Guillaume, 6 years ago

singleton manager

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