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-udp/CMakeLists.txt | 1 + tracker-udp/ftnoir_ftnclientcontrols.ui | 208 ++++++++++++++++++++++++++++++ tracker-udp/ftnoir_tracker_udp.cpp | 70 ++++++++++ tracker-udp/ftnoir_tracker_udp.h | 60 +++++++++ tracker-udp/ftnoir_tracker_udp_dialog.cpp | 26 ++++ 5 files changed, 365 insertions(+) create mode 100644 tracker-udp/CMakeLists.txt create mode 100644 tracker-udp/ftnoir_ftnclientcontrols.ui create mode 100644 tracker-udp/ftnoir_tracker_udp.cpp create mode 100644 tracker-udp/ftnoir_tracker_udp.h create mode 100644 tracker-udp/ftnoir_tracker_udp_dialog.cpp (limited to 'tracker-udp') diff --git a/tracker-udp/CMakeLists.txt b/tracker-udp/CMakeLists.txt new file mode 100644 index 00000000..51e96773 --- /dev/null +++ b/tracker-udp/CMakeLists.txt @@ -0,0 +1 @@ +opentrack_boilerplate(opentrack-tracker-udp) diff --git a/tracker-udp/ftnoir_ftnclientcontrols.ui b/tracker-udp/ftnoir_ftnclientcontrols.ui new file mode 100644 index 00000000..cb9362ca --- /dev/null +++ b/tracker-udp/ftnoir_ftnclientcontrols.ui @@ -0,0 +1,208 @@ + + + UICFTNClientControls + + + Qt::NonModal + + + + 0 + 0 + 195 + 224 + + + + UDP tracker settings + + + + ../facetracknoir/images/facetracknoir.png../facetracknoir/images/facetracknoir.png + + + Qt::LeftToRight + + + false + + + + + + + 0 + 0 + + + + + + + + + + Port + + + + + + + 0 + + + 65535 + + + + + + + + + + Add to axis + + + + + + yaw + + + + + + + + 0 + + + + + +90 + + + + + -90 + + + + + +180 + + + + + -180 + + + + + + + + pitch + + + + + + + roll + + + + + + + + 0 + + + + + +90 + + + + + -90 + + + + + +180 + + + + + -180 + + + + + + + + + 0 + + + + + +90 + + + + + -90 + + + + + +180 + + + + + -180 + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + startEngineClicked() + stopEngineClicked() + cameraSettingsClicked() + + diff --git a/tracker-udp/ftnoir_tracker_udp.cpp b/tracker-udp/ftnoir_tracker_udp.cpp new file mode 100644 index 00000000..1610f917 --- /dev/null +++ b/tracker-udp/ftnoir_tracker_udp.cpp @@ -0,0 +1,70 @@ +/* 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 "ftnoir_tracker_udp.h" +#include "opentrack/plugin-api.hpp" + +FTNoIR_Tracker::FTNoIR_Tracker() : last_recv_pose { 0,0,0, 0,0,0 }, should_quit(false) {} + +FTNoIR_Tracker::~FTNoIR_Tracker() +{ + should_quit = true; + wait(); +} + +void FTNoIR_Tracker::run() { + QByteArray datagram; + datagram.resize(sizeof(last_recv_pose)); + (void) sock.bind(QHostAddress::Any, (int) s.port, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint); + for (;;) { + if (should_quit) + break; + { + QMutexLocker foo(&mutex); + while (sock.hasPendingDatagrams()) { + sock.readDatagram((char * ) last_recv_pose, sizeof(double[6])); + } + } + msleep(1); + } +} + +void FTNoIR_Tracker::start_tracker(QFrame*) +{ + start(); + sock.moveToThread(this); +} + +void FTNoIR_Tracker::data(double *data) +{ + QMutexLocker foo(&mutex); + for (int i = 0; i < 6; i++) + data[i] = last_recv_pose[i]; + + int values[] = { + 0, + 90, + -90, + 180, + -180, + }; + int indices[] = { + s.add_yaw, + s.add_pitch, + s.add_roll, + }; + + for (int i = 0; i < 3; i++) + { + int k = std::min(sizeof(values)/sizeof(values[0]), std::max(0, indices[i])); + data[Yaw + i] += values[k]; + } +} + + +OPENTRACK_DECLARE_TRACKER(FTNoIR_Tracker, TrackerControls, FTNoIR_TrackerDll) diff --git a/tracker-udp/ftnoir_tracker_udp.h b/tracker-udp/ftnoir_tracker_udp.h new file mode 100644 index 00000000..6de5b295 --- /dev/null +++ b/tracker-udp/ftnoir_tracker_udp.h @@ -0,0 +1,60 @@ +#pragma once +#include "ui_ftnoir_ftnclientcontrols.h" +#include +#include +#include +#include "opentrack/plugin-api.hpp" +#include "opentrack/options.hpp" +using namespace options; + +struct settings : opts { + value port; + value add_yaw, add_pitch, add_roll; + settings() : + opts("udp-tracker"), + port(b, "port", 4242), + add_yaw(b, "add-yaw", 0), + add_pitch(b, "add-pitch", 0), + add_roll(b, "add-roll", 0) + {} +}; + +class FTNoIR_Tracker : public ITracker, protected QThread +{ +public: + FTNoIR_Tracker(); + ~FTNoIR_Tracker() override; + void start_tracker(QFrame *) override; + void data(double *data) override; +protected: + void run() override; +private: + QUdpSocket sock; + double last_recv_pose[6]; + QMutex mutex; + settings s; + volatile bool should_quit; +}; + +class TrackerControls: public ITrackerDialog +{ + Q_OBJECT +public: + TrackerControls(); + void register_tracker(ITracker *) override {} + void unregister_tracker() override {} +private: + Ui::UICFTNClientControls ui; + settings s; +private slots: + void doOK(); + void doCancel(); +}; + +class FTNoIR_TrackerDll : public Metadata +{ +public: + QString name() { return QString("UDP sender"); } + QIcon icon() { return QIcon(":/images/facetracknoir.png"); } +}; + diff --git a/tracker-udp/ftnoir_tracker_udp_dialog.cpp b/tracker-udp/ftnoir_tracker_udp_dialog.cpp new file mode 100644 index 00000000..5e7d5437 --- /dev/null +++ b/tracker-udp/ftnoir_tracker_udp_dialog.cpp @@ -0,0 +1,26 @@ +#include "ftnoir_tracker_udp.h" +#include "opentrack/plugin-api.hpp" + +TrackerControls::TrackerControls() +{ + ui.setupUi( this ); + + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); + connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); + + tie_setting(s.port, ui.spinPortNumber); + 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 TrackerControls::doOK() { + s.b->save(); + this->close(); +} + +void TrackerControls::doCancel() { + s.b->reload(); + this->close(); +} + -- cgit v1.2.3