From aa066bdd4622d4f6824fee864f6be6806813f04d Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 30 Oct 2015 07:37:41 +0100 Subject: move to subdirectory-based build system Closes #224 --- tracker-freepie-udp/CMakeLists.txt | 1 + tracker-freepie-udp/freepie-udp-controls.ui | 285 +++++++++++++++++++++ tracker-freepie-udp/freepie-udp-res.qrc | 5 + tracker-freepie-udp/ftnoir_tracker_freepie-udp.cpp | 119 +++++++++ tracker-freepie-udp/ftnoir_tracker_freepie-udp.h | 69 +++++ .../ftnoir_tracker_freepie-udp_dialog.cpp | 30 +++ tracker-freepie-udp/glovepie.png | Bin 0 -> 3584 bytes 7 files changed, 509 insertions(+) create mode 100644 tracker-freepie-udp/CMakeLists.txt create mode 100644 tracker-freepie-udp/freepie-udp-controls.ui create mode 100644 tracker-freepie-udp/freepie-udp-res.qrc create mode 100644 tracker-freepie-udp/ftnoir_tracker_freepie-udp.cpp create mode 100644 tracker-freepie-udp/ftnoir_tracker_freepie-udp.h create mode 100644 tracker-freepie-udp/ftnoir_tracker_freepie-udp_dialog.cpp create mode 100644 tracker-freepie-udp/glovepie.png (limited to 'tracker-freepie-udp') diff --git a/tracker-freepie-udp/CMakeLists.txt b/tracker-freepie-udp/CMakeLists.txt new file mode 100644 index 00000000..34cb2fdc --- /dev/null +++ b/tracker-freepie-udp/CMakeLists.txt @@ -0,0 +1 @@ +opentrack_boilerplate(opentrack-tracker-freepie-udp) diff --git a/tracker-freepie-udp/freepie-udp-controls.ui b/tracker-freepie-udp/freepie-udp-controls.ui new file mode 100644 index 00000000..74e5a6f1 --- /dev/null +++ b/tracker-freepie-udp/freepie-udp-controls.ui @@ -0,0 +1,285 @@ + + + UI_freepie_udp_dialog + + + Qt::NonModal + + + + 0 + 0 + 227 + 372 + + + + Tracker settings + + + + ../facetracknoir/images/facetracknoir.png../facetracknoir/images/facetracknoir.png + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + + + + 0 + 0 + + + + UDP port + + + + + + + 0 + + + 65535 + + + + + + + + + + Axis order + + + + + + output yaw + + + + + + + + input yaw + + + + + input pitch + + + + + input roll + + + + + + + + + input yaw + + + + + input pitch + + + + + input roll + + + + + + + + output pitch + + + + + + + + input yaw + + + + + input pitch + + + + + input roll + + + + + + + + output roll + + + + + + + + + + Add to axis + + + + + + yaw + + + + + + + + 0 + + + + + +90 + + + + + -90 + + + + + +180 + + + + + -180 + + + + + + + + pitch + + + + + + + roll + + + + + + + + 0 + + + + + +90 + + + + + -90 + + + + + +180 + + + + + -180 + + + + + + + + + 0 + + + + + +90 + + + + + -90 + + + + + +180 + + + + + -180 + + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + startEngineClicked() + stopEngineClicked() + cameraSettingsClicked() + + diff --git a/tracker-freepie-udp/freepie-udp-res.qrc b/tracker-freepie-udp/freepie-udp-res.qrc new file mode 100644 index 00000000..3fd3edc4 --- /dev/null +++ b/tracker-freepie-udp/freepie-udp-res.qrc @@ -0,0 +1,5 @@ + + + glovepie.png + + diff --git a/tracker-freepie-udp/ftnoir_tracker_freepie-udp.cpp b/tracker-freepie-udp/ftnoir_tracker_freepie-udp.cpp new file mode 100644 index 00000000..12cf9bca --- /dev/null +++ b/tracker-freepie-udp/ftnoir_tracker_freepie-udp.cpp @@ -0,0 +1,119 @@ +#include "ftnoir_tracker_freepie-udp.h" +#include "opentrack/plugin-api.hpp" + +#include +#include + +TrackerImpl::TrackerImpl() : pose { 0,0,0, 0,0,0 }, should_quit(false) +{ +} + +TrackerImpl::~TrackerImpl() +{ + should_quit = true; + wait(); +} + +template +static const t bound(t datum, t least, t max) +{ + if (datum < least) + return least; + if (datum > max) + return max; + return datum; +} + +void TrackerImpl::run() { +#pragma pack(push, 1) + struct { + uint8_t pad1; + uint8_t flags; + float fl[12]; + } data; +#pragma pack(pop) + enum F { + flag_Raw = 1 << 0, + flag_Orient = 1 << 1, + Mask = flag_Raw | flag_Orient + }; + + (void) sock.bind(QHostAddress::Any, (int) s.port, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint); + + while (!should_quit) { + int order[] = { + bound(s.idx_x, 0, 2), + bound(s.idx_y, 0, 2), + bound(s.idx_z, 0, 2) + }; + float orient[3]; + bool filled = false; + + while (sock.hasPendingDatagrams()) + { + using t = decltype(data); + t tmp {0,0, {0,0,0, 0,0,0, 0,0,0, 0,0,0}}; + (void) sock.readDatagram(reinterpret_cast(&tmp), sizeof(data)); + + int flags = tmp.flags & F::Mask; + + switch (flags) + { + //default: + case flag_Raw: + continue; + case flag_Raw | flag_Orient: + for (int i = 0; i < 3; i++) + orient[i] = tmp.fl[i+9]; + break; + case flag_Orient: + for (int i = 0; i < 3; i++) + orient[i] = tmp.fl[i]; + break; + } + + filled = true; + data = tmp; + } + + if (filled) + { + static const int add_cbx[] = { + 0, + 90, + -90, + 180, + -180, + }; + int indices[] = { s.add_yaw, s.add_pitch, s.add_roll }; + QMutexLocker foo(&mtx); + static constexpr double r2d = 57.295781; + for (int i = 0; i < 3; i++) + { + int val = 0; + int idx = indices[order[i]]; + if (idx >= 0 && idx < (int)(sizeof(add_cbx) / sizeof(*add_cbx))) + val = add_cbx[idx]; + pose[Yaw + i] = r2d * orient[order[i]] + val; + } + } + usleep(4000); + } +} + +void TrackerImpl::start_tracker(QFrame*) +{ + start(); + sock.moveToThread(this); +} + +void TrackerImpl::data(double *data) +{ + QMutexLocker foo(&mtx); + + data[Yaw] = pose[Yaw]; + data[Pitch] = pose[Pitch]; + data[Roll] = pose[Roll]; +} + +OPENTRACK_DECLARE_TRACKER(TrackerImpl, TrackerDialog, TrackerMeta) diff --git a/tracker-freepie-udp/ftnoir_tracker_freepie-udp.h b/tracker-freepie-udp/ftnoir_tracker_freepie-udp.h new file mode 100644 index 00000000..7cff2ec9 --- /dev/null +++ b/tracker-freepie-udp/ftnoir_tracker_freepie-udp.h @@ -0,0 +1,69 @@ +/* Copyright (c) 2014 Stanislaw Halik + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ + +#include +#include +#include +#include "ui_freepie-udp-controls.h" +#include "opentrack/plugin-api.hpp" +#include "opentrack/options.hpp" +using namespace options; + +struct settings : opts { + value port, idx_x, idx_y, idx_z; + value add_yaw, add_pitch, add_roll; + settings() : + opts("freepie-udp-tracker"), + port(b, "port", 5555), + idx_x(b, "axis-index-x", 0), + idx_y(b, "axis-index-y", 1), + idx_z(b, "axis-index-z", 2), + add_yaw(b, "add-yaw-degrees", 0), + add_pitch(b, "add-pitch-degrees", 0), + add_roll(b, "add-roll-degrees", 0) + {} +}; + +class TrackerImpl : public ITracker, private QThread +{ +public: + TrackerImpl(); + ~TrackerImpl() override; + void start_tracker(QFrame *) override; + void data(double *data) override; +protected: + void run() override; +private: + double pose[6]; + QUdpSocket sock; + settings s; + QMutex mtx; + volatile bool should_quit; +}; + +class TrackerDialog : public ITrackerDialog +{ + Q_OBJECT +public: + TrackerDialog(); + void register_tracker(ITracker *) override {} + void unregister_tracker() override {} +private: + Ui::UI_freepie_udp_dialog ui; + settings s; +private slots: + void doOK(); + void doCancel(); +}; + +class TrackerMeta : public Metadata +{ +public: + QString name() { return QString("FreePIE UDP receiver"); } + QIcon icon() { return QIcon(":/glovepie.png"); } +}; + diff --git a/tracker-freepie-udp/ftnoir_tracker_freepie-udp_dialog.cpp b/tracker-freepie-udp/ftnoir_tracker_freepie-udp_dialog.cpp new file mode 100644 index 00000000..55427d35 --- /dev/null +++ b/tracker-freepie-udp/ftnoir_tracker_freepie-udp_dialog.cpp @@ -0,0 +1,30 @@ +#include "ftnoir_tracker_freepie-udp.h" +#include "opentrack/plugin-api.hpp" + +TrackerDialog::TrackerDialog() +{ + ui.setupUi(this); + + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); + connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); + + tie_setting(s.port, ui.port); + tie_setting(s.idx_x, ui.input_x); + tie_setting(s.idx_y, ui.input_y); + tie_setting(s.idx_z, ui.input_z); + + tie_setting(s.add_yaw, ui.add_yaw); + tie_setting(s.add_pitch, ui.add_pitch); + tie_setting(s.add_roll, ui.add_roll); +} + +void TrackerDialog::doOK() { + s.b->save(); + this->close(); +} + +void TrackerDialog::doCancel() { + s.b->reload(); + this->close(); +} + diff --git a/tracker-freepie-udp/glovepie.png b/tracker-freepie-udp/glovepie.png new file mode 100644 index 00000000..2156b7af Binary files /dev/null and b/tracker-freepie-udp/glovepie.png differ -- cgit v1.2.3