summaryrefslogtreecommitdiffhomepage
path: root/tracker-udp
diff options
context:
space:
mode:
Diffstat (limited to 'tracker-udp')
-rw-r--r--tracker-udp/CMakeLists.txt1
-rw-r--r--tracker-udp/ftnoir_ftnclientcontrols.ui208
-rw-r--r--tracker-udp/ftnoir_tracker_udp.cpp70
-rw-r--r--tracker-udp/ftnoir_tracker_udp.h60
-rw-r--r--tracker-udp/ftnoir_tracker_udp_dialog.cpp26
5 files changed, 365 insertions, 0 deletions
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UICFTNClientControls</class>
+ <widget class="QWidget" name="UICFTNClientControls">
+ <property name="windowModality">
+ <enum>Qt::NonModal</enum>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>195</width>
+ <height>224</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>UDP tracker settings</string>
+ </property>
+ <property name="windowIcon">
+ <iconset>
+ <normaloff>../facetracknoir/images/facetracknoir.png</normaloff>../facetracknoir/images/facetracknoir.png</iconset>
+ </property>
+ <property name="layoutDirection">
+ <enum>Qt::LeftToRight</enum>
+ </property>
+ <property name="autoFillBackground">
+ <bool>false</bool>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title">
+ <string/>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>Port</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QSpinBox" name="spinPortNumber">
+ <property name="minimum">
+ <number>0</number>
+ </property>
+ <property name="maximum">
+ <number>65535</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox_2">
+ <property name="title">
+ <string>Add to axis</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_3">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_7">
+ <property name="text">
+ <string>yaw</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="add_yaw">
+ <item>
+ <property name="text">
+ <string>0</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>+90</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>-90</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>+180</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>-180</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_8">
+ <property name="text">
+ <string>pitch</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_10">
+ <property name="text">
+ <string>roll</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="add_pitch">
+ <item>
+ <property name="text">
+ <string>0</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>+90</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>-90</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>+180</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>-180</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QComboBox" name="add_roll">
+ <item>
+ <property name="text">
+ <string>0</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>+90</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>-90</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>+180</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>-180</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+ <slots>
+ <slot>startEngineClicked()</slot>
+ <slot>stopEngineClicked()</slot>
+ <slot>cameraSettingsClicked()</slot>
+ </slots>
+</ui>
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 <sthalik@misaki.pl>
+
+ * 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<unsigned>(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 <QUdpSocket>
+#include <QThread>
+#include <cmath>
+#include "opentrack/plugin-api.hpp"
+#include "opentrack/options.hpp"
+using namespace options;
+
+struct settings : opts {
+ value<int> port;
+ value<int> 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();
+}
+