diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-10-30 07:37:41 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-10-30 08:39:32 +0100 |
commit | aa066bdd4622d4f6824fee864f6be6806813f04d (patch) | |
tree | 3df328b8b364cba2373a85827191b259bd78d546 /tracker-freepie-udp | |
parent | d6a54431d178632a2bf466c9904f74abd143afe6 (diff) |
move to subdirectory-based build system
Closes #224
Diffstat (limited to 'tracker-freepie-udp')
-rw-r--r-- | tracker-freepie-udp/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tracker-freepie-udp/freepie-udp-controls.ui | 285 | ||||
-rw-r--r-- | tracker-freepie-udp/freepie-udp-res.qrc | 5 | ||||
-rw-r--r-- | tracker-freepie-udp/ftnoir_tracker_freepie-udp.cpp | 119 | ||||
-rw-r--r-- | tracker-freepie-udp/ftnoir_tracker_freepie-udp.h | 69 | ||||
-rw-r--r-- | tracker-freepie-udp/ftnoir_tracker_freepie-udp_dialog.cpp | 30 | ||||
-rw-r--r-- | tracker-freepie-udp/glovepie.png | bin | 0 -> 3584 bytes |
7 files changed, 509 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>UI_freepie_udp_dialog</class> + <widget class="QWidget" name="UI_freepie_udp_dialog"> + <property name="windowModality"> + <enum>Qt::NonModal</enum> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>227</width> + <height>372</height> + </rect> + </property> + <property name="windowTitle"> + <string>Tracker settings</string> + </property> + <property name="windowIcon"> + <iconset> + <normaloff>../facetracknoir/images/facetracknoir.png</normaloff>../facetracknoir/images/facetracknoir.png</iconset> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QFrame" name="frame"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Raised</enum> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="label_5"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>UDP port</string> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="port"> + <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"> + <property name="title"> + <string>Axis order</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0" rowspan="2"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>output yaw</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QComboBox" name="input_x"> + <item> + <property name="text"> + <string>input yaw</string> + </property> + </item> + <item> + <property name="text"> + <string>input pitch</string> + </property> + </item> + <item> + <property name="text"> + <string>input roll</string> + </property> + </item> + </widget> + </item> + <item row="1" column="1" rowspan="2"> + <widget class="QComboBox" name="input_y"> + <item> + <property name="text"> + <string>input yaw</string> + </property> + </item> + <item> + <property name="text"> + <string>input pitch</string> + </property> + </item> + <item> + <property name="text"> + <string>input roll</string> + </property> + </item> + </widget> + </item> + <item row="2" column="0" rowspan="2"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>output pitch</string> + </property> + </widget> + </item> + <item row="3" column="1" rowspan="2"> + <widget class="QComboBox" name="input_z"> + <item> + <property name="text"> + <string>input yaw</string> + </property> + </item> + <item> + <property name="text"> + <string>input pitch</string> + </property> + </item> + <item> + <property name="text"> + <string>input roll</string> + </property> + </item> + </widget> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>output roll</string> + </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_2"> + <item row="0" column="0"> + <widget class="QLabel" name="label_4"> + <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_6"> + <property name="text"> + <string>pitch</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_9"> + <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> + <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-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 @@ +<RCC> + <qresource prefix="/"> + <file>glovepie.png</file> + </qresource> +</RCC> 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 <cinttypes> +#include <algorithm> + +TrackerImpl::TrackerImpl() : pose { 0,0,0, 0,0,0 }, should_quit(false) +{ +} + +TrackerImpl::~TrackerImpl() +{ + should_quit = true; + wait(); +} + +template<typename t> +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<int>(s.idx_x, 0, 2), + bound<int>(s.idx_y, 0, 2), + bound<int>(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<char*>(&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 <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 <cinttypes> +#include <QUdpSocket> +#include <QThread> +#include "ui_freepie-udp-controls.h" +#include "opentrack/plugin-api.hpp" +#include "opentrack/options.hpp" +using namespace options; + +struct settings : opts { + value<int> port, idx_x, idx_y, idx_z; + value<int> 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 Binary files differnew file mode 100644 index 00000000..2156b7af --- /dev/null +++ b/tracker-freepie-udp/glovepie.png |