[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 |
|
---|
| 23 | using namespace TCLAP;
|
---|
| 24 | using namespace std;
|
---|
| 25 | using namespace flair::core;
|
---|
| 26 | using namespace flair::sensor;
|
---|
| 27 |
|
---|
| 28 | string receiverAddress;
|
---|
| 29 | int receiverPort;
|
---|
| 30 | string connection;
|
---|
| 31 | int port;
|
---|
| 32 | uint32_t period;
|
---|
| 33 | string xml_file;
|
---|
| 34 |
|
---|
[16] | 35 | void parseOptions(int argc, char **argv);
|
---|
[11] | 36 |
|
---|
[16] | 37 | int 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] | 72 | void 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 | }
|
---|