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

Last change on this file since 14 was 11, checked in by Sanahuja Guillaume, 9 years ago

ds3

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