From 95114eccc774bbb0fbeade8904aafa4f9b6d143d Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 25 Jul 2015 02:50:52 +0200 Subject: initial impl of arbitrary keybindings Issue: #118 Linux and OSX likely broken for now. --- facetracknoir/keyboard.h | 33 +++++++ facetracknoir/keyboard_listener.ui | 37 +++++++ facetracknoir/options-dialog.cpp | 50 ++++++---- facetracknoir/options-dialog.hpp | 1 + facetracknoir/settings.ui | 193 ++++++------------------------------- 5 files changed, 129 insertions(+), 185 deletions(-) create mode 100644 facetracknoir/keyboard.h create mode 100644 facetracknoir/keyboard_listener.ui (limited to 'facetracknoir') diff --git a/facetracknoir/keyboard.h b/facetracknoir/keyboard.h new file mode 100644 index 00000000..65f5c58e --- /dev/null +++ b/facetracknoir/keyboard.h @@ -0,0 +1,33 @@ +#pragma once +#include "ui_keyboard_listener.h" +#include +#include + +class KeyboardListener : public QLabel +{ + Q_OBJECT + Ui_keyboard_listener ui; +public: + KeyboardListener(QWidget* parent = nullptr) : QLabel(parent) + { + ui.setupUi(this); + setFocusPolicy(Qt::StrongFocus); + } + void keyPressEvent(QKeyEvent* event) override + { + { + switch (event->key() | event->modifiers()) + { + case 83886113: // ctrl + case 50331680: // shift + case 150994979: // alt + case 16777250: // meta + return; + default: break; + } + } + emit key_pressed(QKeySequence(event->key())); + } +signals: + void key_pressed(QKeySequence k); +}; diff --git a/facetracknoir/keyboard_listener.ui b/facetracknoir/keyboard_listener.ui new file mode 100644 index 00000000..69ec530d --- /dev/null +++ b/facetracknoir/keyboard_listener.ui @@ -0,0 +1,37 @@ + + + keyboard_listener + + + Qt::ApplicationModal + + + + 0 + 0 + 224 + 33 + + + + + 0 + 0 + + + + Bind a shortcut + + + <html><head/><body><p>Press a key or close this window to cancel.</p></body></html> + + + Qt::RichText + + + 10 + + + + + diff --git a/facetracknoir/options-dialog.cpp b/facetracknoir/options-dialog.cpp index ca4c6c3e..1d8e636a 100644 --- a/facetracknoir/options-dialog.cpp +++ b/facetracknoir/options-dialog.cpp @@ -7,6 +7,9 @@ */ #include "options-dialog.hpp" +#include "keyboard.h" +#include +#include OptionsDialog::OptionsDialog() { @@ -15,27 +18,6 @@ OptionsDialog::OptionsDialog() connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); - for ( int i = 0; i < global_key_sequences.size(); i++) { - ui.cbxCenterKey->addItem(global_key_sequences.at(i)); - ui.cbxToggleKey->addItem(global_key_sequences.at(i)); - ui.cbxZeroKey->addItem(global_key_sequences.at(i)); - } - - tie_setting(s.center.key_index, ui.cbxCenterKey); - tie_setting(s.center.alt, ui.chkCenterAlt); - tie_setting(s.center.shift, ui.chkCenterShift); - tie_setting(s.center.ctrl, ui.chkCenterCtrl); - - tie_setting(s.toggle.key_index, ui.cbxToggleKey); - tie_setting(s.toggle.alt, ui.chkToggleAlt); - tie_setting(s.toggle.shift, ui.chkToggleShift); - tie_setting(s.toggle.ctrl, ui.chkToggleCtrl); - - tie_setting(s.zero.key_index, ui.cbxZeroKey); - tie_setting(s.zero.alt, ui.chkZeroAlt); - tie_setting(s.zero.shift, ui.chkZeroShift); - tie_setting(s.zero.ctrl, ui.chkZeroCtrl); - tie_setting(s.s_main.tray_enabled, ui.trayp); tie_setting(s.s_main.center_at_startup, ui.center_at_startup); @@ -67,6 +49,32 @@ OptionsDialog::OptionsDialog() tie_setting(s.s_main.camera_yaw, ui.camera_yaw); tie_setting(s.s_main.camera_pitch, ui.camera_pitch); tie_setting(s.s_main.camera_roll, ui.camera_roll); + + connect(ui.bind_center, &QPushButton::pressed, [&]() -> void { bind_key(s.center.keycode, ui.center_text); }); + connect(ui.bind_zero, &QPushButton::pressed, [&]() -> void { bind_key(s.zero.keycode, ui.zero_text); }); + connect(ui.bind_toggle, &QPushButton::pressed, [&]() -> void { bind_key(s.toggle.keycode, ui.toggle_text); }); + + ui.center_text->setText(QKeySequence(s.center.keycode).toString()); + ui.zero_text->setText(QKeySequence(s.zero.keycode).toString()); + ui.toggle_text->setText(QKeySequence(s.toggle.keycode).toString()); +} + +void OptionsDialog::bind_key(value& ret, QLabel* label) +{ + ret = 0; + QDialog d; + auto l = new QHBoxLayout; + l->setMargin(0); + auto k = new KeyboardListener; + l->addWidget(k); + d.setLayout(l); + d.setFixedSize(QSize(500, 500)); + d.setWindowFlags(Qt::Dialog); + connect(k, &KeyboardListener::key_pressed, [&] (QKeySequence s) -> void { ret = static_cast(s).toInt(); d.close(); }); + d.exec(); + label->setText(QKeySequence(ret).toString()); + delete k; + delete l; } void OptionsDialog::doOK() { diff --git a/facetracknoir/options-dialog.hpp b/facetracknoir/options-dialog.hpp index 71a3acda..0ab9849d 100644 --- a/facetracknoir/options-dialog.hpp +++ b/facetracknoir/options-dialog.hpp @@ -18,4 +18,5 @@ private: private slots: void doOK(); void doCancel(); + void bind_key(value& ret, QLabel* label); }; diff --git a/facetracknoir/settings.ui b/facetracknoir/settings.ui index 34b15b47..5eea9e57 100644 --- a/facetracknoir/settings.ui +++ b/facetracknoir/settings.ui @@ -62,82 +62,48 @@ QGroupBox { border: 0; } - - + + - Toggle - - - false + - - - - - 50 - 16777215 - - + + - Shift + Center + + + false - - - - - 50 - 16777215 - - + + - Ctrl + - - - - - 90 - 0 - - - - Select Number - - - QComboBox::InsertAlphabetically + + + + - - + + - Center + Toggle false - - - - - 50 - 16777215 - - - - Alt - - - - + Zero @@ -147,113 +113,24 @@ - - - - - 50 - 16777215 - - - - Alt - - - - - - - - 50 - 16777215 - - - - Ctrl - - - - - - - - 50 - 16777215 - - - - Alt - - - - - - - - 50 - 16777215 - - + + - Ctrl + Bind - - - - - 50 - 16777215 - - + + - Shift + Bind - - - - - 90 - 0 - - - - Select Number - - - QComboBox::InsertAlphabetically - - - - - - - - 50 - 16777215 - - + + - Shift - - - - - - - - 90 - 0 - - - - Select Number - - - QComboBox::InsertAlphabetically + Bind @@ -1152,21 +1029,9 @@ - chkCenterShift tabWidget - chkCenterAlt - cbxCenterKey - chkToggleShift - chkToggleCtrl - chkToggleAlt - cbxToggleKey - chkZeroShift - chkZeroCtrl - chkZeroAlt - cbxZeroKey center_at_startup trayp - chkCenterCtrl camera_yaw camera_pitch camera_roll -- cgit v1.2.3 From 8494245b92e02f982a506ed044a555db239bd4d6 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 25 Jul 2015 05:18:01 +0200 Subject: shortcuts: store .ini value as portable string --- facetracknoir/options-dialog.cpp | 14 +++++++------- facetracknoir/options-dialog.hpp | 2 +- opentrack/shortcuts.cpp | 15 +++++++++++---- opentrack/shortcuts.h | 4 ++-- 4 files changed, 21 insertions(+), 14 deletions(-) (limited to 'facetracknoir') diff --git a/facetracknoir/options-dialog.cpp b/facetracknoir/options-dialog.cpp index 1d8e636a..8ac95b71 100644 --- a/facetracknoir/options-dialog.cpp +++ b/facetracknoir/options-dialog.cpp @@ -54,14 +54,14 @@ OptionsDialog::OptionsDialog() connect(ui.bind_zero, &QPushButton::pressed, [&]() -> void { bind_key(s.zero.keycode, ui.zero_text); }); connect(ui.bind_toggle, &QPushButton::pressed, [&]() -> void { bind_key(s.toggle.keycode, ui.toggle_text); }); - ui.center_text->setText(QKeySequence(s.center.keycode).toString()); - ui.zero_text->setText(QKeySequence(s.zero.keycode).toString()); - ui.toggle_text->setText(QKeySequence(s.toggle.keycode).toString()); + ui.center_text->setText(s.center.keycode == "" ? "None" : static_cast(s.center.keycode)); + ui.toggle_text->setText(s.toggle.keycode == "" ? "None" : static_cast(s.toggle.keycode)); + ui.zero_text->setText(s.zero.keycode == "" ? "None" : static_cast(s.zero.keycode)); } -void OptionsDialog::bind_key(value& ret, QLabel* label) +void OptionsDialog::bind_key(value& ret, QLabel* label) { - ret = 0; + ret = ""; QDialog d; auto l = new QHBoxLayout; l->setMargin(0); @@ -70,9 +70,9 @@ void OptionsDialog::bind_key(value& ret, QLabel* label) d.setLayout(l); d.setFixedSize(QSize(500, 500)); d.setWindowFlags(Qt::Dialog); - connect(k, &KeyboardListener::key_pressed, [&] (QKeySequence s) -> void { ret = static_cast(s).toInt(); d.close(); }); + connect(k, &KeyboardListener::key_pressed, [&] (QKeySequence s) -> void { ret = s.toString(QKeySequence::PortableText); d.close(); }); d.exec(); - label->setText(QKeySequence(ret).toString()); + label->setText(ret == "" ? "None" : static_cast(ret)); delete k; delete l; } diff --git a/facetracknoir/options-dialog.hpp b/facetracknoir/options-dialog.hpp index 0ab9849d..9ad656a4 100644 --- a/facetracknoir/options-dialog.hpp +++ b/facetracknoir/options-dialog.hpp @@ -18,5 +18,5 @@ private: private slots: void doOK(); void doCancel(); - void bind_key(value& ret, QLabel* label); + void bind_key(value& ret, QLabel* label); }; diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp index d68da30e..81393ae3 100644 --- a/opentrack/shortcuts.cpp +++ b/opentrack/shortcuts.cpp @@ -132,18 +132,25 @@ void Shortcuts::bind_keyboard_shortcut(K &key, key_opts& k) key->setShortcut(QKeySequence::UnknownKey); } - if (k.keycode) + if (k.keycode != "") { - key->setShortcut(QKeySequence(k.keycode)); + key->setShortcut(QKeySequence::fromString(k.keycode, QKeySequence::PortableText)); key->setEnabled(); } } #else key = K(); int idx = 0; + QKeySequence seq;; + + if (k.keycode == "") + code = QKeySequence(Qt::Key_unknown); + else + code = QKeySequence::fromString(k.keycode, QKeySequence::PortableText) + Qt::KeyboardModifiers mods = Qt::NoModifier; - if (k.keycode != Qt::Key_unknown) - win_key::from_qt(QKeySequence(k.keycode), idx, mods); + if (code != Qt::Key_unknown) + win_key::from_qt(code, idx, mods); key.shift = !!(mods & Qt::ShiftModifier); key.alt = !!(mods & Qt::AltModifier); key.ctrl = !!(mods & Qt::ControlModifier); diff --git a/opentrack/shortcuts.h b/opentrack/shortcuts.h index 6a9a6f77..2d7fec54 100644 --- a/opentrack/shortcuts.h +++ b/opentrack/shortcuts.h @@ -27,10 +27,10 @@ using namespace options; extern QList global_key_sequences; struct key_opts { - value keycode; + value keycode; key_opts(pbundle b, const QString& name) : - keycode(b, QString("keycode-%1").arg(name), 0) + keycode(b, QString("keycode-%1").arg(name), "") {} }; -- cgit v1.2.3 From 0a41cdc4d9bfaea20cfe07d71070f235c3bb8de6 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 25 Jul 2015 05:56:46 +0200 Subject: shortcuts: allow for modifier keys --- facetracknoir/keyboard.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'facetracknoir') diff --git a/facetracknoir/keyboard.h b/facetracknoir/keyboard.h index 65f5c58e..ccfd7a84 100644 --- a/facetracknoir/keyboard.h +++ b/facetracknoir/keyboard.h @@ -26,7 +26,7 @@ public: default: break; } } - emit key_pressed(QKeySequence(event->key())); + emit key_pressed(QKeySequence(event->key() | event->modifiers())); } signals: void key_pressed(QKeySequence k); -- cgit v1.2.3 From 92a56e52f7d4e843aea375f687a0c829f4003abd Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 25 Jul 2015 06:20:59 +0200 Subject: shortcuts: clarify binding dialog --- facetracknoir/keyboard_listener.ui | 2 +- facetracknoir/options-dialog.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'facetracknoir') diff --git a/facetracknoir/keyboard_listener.ui b/facetracknoir/keyboard_listener.ui index 69ec530d..b6977df0 100644 --- a/facetracknoir/keyboard_listener.ui +++ b/facetracknoir/keyboard_listener.ui @@ -23,7 +23,7 @@ Bind a shortcut - <html><head/><body><p>Press a key or close this window to cancel.</p></body></html> + <html><head/><body><p>Press a key or close this window to remove the keybinding.</p></body></html> Qt::RichText diff --git a/facetracknoir/options-dialog.cpp b/facetracknoir/options-dialog.cpp index 8ac95b71..b90408a8 100644 --- a/facetracknoir/options-dialog.cpp +++ b/facetracknoir/options-dialog.cpp @@ -68,7 +68,7 @@ void OptionsDialog::bind_key(value& ret, QLabel* label) auto k = new KeyboardListener; l->addWidget(k); d.setLayout(l); - d.setFixedSize(QSize(500, 500)); + d.setFixedSize(QSize(500, 300)); d.setWindowFlags(Qt::Dialog); connect(k, &KeyboardListener::key_pressed, [&] (QKeySequence s) -> void { ret = s.toString(QKeySequence::PortableText); d.close(); }); d.exec(); -- cgit v1.2.3 From e646166be460dce1553360463992d3df018d1906 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 25 Jul 2015 06:45:03 +0200 Subject: shortcuts: also guard against multiple-modifier combos --- facetracknoir/keyboard.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'facetracknoir') diff --git a/facetracknoir/keyboard.h b/facetracknoir/keyboard.h index ccfd7a84..a7673f8f 100644 --- a/facetracknoir/keyboard.h +++ b/facetracknoir/keyboard.h @@ -2,6 +2,7 @@ #include "ui_keyboard_listener.h" #include #include +#include class KeyboardListener : public QLabel { @@ -15,18 +16,21 @@ public: } void keyPressEvent(QKeyEvent* event) override { + //qDebug() << "k" << (event->key() | event->modifiers()); + switch (event->key() | event->modifiers()) { - switch (event->key() | event->modifiers()) - { - case 83886113: // ctrl - case 50331680: // shift - case 150994979: // alt - case 16777250: // meta - return; - default: break; - } + case 83886113: // ctrl + case 50331680: // shift + case 150994979: // alt + case 218103841: // ctrl+alt + case 117440545: // ctrl+shift + case 184549408: // alt+shift + case 251658272: // ctrl+alt+shift + break; + default: + emit key_pressed(QKeySequence(event->key() | event->modifiers())); + break; } - emit key_pressed(QKeySequence(event->key() | event->modifiers())); } signals: void key_pressed(QKeySequence k); -- cgit v1.2.3 From 24538cf3a3a91481851618791b11be81437563e4 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 25 Jul 2015 07:27:03 +0200 Subject: move portability classes to compat library --- CMakeLists.txt | 25 +++---- compat/compat.cpp | 81 ---------------------- compat/compat.h | 37 ---------- facetracknoir/facetracknoir.rc | 4 +- ftnoir_filter_accela/ftnoir_filter_accela.h | 2 +- ftnoir_protocol_ft/ftnoir_protocol_ft.h | 2 +- ftnoir_protocol_sc/scserver.manifest | 26 +++---- ftnoir_protocol_wine/ftnoir_protocol_wine.h | 2 +- .../opentrack-wrapper-wine-main.cxx | 4 +- .../opentrack-wrapper-wine-posix.cxx | 4 +- .../opentrack-wrapper-wine-windows.cxx | 4 +- ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp | 2 +- ftnoir_tracker_ht/ftnoir_tracker_ht.cpp | 2 +- ftnoir_tracker_ht/ftnoir_tracker_ht.h | 2 +- ftnoir_tracker_pt/camera.cpp | 2 +- ftnoir_tracker_pt/ftnoir_tracker_pt.h | 2 +- ftnoir_tracker_pt/point_extractor.cpp | 2 +- ftnoir_tracker_pt/point_tracker.h | 2 +- opentrack-compat/export.hpp | 13 ++++ opentrack-compat/mingw-version-script.txt | 8 +++ opentrack-compat/posix-version-script.txt | 8 +++ opentrack-compat/qcopyable-mutex.hpp | 37 ++++++++++ opentrack-compat/shm.cpp | 81 ++++++++++++++++++++++ opentrack-compat/shm.h | 37 ++++++++++ opentrack-compat/sleep.hpp | 22 ++++++ opentrack-compat/timer.hpp | 75 ++++++++++++++++++++ opentrack/export.hpp | 13 ---- opentrack/mingw-version-script.txt | 8 --- opentrack/plugin-api.hpp | 4 +- opentrack/pose.hpp | 22 ------ opentrack/posix-version-script.txt | 8 --- opentrack/qcopyable-mutex.hpp | 37 ---------- opentrack/sleep.hpp | 22 ------ opentrack/timer.hpp | 75 -------------------- opentrack/tracker.h | 20 +++++- opentrack/version.cc | 2 +- qfunctionconfigurator/functionconfig.h | 2 +- 37 files changed, 347 insertions(+), 352 deletions(-) delete mode 100644 compat/compat.cpp delete mode 100644 compat/compat.h create mode 100644 opentrack-compat/export.hpp create mode 100644 opentrack-compat/mingw-version-script.txt create mode 100644 opentrack-compat/posix-version-script.txt create mode 100644 opentrack-compat/qcopyable-mutex.hpp create mode 100644 opentrack-compat/shm.cpp create mode 100644 opentrack-compat/shm.h create mode 100644 opentrack-compat/sleep.hpp create mode 100644 opentrack-compat/timer.hpp delete mode 100644 opentrack/export.hpp delete mode 100644 opentrack/mingw-version-script.txt delete mode 100644 opentrack/pose.hpp delete mode 100644 opentrack/posix-version-script.txt delete mode 100644 opentrack/qcopyable-mutex.hpp delete mode 100644 opentrack/sleep.hpp delete mode 100644 opentrack/timer.hpp (limited to 'facetracknoir') diff --git a/CMakeLists.txt b/CMakeLists.txt index 6be4e425..e6a3afc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,10 +112,10 @@ macro(opentrack_library n dir) set(link-mode STATIC) endif() add_library(${n} ${link-mode} ${${n}-all}) - target_link_libraries(${n} opentrack-api ${MY_QT_LIBS}) + target_link_libraries(${n} opentrack-api ${MY_QT_LIBS} opentrack-compat) if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE) SET_TARGET_PROPERTIES(${n} PROPERTIES - LINK_FLAGS "${foolib_LINK} ${foolib_GNU-LINK} -Wl,--as-needed -Wl,--version-script=\"${CMAKE_SOURCE_DIR}/opentrack/${version-script}-version-script.txt\"" + LINK_FLAGS "${foolib_LINK} ${foolib_GNU-LINK} -Wl,--as-needed -Wl,--version-script=\"${CMAKE_SOURCE_DIR}/opentrack-compat/${version-script}-version-script.txt\"" COMPILE_FLAGS "${foolib_COMPILE} ${foolib_GNU-COMPILE} -fvisibility=hidden -fvisibility-inlines-hidden" ) else() @@ -125,7 +125,9 @@ macro(opentrack_library n dir) endif() set_target_properties(${n} PROPERTIES LINK_FLAGS "${link-flags} ${foolib_LINK}" COMPILE_FLAGS "${foolib_COMPILE}") endif() - install(TARGETS ${n} RUNTIME DESTINATION . LIBRARY DESTINATION .) + if(NOT foolib_STATIC) + install(TARGETS ${n} RUNTIME DESTINATION . LIBRARY DESTINATION .) + endif() endmacro() function(link_with_dinput8 n) @@ -194,13 +196,19 @@ opentrack_qt(opentrack-api) add_library(opentrack-api STATIC ${opentrack-api-all}) opentrack_compat(opentrack-api) target_link_libraries(opentrack-api ${MY_QT_LIBS}) - if(NOT WIN32) target_link_libraries(opentrack-api dl) else() target_link_libraries(opentrack-api winmm) endif() +opentrack_module(opentrack-compat opentrack-compat) +add_library(opentrack-compat STATIC ${opentrack-compat-c}) +opentrack_compat(opentrack-compat) # uh... +if(NOT WIN32 AND NOT APPLE) + target_link_libraries(opentrack-compat rt) +endif() + # ---- # conditional targets @@ -217,7 +225,6 @@ if(WIN32) ENABLE_LANGUAGE(RC) endif(WIN32) -opentrack_module(opentrack-compat compat) opentrack_module(opentrack-xplane-plugin x-plane-plugin) if(SDK_XPLANE) @@ -244,12 +251,6 @@ if(SDK_XPLANE) endif() endif() -add_library(opentrack-compat STATIC ${opentrack-compat-c}) -opentrack_compat(opentrack-compat) # uh... -if(NOT WIN32 AND NOT APPLE) - target_link_libraries(opentrack-compat rt) -endif() - opentrack_module(opentrack-csv csv) add_library(opentrack-csv STATIC ${opentrack-csv-c}) opentrack_compat(opentrack-csv) @@ -377,7 +378,7 @@ if(OpenCV_FOUND) if(SDK_HT AND SDK_HT_FLANDMARK) opentrack_library(opentrack-tracker-ht ftnoir_tracker_ht) - target_link_libraries(opentrack-tracker-ht opentrack-compat ${SDK_HT} ${SDK_HT_FLANDMARK} ${OpenCV_LIBS}) + target_link_libraries(opentrack-tracker-ht ${SDK_HT} ${SDK_HT_FLANDMARK} ${OpenCV_LIBS}) link_with_dinput8(opentrack-tracker-ht) target_include_directories(opentrack-tracker-ht SYSTEM PUBLIC ${OpenCV_INCLUDE_DIRS}) endif() diff --git a/compat/compat.cpp b/compat/compat.cpp deleted file mode 100644 index 9000b453..00000000 --- a/compat/compat.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* Copyright (c) 2013 Stanisław 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 "compat.h" - -#if defined(_WIN32) -PortableLockedShm::PortableLockedShm(const char* shmName, const char* mutexName, int mapSize) -{ - hMutex = CreateMutexA(NULL, false, mutexName); - hMapFile = CreateFileMappingA( - INVALID_HANDLE_VALUE, - NULL, - PAGE_READWRITE, - 0, - mapSize, - shmName); - mem = MapViewOfFile(hMapFile, - FILE_MAP_WRITE, - 0, - 0, - mapSize); -} - -PortableLockedShm::~PortableLockedShm() -{ - UnmapViewOfFile(mem); - CloseHandle(hMapFile); - CloseHandle(hMutex); -} - -void PortableLockedShm::lock() -{ - (void) WaitForSingleObject(hMutex, INFINITE); -} - -void PortableLockedShm::unlock() -{ - (void) ReleaseMutex(hMutex); -} -#else -#pragma GCC diagnostic ignored "-Wunused-result" -PortableLockedShm::PortableLockedShm(const char *shmName, const char* /*mutexName*/, int mapSize) : size(mapSize) -{ - char filename[512] = {0}; - strcpy(filename, "/"); - strcat(filename, shmName); - fd = shm_open(filename, O_RDWR | O_CREAT, 0600); - (void) ftruncate(fd, mapSize); - mem = mmap(NULL, mapSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, (off_t)0); -} - -PortableLockedShm::~PortableLockedShm() -{ - (void) munmap(mem, size); - (void) close(fd); -} - -void PortableLockedShm::lock() -{ - flock(fd, LOCK_EX); -} - -void PortableLockedShm::unlock() -{ - flock(fd, LOCK_UN); -} -#endif - -bool PortableLockedShm::success() -{ -#ifndef _WIN32 - return (void*) mem != (void*) -1; -#else - return (void*) mem != NULL; -#endif -} diff --git a/compat/compat.h b/compat/compat.h deleted file mode 100644 index 17a0d843..00000000 --- a/compat/compat.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (c) 2013 Stanisław 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. - */ -#pragma once - -#if defined(_WIN32) -#include -#else -#include -#include -#include -#include -#include -#include -#include -#include -#endif - -class PortableLockedShm { -public: - PortableLockedShm(const char *shmName, const char *mutexName, int mapSize); - ~PortableLockedShm(); - void lock(); - void unlock(); - bool success(); - inline void* ptr() { return mem; } -private: - void* mem; -#if defined(_WIN32) - HANDLE hMutex, hMapFile; -#else - int fd, size; -#endif -}; diff --git a/facetracknoir/facetracknoir.rc b/facetracknoir/facetracknoir.rc index 655baa9d..020ffe97 100644 --- a/facetracknoir/facetracknoir.rc +++ b/facetracknoir/facetracknoir.rc @@ -1,2 +1,2 @@ -#include -IDI_ICON1 ICON "facetracknoir.ico" +#include +IDI_ICON1 ICON "facetracknoir.ico" diff --git a/ftnoir_filter_accela/ftnoir_filter_accela.h b/ftnoir_filter_accela/ftnoir_filter_accela.h index 54845bfe..318cf909 100644 --- a/ftnoir_filter_accela/ftnoir_filter_accela.h +++ b/ftnoir_filter_accela/ftnoir_filter_accela.h @@ -14,7 +14,7 @@ #include "opentrack/options.hpp" using namespace options; -#include "opentrack/timer.hpp" +#include "opentrack-compat/timer.hpp" struct settings_accela : opts { value rot_threshold, trans_threshold, ewma, rot_deadzone, trans_deadzone; diff --git a/ftnoir_protocol_ft/ftnoir_protocol_ft.h b/ftnoir_protocol_ft/ftnoir_protocol_ft.h index f80a511b..6010de90 100644 --- a/ftnoir_protocol_ft/ftnoir_protocol_ft.h +++ b/ftnoir_protocol_ft/ftnoir_protocol_ft.h @@ -44,7 +44,7 @@ #include #include #include -#include "compat/compat.h" +#include "opentrack-compat/shm.h" #include "opentrack/options.hpp" #include "freetrackclient/fttypes.h" using namespace options; diff --git a/ftnoir_protocol_sc/scserver.manifest b/ftnoir_protocol_sc/scserver.manifest index 60311d6e..d342cfda 100644 --- a/ftnoir_protocol_sc/scserver.manifest +++ b/ftnoir_protocol_sc/scserver.manifest @@ -1,13 +1,13 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/ftnoir_protocol_wine/ftnoir_protocol_wine.h b/ftnoir_protocol_wine/ftnoir_protocol_wine.h index 528c4dd3..72897f1f 100644 --- a/ftnoir_protocol_wine/ftnoir_protocol_wine.h +++ b/ftnoir_protocol_wine/ftnoir_protocol_wine.h @@ -9,7 +9,7 @@ #include #include #include "opentrack/plugin-api.hpp" -#include "compat/compat.h" +#include "opentrack-compat/shm.h" #include "ftnoir_protocol_wine/wine-shm.h" class FTNoIR_Protocol : public IProtocol diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx index 026135f0..ffe8938d 100644 --- a/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx +++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx @@ -6,13 +6,13 @@ #include #include "freetrackclient/fttypes.h" #include "ftnoir_protocol_wine/wine-shm.h" -#include "opentrack/export.hpp" +#include "opentrack-compat/export.hpp" enum Axis { TX = 0, TY, TZ, Yaw, Pitch, Roll }; -#include "compat/compat.h" +#include "opentrack-compat/shm.h" void create_registry_key(void); diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx index 6f43f899..50cce728 100644 --- a/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx +++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx @@ -3,5 +3,5 @@ #endif #define PortableLockedShm ShmPosix -#include "compat/compat.h" -#include "compat/compat.cpp" +#include "opentrack-compat/shm.h" +#include "opentrack-compat/shm.cpp" diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx index 6592fbe6..19ee8ffd 100644 --- a/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx +++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx @@ -3,8 +3,8 @@ #endif #define PortableLockedShm ShmWine -#include "compat/compat.h" -#include "compat/compat.cpp" +#include "opentrack-compat/shm.h" +#include "opentrack-compat/shm.cpp" #include "wine-shm.h" static void write_path(const char* key, const char* subkey) diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp index 05f3e3a4..08ddd3b2 100644 --- a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp +++ b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp @@ -17,7 +17,7 @@ #include #include #include "opentrack/camera-names.hpp" -#include "opentrack/sleep.hpp" +#include "opentrack-compat/sleep.hpp" typedef struct { int width; diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp index ad13d716..cc9d2ba1 100644 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp +++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp @@ -4,7 +4,7 @@ #include "opentrack/plugin-api.hpp" #include #include "opentrack/camera-names.hpp" -#include "opentrack/sleep.hpp" +#include "opentrack-compat/sleep.hpp" typedef struct { int width; diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.h b/ftnoir_tracker_ht/ftnoir_tracker_ht.h index 32fb6949..16fdbe5c 100644 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.h +++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.h @@ -10,7 +10,7 @@ #include "headtracker-ftnoir.h" #include "ui_ht-trackercontrols.h" #include "ht_video_widget.h" -#include "compat/compat.h" +#include "opentrack-compat/shm.h" #include #include "opentrack/options.hpp" #include "opentrack/plugin-api.hpp" diff --git a/ftnoir_tracker_pt/camera.cpp b/ftnoir_tracker_pt/camera.cpp index 4619f695..9e11b815 100644 --- a/ftnoir_tracker_pt/camera.cpp +++ b/ftnoir_tracker_pt/camera.cpp @@ -8,7 +8,7 @@ #include "camera.h" #include #include -#include "opentrack/sleep.hpp" +#include "opentrack-compat/sleep.hpp" void Camera::set_device_index(int index) { diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.h b/ftnoir_tracker_pt/ftnoir_tracker_pt.h index b303a913..3291c7fc 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.h +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.h @@ -14,7 +14,7 @@ #include "point_extractor.h" #include "point_tracker.h" #include "pt_video_widget.h" -#include "opentrack/timer.hpp" +#include "opentrack-compat/timer.hpp" #include "opentrack/opencv-camera-dialog.hpp" #include diff --git a/ftnoir_tracker_pt/point_extractor.cpp b/ftnoir_tracker_pt/point_extractor.cpp index 4791dcc2..7174d719 100644 --- a/ftnoir_tracker_pt/point_extractor.cpp +++ b/ftnoir_tracker_pt/point_extractor.cpp @@ -9,7 +9,7 @@ #include #ifdef DEBUG_EXTRACTION -# include "opentrack/timer.hpp" +# include "opentrack-compat/timer.hpp" #endif PointExtractor::PointExtractor(){ diff --git a/ftnoir_tracker_pt/point_tracker.h b/ftnoir_tracker_pt/point_tracker.h index 7c710704..323eade4 100644 --- a/ftnoir_tracker_pt/point_tracker.h +++ b/ftnoir_tracker_pt/point_tracker.h @@ -15,7 +15,7 @@ # include #endif #include -#include "opentrack/timer.hpp" +#include "opentrack-compat/timer.hpp" #include "ftnoir_tracker_pt_settings.h" #include diff --git a/opentrack-compat/export.hpp b/opentrack-compat/export.hpp new file mode 100644 index 00000000..f0983b75 --- /dev/null +++ b/opentrack-compat/export.hpp @@ -0,0 +1,13 @@ +#pragma once + +#ifdef _WIN32 +# define OPENTRACK_LINKAGE __declspec(dllexport) +#else +# define OPENTRACK_LINKAGE +#endif + +#ifndef _MSC_VER +# define OPENTRACK_EXPORT __attribute__ ((visibility ("default"))) OPENTRACK_LINKAGE +#else +# define OPENTRACK_EXPORT OPENTRACK_LINKAGE +#endif \ No newline at end of file diff --git a/opentrack-compat/mingw-version-script.txt b/opentrack-compat/mingw-version-script.txt new file mode 100644 index 00000000..fe20ad37 --- /dev/null +++ b/opentrack-compat/mingw-version-script.txt @@ -0,0 +1,8 @@ +{ + global: + GetDialog?0; + GetConstructor?0; + GetMetadata?0; + local: + *; +}; diff --git a/opentrack-compat/posix-version-script.txt b/opentrack-compat/posix-version-script.txt new file mode 100644 index 00000000..97edb9aa --- /dev/null +++ b/opentrack-compat/posix-version-script.txt @@ -0,0 +1,8 @@ +{ + global: + GetDialog; + GetConstructor; + GetMetadata; + local: + *; +}; \ No newline at end of file diff --git a/opentrack-compat/qcopyable-mutex.hpp b/opentrack-compat/qcopyable-mutex.hpp new file mode 100644 index 00000000..f7f36f93 --- /dev/null +++ b/opentrack-compat/qcopyable-mutex.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include + +class MyMutex { +private: + QMutex inner; + +public: + QMutex* operator->() { return &inner; } + QMutex* operator->() const { return &const_cast(this)->inner; } + + MyMutex operator=(const MyMutex& datum) + { + auto mode = + datum->isRecursive() + ? QMutex::Recursive + : QMutex::NonRecursive; + + return MyMutex(mode); + } + + MyMutex(const MyMutex& datum) + { + *this = datum; + } + + MyMutex(QMutex::RecursionMode mode = QMutex::NonRecursive) : + inner(mode) + { + } + + QMutex* operator&() + { + return &inner; + } +}; diff --git a/opentrack-compat/shm.cpp b/opentrack-compat/shm.cpp new file mode 100644 index 00000000..b18a9933 --- /dev/null +++ b/opentrack-compat/shm.cpp @@ -0,0 +1,81 @@ +/* Copyright (c) 2013 Stanisław 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 "shm.h" + +#if defined(_WIN32) +PortableLockedShm::PortableLockedShm(const char* shmName, const char* mutexName, int mapSize) +{ + hMutex = CreateMutexA(NULL, false, mutexName); + hMapFile = CreateFileMappingA( + INVALID_HANDLE_VALUE, + NULL, + PAGE_READWRITE, + 0, + mapSize, + shmName); + mem = MapViewOfFile(hMapFile, + FILE_MAP_WRITE, + 0, + 0, + mapSize); +} + +PortableLockedShm::~PortableLockedShm() +{ + UnmapViewOfFile(mem); + CloseHandle(hMapFile); + CloseHandle(hMutex); +} + +void PortableLockedShm::lock() +{ + (void) WaitForSingleObject(hMutex, INFINITE); +} + +void PortableLockedShm::unlock() +{ + (void) ReleaseMutex(hMutex); +} +#else +#pragma GCC diagnostic ignored "-Wunused-result" +PortableLockedShm::PortableLockedShm(const char *shmName, const char* /*mutexName*/, int mapSize) : size(mapSize) +{ + char filename[512] = {0}; + strcpy(filename, "/"); + strcat(filename, shmName); + fd = shm_open(filename, O_RDWR | O_CREAT, 0600); + (void) ftruncate(fd, mapSize); + mem = mmap(NULL, mapSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, (off_t)0); +} + +PortableLockedShm::~PortableLockedShm() +{ + (void) munmap(mem, size); + (void) close(fd); +} + +void PortableLockedShm::lock() +{ + flock(fd, LOCK_EX); +} + +void PortableLockedShm::unlock() +{ + flock(fd, LOCK_UN); +} +#endif + +bool PortableLockedShm::success() +{ +#ifndef _WIN32 + return (void*) mem != (void*) -1; +#else + return (void*) mem != NULL; +#endif +} diff --git a/opentrack-compat/shm.h b/opentrack-compat/shm.h new file mode 100644 index 00000000..17a0d843 --- /dev/null +++ b/opentrack-compat/shm.h @@ -0,0 +1,37 @@ +/* Copyright (c) 2013 Stanisław 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. + */ +#pragma once + +#if defined(_WIN32) +#include +#else +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +class PortableLockedShm { +public: + PortableLockedShm(const char *shmName, const char *mutexName, int mapSize); + ~PortableLockedShm(); + void lock(); + void unlock(); + bool success(); + inline void* ptr() { return mem; } +private: + void* mem; +#if defined(_WIN32) + HANDLE hMutex, hMapFile; +#else + int fd, size; +#endif +}; diff --git a/opentrack-compat/sleep.hpp b/opentrack-compat/sleep.hpp new file mode 100644 index 00000000..27920842 --- /dev/null +++ b/opentrack-compat/sleep.hpp @@ -0,0 +1,22 @@ +#pragma once + +namespace portable +{ +#ifdef _WIN32 + #include + + template + void sleep(unsigned milliseconds) + { + Sleep(milliseconds); + } +#else + #include + + template + void sleep(unsigned milliseconds) + { + usleep(milliseconds * 1000U); // takes microseconds + } +#endif +} diff --git a/opentrack-compat/timer.hpp b/opentrack-compat/timer.hpp new file mode 100644 index 00000000..fd710499 --- /dev/null +++ b/opentrack-compat/timer.hpp @@ -0,0 +1,75 @@ +/* Copyright (c) 2014-2015, 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. + */ + +#pragma once +#include +#if defined (_WIN32) +# include +# ifndef CLOCK_MONOTONIC +# define CLOCK_MONOTONIC -1 +# endif +static inline void opentrack_clock_gettime(int, struct timespec* ts) +{ + static LARGE_INTEGER freq; + + if (!freq.QuadPart) + (void) QueryPerformanceFrequency(&freq); + + LARGE_INTEGER d; + + (void) QueryPerformanceCounter(&d); + + d.QuadPart *= 1000000000L; + d.QuadPart /= freq.QuadPart; + + ts->tv_sec = d.QuadPart / 1000000000L; + ts->tv_nsec = d.QuadPart % 1000000000L; +} +# define clock_gettime opentrack_clock_gettime +#else +# if defined(__MACH__) +# define CLOCK_MONOTONIC 0 +# include +# include +static inline void clock_gettime(int, struct timespec* ts) +{ + static mach_timebase_info_data_t sTimebaseInfo; + uint64_t state, nsec; + if ( sTimebaseInfo.denom == 0 ) { + (void) mach_timebase_info(&sTimebaseInfo); + } + state = mach_absolute_time(); + nsec = state * sTimebaseInfo.numer / sTimebaseInfo.denom; + ts->tv_sec = nsec / 1000000000L; + ts->tv_nsec = nsec % 1000000000L; +} +# endif +#endif +class Timer { +private: + struct timespec state; + long conv(const struct timespec& cur) + { + return (cur.tv_sec - state.tv_sec) * 1000000000L + (cur.tv_nsec - state.tv_nsec); + } +public: + Timer() { + start(); + } + void start() { + (void) clock_gettime(CLOCK_MONOTONIC, &state); + } + long elapsed() { + struct timespec cur; + (void) clock_gettime(CLOCK_MONOTONIC, &cur); + return conv(cur); + } + long elapsed_ms() { + return elapsed() / 1000000L; + } +}; diff --git a/opentrack/export.hpp b/opentrack/export.hpp deleted file mode 100644 index f0983b75..00000000 --- a/opentrack/export.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#ifdef _WIN32 -# define OPENTRACK_LINKAGE __declspec(dllexport) -#else -# define OPENTRACK_LINKAGE -#endif - -#ifndef _MSC_VER -# define OPENTRACK_EXPORT __attribute__ ((visibility ("default"))) OPENTRACK_LINKAGE -#else -# define OPENTRACK_EXPORT OPENTRACK_LINKAGE -#endif \ No newline at end of file diff --git a/opentrack/mingw-version-script.txt b/opentrack/mingw-version-script.txt deleted file mode 100644 index fe20ad37..00000000 --- a/opentrack/mingw-version-script.txt +++ /dev/null @@ -1,8 +0,0 @@ -{ - global: - GetDialog?0; - GetConstructor?0; - GetMetadata?0; - local: - *; -}; diff --git a/opentrack/plugin-api.hpp b/opentrack/plugin-api.hpp index b0da4950..572b7f31 100644 --- a/opentrack/plugin-api.hpp +++ b/opentrack/plugin-api.hpp @@ -8,7 +8,7 @@ #pragma once -#include "export.hpp" +#include "../opentrack-compat/export.hpp" #include #include #include @@ -59,7 +59,7 @@ struct IFilter // optional destructor virtual ~IFilter() {} // perform filtering step. - // you have to take care of dt on your own, try "opentrack/timer.hpp" + // you have to take care of dt on your own, try "opentrack-compat/timer.hpp" virtual void filter(const double *input, double *output) = 0; }; diff --git a/opentrack/pose.hpp b/opentrack/pose.hpp deleted file mode 100644 index 93d467a9..00000000 --- a/opentrack/pose.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include -#include -#include "./plugin-api.hpp" - -class Pose { -private: - static constexpr double pi = 3.141592653; - static constexpr double d2r = pi/180.0; - static constexpr double r2d = 180./pi; - - double axes[6]; -public: - Pose() : axes {0,0,0, 0,0,0} {} - - inline operator double*() { return axes; } - inline operator const double*() const { return axes; } - - inline double& operator()(int i) { return axes[i]; } - inline double operator()(int i) const { return axes[i]; } -}; diff --git a/opentrack/posix-version-script.txt b/opentrack/posix-version-script.txt deleted file mode 100644 index 97edb9aa..00000000 --- a/opentrack/posix-version-script.txt +++ /dev/null @@ -1,8 +0,0 @@ -{ - global: - GetDialog; - GetConstructor; - GetMetadata; - local: - *; -}; \ No newline at end of file diff --git a/opentrack/qcopyable-mutex.hpp b/opentrack/qcopyable-mutex.hpp deleted file mode 100644 index f7f36f93..00000000 --- a/opentrack/qcopyable-mutex.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include - -class MyMutex { -private: - QMutex inner; - -public: - QMutex* operator->() { return &inner; } - QMutex* operator->() const { return &const_cast(this)->inner; } - - MyMutex operator=(const MyMutex& datum) - { - auto mode = - datum->isRecursive() - ? QMutex::Recursive - : QMutex::NonRecursive; - - return MyMutex(mode); - } - - MyMutex(const MyMutex& datum) - { - *this = datum; - } - - MyMutex(QMutex::RecursionMode mode = QMutex::NonRecursive) : - inner(mode) - { - } - - QMutex* operator&() - { - return &inner; - } -}; diff --git a/opentrack/sleep.hpp b/opentrack/sleep.hpp deleted file mode 100644 index 27920842..00000000 --- a/opentrack/sleep.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -namespace portable -{ -#ifdef _WIN32 - #include - - template - void sleep(unsigned milliseconds) - { - Sleep(milliseconds); - } -#else - #include - - template - void sleep(unsigned milliseconds) - { - usleep(milliseconds * 1000U); // takes microseconds - } -#endif -} diff --git a/opentrack/timer.hpp b/opentrack/timer.hpp deleted file mode 100644 index fd710499..00000000 --- a/opentrack/timer.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/* Copyright (c) 2014-2015, 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. - */ - -#pragma once -#include -#if defined (_WIN32) -# include -# ifndef CLOCK_MONOTONIC -# define CLOCK_MONOTONIC -1 -# endif -static inline void opentrack_clock_gettime(int, struct timespec* ts) -{ - static LARGE_INTEGER freq; - - if (!freq.QuadPart) - (void) QueryPerformanceFrequency(&freq); - - LARGE_INTEGER d; - - (void) QueryPerformanceCounter(&d); - - d.QuadPart *= 1000000000L; - d.QuadPart /= freq.QuadPart; - - ts->tv_sec = d.QuadPart / 1000000000L; - ts->tv_nsec = d.QuadPart % 1000000000L; -} -# define clock_gettime opentrack_clock_gettime -#else -# if defined(__MACH__) -# define CLOCK_MONOTONIC 0 -# include -# include -static inline void clock_gettime(int, struct timespec* ts) -{ - static mach_timebase_info_data_t sTimebaseInfo; - uint64_t state, nsec; - if ( sTimebaseInfo.denom == 0 ) { - (void) mach_timebase_info(&sTimebaseInfo); - } - state = mach_absolute_time(); - nsec = state * sTimebaseInfo.numer / sTimebaseInfo.denom; - ts->tv_sec = nsec / 1000000000L; - ts->tv_nsec = nsec % 1000000000L; -} -# endif -#endif -class Timer { -private: - struct timespec state; - long conv(const struct timespec& cur) - { - return (cur.tv_sec - state.tv_sec) * 1000000000L + (cur.tv_nsec - state.tv_nsec); - } -public: - Timer() { - start(); - } - void start() { - (void) clock_gettime(CLOCK_MONOTONIC, &state); - } - long elapsed() { - struct timespec cur; - (void) clock_gettime(CLOCK_MONOTONIC, &cur); - return conv(cur); - } - long elapsed_ms() { - return elapsed() / 1000000L; - } -}; diff --git a/opentrack/tracker.h b/opentrack/tracker.h index 453357c4..c5c39797 100644 --- a/opentrack/tracker.h +++ b/opentrack/tracker.h @@ -10,10 +10,9 @@ #include -#include "timer.hpp" +#include "opentrack-compat/timer.hpp" #include "plugin-support.hpp" #include "mappings.hpp" -#include "pose.hpp" #include "simple-mat.hpp" #include "selected-libraries.hpp" @@ -24,6 +23,23 @@ #include #include +class Pose { +private: + static constexpr double pi = 3.141592653; + static constexpr double d2r = pi/180.0; + static constexpr double r2d = 180./pi; + + double axes[6]; +public: + Pose() : axes {0,0,0, 0,0,0} {} + + inline operator double*() { return axes; } + inline operator const double*() const { return axes; } + + inline double& operator()(int i) { return axes[i]; } + inline double operator()(int i) const { return axes[i]; } +}; + class Tracker : private QThread { Q_OBJECT private: diff --git a/opentrack/version.cc b/opentrack/version.cc index 026ad057..13bc5dc5 100644 --- a/opentrack/version.cc +++ b/opentrack/version.cc @@ -1,4 +1,4 @@ -#include "opentrack/export.hpp" +#include "opentrack-compat/export.hpp" #ifdef __cplusplus extern "C" diff --git a/qfunctionconfigurator/functionconfig.h b/qfunctionconfigurator/functionconfig.h index 7ead2c5d..a8b46597 100644 --- a/qfunctionconfigurator/functionconfig.h +++ b/qfunctionconfigurator/functionconfig.h @@ -14,7 +14,7 @@ #include #include #include -#include "opentrack/qcopyable-mutex.hpp" +#include "opentrack-compat/qcopyable-mutex.hpp" class Map { private: -- cgit v1.2.3