diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-11-21 11:09:37 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-11-21 11:09:37 +0100 |
commit | da9c3080111b0cd31b48696c3c67ac46e4843ee8 (patch) | |
tree | 8cbc3146bffa1b3ea76c388bc377b010663a863b | |
parent | daa0cc1348c40d7f654621f6a82b01934129a79f (diff) |
tracker/qt-gamepad: add stub
-rw-r--r-- | cmake/opentrack-qt.cmake | 2 | ||||
-rw-r--r-- | tracker-qt-gamepad/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tracker-qt-gamepad/test.cpp | 99 | ||||
-rw-r--r-- | tracker-qt-gamepad/test.h | 45 | ||||
-rw-r--r-- | tracker-qt-gamepad/test.ui | 59 | ||||
-rw-r--r-- | tracker-qt-gamepad/test_dialog.cpp | 3 |
6 files changed, 210 insertions, 1 deletions
diff --git a/cmake/opentrack-qt.cmake b/cmake/opentrack-qt.cmake index bb492eda..c6ab2673 100644 --- a/cmake/opentrack-qt.cmake +++ b/cmake/opentrack-qt.cmake @@ -1,5 +1,5 @@ find_package(Qt5 REQUIRED COMPONENTS Core Network Widgets Gui QUIET) -find_package(Qt5 COMPONENTS SerialPort QUIET) +find_package(Qt5 COMPONENTS SerialPort Gamepad QUIET) include_directories(SYSTEM ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS}) add_definitions(${Qt5Core_DEFINITIONS} ${Qt5Gui_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ${Qt5Network_DEFINITIONS}) set(MY_QT_LIBS ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5Network_LIBRARIES}) diff --git a/tracker-qt-gamepad/CMakeLists.txt b/tracker-qt-gamepad/CMakeLists.txt new file mode 100644 index 00000000..c892c5c6 --- /dev/null +++ b/tracker-qt-gamepad/CMakeLists.txt @@ -0,0 +1,3 @@ +if(FALSE AND Qt5Gamepad_FOUND) + opentrack_boilerplate(opentrack-tracker-qt-gamepad) +endif() diff --git a/tracker-qt-gamepad/test.cpp b/tracker-qt-gamepad/test.cpp new file mode 100644 index 00000000..4f2c8daa --- /dev/null +++ b/tracker-qt-gamepad/test.cpp @@ -0,0 +1,99 @@ +/* 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 "test.h" +#include "api/plugin-api.hpp" +#include <cmath> + +#include <QDebug> + +const double gamepad_tracker::incr[6] = +{ + 50, 40, 80, + 70, 5, 3 +}; + +gamepad_tracker::gamepad_tracker() : + last_x { 0, 0, 0, 0, 0, 0 } +{ +} + +gamepad_tracker::~gamepad_tracker() +{ +} + +void gamepad_tracker::start_tracker(QFrame*) +{ + t.start(); +} + +#ifdef EMIT_NAN +# include <cstdlib> +#endif + +void gamepad_tracker::data(double *data) +{ + using std::fmod; + using std::sin; + using std::fabs; + using std::copysign; + + const double dt = t.elapsed_seconds(); + t.start(); + +#ifdef EMIT_NAN + if ((rand()%4) == 0) + { + for (int i = 0; i < 6; i++) + data[i] = 0./0.; + } + else +#endif + for (int i = 0; i < 6; i++) + { + double x = fmod(last_x[i] + incr[i] * d2r * dt, 2 * M_PI); + last_x[i] = x; + + if (i >= 3) + { +#ifdef DISCONTINUITY + if (x > pi + pi/2) + x -= M_PI; + else if (x > pi/2 && x < pi) + x += M_PI; +#endif + + data[i] = sin(x) * 180; + } + else + { + data[i] = sin(x) * 100; + } + } +} + +gamepad_dialog::gamepad_dialog() +{ + ui.setupUi(this); + + connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); + connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); +} + +void gamepad_dialog::doOK() +{ + //s.b->save(); + close(); +} + +void gamepad_dialog::doCancel() +{ + close(); +} + +OPENTRACK_DECLARE_TRACKER(gamepad_tracker, gamepad_dialog, gamepad_metadata) diff --git a/tracker-qt-gamepad/test.h b/tracker-qt-gamepad/test.h new file mode 100644 index 00000000..ffa9ac44 --- /dev/null +++ b/tracker-qt-gamepad/test.h @@ -0,0 +1,45 @@ +#pragma once +#include "ui_test.h" +#include "api/plugin-api.hpp" +#include "compat/timer.hpp" + +#include <cmath> + +class gamepad_tracker : public ITracker +{ +public: + gamepad_tracker(); + ~gamepad_tracker() override; + void start_tracker(QFrame *) override; + void data(double *data) override; + +private: + static constexpr double r2d = 180 / M_PI; + static constexpr double d2r = M_PI / 180; + + static const double incr[6]; + double last_x[6]; + Timer t; +}; + +class gamepad_dialog : public ITrackerDialog +{ + Q_OBJECT + + Ui::test_ui ui; +public: + gamepad_dialog(); + void register_tracker(ITracker *) override {} + void unregister_tracker() override {} +private slots: + void doOK(); + void doCancel(); +}; + +class gamepad_metadata : public Metadata +{ +public: + QString name() { return QString(QCoreApplication::translate("gamepad_metadata", "Gamepad input")); } + QIcon icon() { return QIcon(":/images/facetracknoir.png"); } +}; + diff --git a/tracker-qt-gamepad/test.ui b/tracker-qt-gamepad/test.ui new file mode 100644 index 00000000..bdf2cd4e --- /dev/null +++ b/tracker-qt-gamepad/test.ui @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>test_ui</class> + <widget class="QWidget" name="test_ui"> + <property name="windowModality"> + <enum>Qt::NonModal</enum> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>352</width> + <height>224</height> + </rect> + </property> + <property name="windowTitle"> + <string>Gamepad input</string> + </property> + <property name="windowIcon"> + <iconset> + <normaloff>../gui/images/facetracknoir.png</normaloff>../gui/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> + <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-qt-gamepad/test_dialog.cpp b/tracker-qt-gamepad/test_dialog.cpp new file mode 100644 index 00000000..5d33555b --- /dev/null +++ b/tracker-qt-gamepad/test_dialog.cpp @@ -0,0 +1,3 @@ +#include "test.h" +#include "api/plugin-api.hpp" + |