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

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

cosmetic changes

File size: 3.1 KB
RevLine 
[11]1// %flair:license{
[16]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[11]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
[16]35void parseOptions(int argc, char **argv);
[11]36
[16]37int main(int argc, char *argv[]) {
38 parseOptions(argc, argv);
[11]39
[16]40 DualShock3 *joystick;
41 FrameworkManager *manager;
[11]42
[16]43 manager = new FrameworkManager("dualshock3");
44 manager->SetupConnection("127.0.0.1", port);
45 manager->SetupUserInterface(xml_file);
[11]46
[16]47 if (connection == "usb") {
[137]48 joystick = new DualShock3("dualshock3", receiverAddress,
[16]49 receiverPort, DualShock3::Usb, period, 6);
50 } else {
[137]51 joystick = new DualShock3("dualshock3", receiverAddress,
[16]52 receiverPort, DualShock3::Bluetooth, period, 6);
53 }
[11]54
[16]55 joystick->DrawUserInterface();
[11]56
[16]57 if (!manager->ErrorOccured()) {
58 joystick->Start();
59 joystick->Join();
60 }
[11]61
[16]62 delete manager;
[11]63}
64
[16]65void parseOptions(int argc, char **argv) {
66 try {
67 CmdLine cmd("Command description message", ' ', "0.1");
[11]68
[16]69 ValueArg<string> addressArg("a", "address",
70 "data receiver address (ex: uav)", true,
71 "127.0.0.1:20000", "string");
72 cmd.add(addressArg);
[11]73
[16]74 ValueArg<string> connectionArg("c", "connection",
75 "connection type (usb or bluetooth)", false,
76 "bluetooth", "string");
77 cmd.add(connectionArg);
[11]78
[16]79 ValueArg<int> portArg("p", "port",
80 "local port used to connect to the ground station",
81 false, 9000, "int");
82 cmd.add(portArg);
[11]83
[16]84 ValueArg<int> periodArg("t", "period", "sending data period", false, 10,
85 "int");
86 cmd.add(periodArg);
[11]87
[16]88 ValueArg<string> xmlArg("x", "xml", "xml file", true, "./settings.xml",
89 "string");
90 cmd.add(xmlArg);
[11]91
[16]92 cmd.parse(argc, argv);
[11]93
[16]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();
[11]104
[16]105 } catch (ArgException &e) { // catch any exceptions
106 cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
107 }
[11]108}
Note: See TracBrowser for help on using the repository browser.