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

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

change default usb method for ds3, now input event, no need to be root

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