diff options
64 files changed, 504 insertions, 453 deletions
diff --git a/api/plugin-api.cpp b/api/plugin-api.cpp index c28b5d4e..eed377b0 100644 --- a/api/plugin-api.cpp +++ b/api/plugin-api.cpp @@ -26,6 +26,16 @@ void BaseDialog::closeEvent(QCloseEvent*) bool ITracker::center() { return false; } +module_status ITracker::status_ok() +{ + return module_status(); +} + +module_status ITracker::error(const QString& error) +{ + return module_status(error); +} + Metadata::Metadata() {} IFilter::IFilter() {} IFilterDialog::IFilterDialog() {} @@ -46,3 +56,14 @@ void BaseDialog::done(int) IExtensionDialog::~IExtensionDialog() { } + +bool module_status::is_ok() const +{ + return error.isEmpty(); +} + +module_status::module_status(const QString& error) : error(error) {} + +module_status module_status_mixin::status_ok() { return module_status(); } + +module_status module_status_mixin::error(const QString& error) { return module_status(error); } diff --git a/api/plugin-api.hpp b/api/plugin-api.hpp index 29f678f3..15a2cc48 100644 --- a/api/plugin-api.hpp +++ b/api/plugin-api.hpp @@ -82,8 +82,24 @@ struct OTR_API_EXPORT Metadata virtual ~Metadata(); }; +struct OTR_API_EXPORT module_status final +{ + QString error; + + bool is_ok() const; + module_status(const QString& error = QString()); +}; + +struct OTR_API_EXPORT module_status_mixin +{ + static module_status status_ok(); + static module_status error(const QString& error); + + virtual module_status check_status() = 0; +}; + // implement this in filters -struct OTR_API_EXPORT IFilter +struct OTR_API_EXPORT IFilter : module_status_mixin { IFilter(const IFilter&) = delete; IFilter(IFilter&&) = delete; @@ -116,7 +132,7 @@ struct OTR_API_EXPORT IFilterDialog : public plugin_api::detail::BaseDialog OPENTRACK_DECLARE_PLUGIN_INTERNAL(filter_class, IFilter, metadata_class, dialog_class, IFilterDialog) // implement this in protocols -struct OTR_API_EXPORT IProtocol +struct OTR_API_EXPORT IProtocol : module_status_mixin { IProtocol(); @@ -126,10 +142,8 @@ struct OTR_API_EXPORT IProtocol // optional destructor virtual ~IProtocol(); - // return true if protocol was properly initialized - virtual bool correct() = 0; // called 250 times a second with XYZ yaw pitch roll pose - // try not to perform intense computation here. if you must, use a thread. + // try not to perform intense computation here. use a thread. virtual void pose(const double* headpose) = 0; // return game name or placeholder text virtual QString game_name() = 0; @@ -159,13 +173,16 @@ struct OTR_API_EXPORT ITracker // optional destructor virtual ~ITracker(); // start tracking, and grab a frame to display webcam video in, optionally - virtual void start_tracker(QFrame* frame) = 0; + virtual module_status start_tracker(QFrame* frame) = 0; // return XYZ yaw pitch roll data. don't block here, use a separate thread for computation. virtual void data(double *data) = 0; // tracker notified of centering // returning true makes identity the center pose virtual bool center(); + static module_status status_ok(); + static module_status error(const QString& error); + ITracker(const ITracker&) = delete; ITracker(ITracker&&) = delete; ITracker& operator=(const ITracker&) = delete; @@ -187,7 +204,7 @@ struct OTR_API_EXPORT ITrackerDialog : public plugin_api::detail::BaseDialog #define OPENTRACK_DECLARE_TRACKER(tracker_class, dialog_class, metadata_class) \ OPENTRACK_DECLARE_PLUGIN_INTERNAL(tracker_class, ITracker, metadata_class, dialog_class, ITrackerDialog) -struct OTR_API_EXPORT IExtension +struct OTR_API_EXPORT IExtension : module_status_mixin { enum event_mask : unsigned { diff --git a/ext-falcon-bms-linear-acc/falcon-bms-ext.hpp b/ext-falcon-bms-linear-acc/falcon-bms-ext.hpp index 4dd6c5d5..d5d5216f 100644 --- a/ext-falcon-bms-linear-acc/falcon-bms-ext.hpp +++ b/ext-falcon-bms-linear-acc/falcon-bms-ext.hpp @@ -8,4 +8,5 @@ struct falcon_bms_acceleration_ext : IExtension event_mask hook_types() override; falcon_bms_acceleration_ext(); void process_finished(Pose&p) override; + module_status check_status() override { return status_ok(); } }; diff --git a/filter-accela/ftnoir_filter_accela.h b/filter-accela/ftnoir_filter_accela.h index f3fcb6a5..990a9750 100644 --- a/filter-accela/ftnoir_filter_accela.h +++ b/filter-accela/ftnoir_filter_accela.h @@ -23,6 +23,7 @@ public: void filter(const double* input, double *output) override; void center() override { first_run = true; } spline spline_rot, spline_pos; + module_status check_status() override { return status_ok(); } private: settings_accela s; double last_output[6], deltas[6]; diff --git a/filter-ewma2/ftnoir_filter_ewma2.h b/filter-ewma2/ftnoir_filter_ewma2.h index f8c77280..4c019bd0 100644 --- a/filter-ewma2/ftnoir_filter_ewma2.h +++ b/filter-ewma2/ftnoir_filter_ewma2.h @@ -25,6 +25,7 @@ public: ewma(); void filter(const double *input, double *output) override; void center() override { first_run = true; } + module_status check_status() override { return status_ok(); } private: // Deltas are smoothed over the last 1/60sec. const double delta_RC = 1./60; diff --git a/gui/main-window.cpp b/gui/main-window.cpp index 87a7ad8e..b0f26cbe 100644 --- a/gui/main-window.cpp +++ b/gui/main-window.cpp @@ -506,10 +506,6 @@ void MainWindow::start_tracker_() if (!work->is_ok()) { - QMessageBox::warning(this, tr("Library load error"), - tr("One of libraries failed to load. Check installation."), - QMessageBox::Ok, - QMessageBox::NoButton); work = nullptr; return; } diff --git a/logic/runtime-libraries.cpp b/logic/runtime-libraries.cpp index a04da6a2..8feeaaba 100644 --- a/logic/runtime-libraries.cpp +++ b/logic/runtime-libraries.cpp @@ -1,13 +1,13 @@ #include "runtime-libraries.hpp" #include "options/scoped.hpp" +#include <QMessageBox> #include <QDebug> -runtime_libraries::runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dylibptr f) : - pTracker(nullptr), - pFilter(nullptr), - pProtocol(nullptr), - correct(false) +runtime_libraries::runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dylibptr f) { + module_status status = + module_status_mixin::error(QCoreApplication::translate("module", "Library load failure")); + using namespace options; with_tracker_teardown sentinel; @@ -15,15 +15,12 @@ runtime_libraries::runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dyli pProtocol = make_dylib_instance<IProtocol>(p); if (!pProtocol) - { - qDebug() << "protocol dylib load failure"; goto end; - } - if(!pProtocol->correct()) + if(status = pProtocol->check_status(), !status.is_ok()) { - qDebug() << "protocol load failure"; - pProtocol = nullptr; + status = QCoreApplication::translate("module", "Error occured while loading protocol %1\n\n%2\n") + .arg(p->name).arg(status.error); goto end; } @@ -36,10 +33,30 @@ runtime_libraries::runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dyli goto end; } - pTracker->start_tracker(frame); + if (pFilter) + if(status = pFilter->check_status(), !status.is_ok()) + { + status = QCoreApplication::translate("module", "Error occured while loading filter %1\n\n%2\n") + .arg(f->name).arg(status.error); + goto end; + } + + if (status = pTracker->start_tracker(frame), !status.is_ok()) + { + status = QCoreApplication::translate("module", "Error occured while loading tracker %1\n\n%2\n") + .arg(t->name).arg(status.error); + goto end; + } correct = true; + return; + end: - (void)0; + pTracker = nullptr; + pFilter = nullptr; + pProtocol = nullptr; + + if (!status.is_ok()) + QMessageBox::critical(nullptr, "Startup failure", status.error, QMessageBox::Cancel, QMessageBox::NoButton); } diff --git a/logic/runtime-libraries.hpp b/logic/runtime-libraries.hpp index cc96f0e7..1105c179 100644 --- a/logic/runtime-libraries.hpp +++ b/logic/runtime-libraries.hpp @@ -24,5 +24,5 @@ struct OTR_LOGIC_EXPORT runtime_libraries final runtime_libraries(QFrame* frame, dylibptr t, dylibptr p, dylibptr f); runtime_libraries() : pTracker(nullptr), pFilter(nullptr), pProtocol(nullptr), correct(false) {} - bool correct; + bool correct = false; }; diff --git a/options/base-value.hpp b/options/base-value.hpp index 7bf83619..f000edb1 100644 --- a/options/base-value.hpp +++ b/options/base-value.hpp @@ -28,6 +28,7 @@ class OTR_OPTIONS_EXPORT base_value : public QObject using comparator = bool(*)(const QVariant& val1, const QVariant& val2); template<typename t> using signal_sig = void(base_value::*)(cv_qualified<t>) const; + public: bundle get_bundle() { return b; } QString name() const { return self_name; } diff --git a/proto-flightgear/ftnoir_protocol_fg.cpp b/proto-flightgear/ftnoir_protocol_fg.cpp index 3e0f955c..e1101c0f 100644 --- a/proto-flightgear/ftnoir_protocol_fg.cpp +++ b/proto-flightgear/ftnoir_protocol_fg.cpp @@ -25,9 +25,14 @@ void flightgear::pose(const double* headpose) { (void) outSocket.writeDatagram(reinterpret_cast<const char*>(&FlightData), sizeof(FlightData), destIP, static_cast<quint16>(s.port)); } -bool flightgear::correct() +module_status flightgear::check_status() { - return outSocket.bind(QHostAddress::Any, 0, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint); + if (outSocket.bind(QHostAddress::Any, 0, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint)) + return status_ok(); + else + return error(QCoreApplication::translate("flightgear", "Can't bind to [%1.%2.%3.%4]:%5") + .arg(s.ip1).arg(s.ip2).arg(s.ip3).arg(s.ip4) + .arg(s.port)); } OPENTRACK_DECLARE_PROTOCOL(flightgear, FGControls, flightgearDll) diff --git a/proto-flightgear/ftnoir_protocol_fg.h b/proto-flightgear/ftnoir_protocol_fg.h index 48e5f1c1..31a7660c 100644 --- a/proto-flightgear/ftnoir_protocol_fg.h +++ b/proto-flightgear/ftnoir_protocol_fg.h @@ -41,11 +41,9 @@ struct settings : opts { class flightgear : public IProtocol { public: - bool correct(); void pose(const double *headpose); - QString game_name() { - return QCoreApplication::translate("flightgear", "FlightGear"); - } + QString game_name() { return QCoreApplication::translate("flightgear", "FlightGear"); } + module_status check_status() override; private: settings s; flightgear_datagram FlightData; diff --git a/proto-fsuipc/ftnoir_protocol_fsuipc.cpp b/proto-fsuipc/ftnoir_protocol_fsuipc.cpp index 959408fe..b5259581 100644 --- a/proto-fsuipc/ftnoir_protocol_fsuipc.cpp +++ b/proto-fsuipc/ftnoir_protocol_fsuipc.cpp @@ -144,23 +144,14 @@ void fsuipc::pose(const double *headpose ) { prevRotZ = virtRotZ; } -bool fsuipc::correct() +module_status fsuipc::check_status() { - qDebug() << "correct says: Starting Function"; - - // - // Load the DLL. - // FSUIPCLib.setFileName( s.LocationOfDLL ); - if (FSUIPCLib.load() != true) { - qDebug() << "correct says: Error loading FSUIPC DLL"; - return false; - } - else { - qDebug() << "correct says: FSUIPC DLL loaded."; - } - return true; + if (FSUIPCLib.load() != true) + return error(QCoreApplication::translate("fsuipc", "Can't load fsuipc at '%1'").arg(s.LocationOfDLL)); + else + return status_ok(); } OPENTRACK_DECLARE_PROTOCOL(fsuipc, FSUIPCControls, fsuipcDll) diff --git a/proto-fsuipc/ftnoir_protocol_fsuipc.h b/proto-fsuipc/ftnoir_protocol_fsuipc.h index cd2ed9a7..54171ce7 100644 --- a/proto-fsuipc/ftnoir_protocol_fsuipc.h +++ b/proto-fsuipc/ftnoir_protocol_fsuipc.h @@ -50,12 +50,9 @@ class fsuipc : public IProtocol public: fsuipc(); ~fsuipc() override; - bool correct(); + module_status check_status() override; void pose(const double* headpose); - QString game_name() - { - return QCoreApplication::translate("fsuipc", "Microsoft Flight Simulator X"); - } + QString game_name() { return QCoreApplication::translate("fsuipc", "Microsoft Flight Simulator X"); } private: QLibrary FSUIPCLib; double prevPosX, prevPosY, prevPosZ, prevRotX, prevRotY, prevRotZ; diff --git a/proto-ft/ftnoir_protocol_ft.cpp b/proto-ft/ftnoir_protocol_ft.cpp index fbfc23d9..d03ca59a 100644 --- a/proto-ft/ftnoir_protocol_ft.cpp +++ b/proto-ft/ftnoir_protocol_ft.cpp @@ -192,10 +192,10 @@ void freetrack::set_protocols(bool ft, bool npclient) settings_npclient.setValue("Path", ""); } -bool freetrack::correct() +module_status freetrack::check_status() { if (!shm.success()) - return false; + return error("Can't load freetrack memory mapping"); bool use_ft = false, use_npclient = false; @@ -241,7 +241,7 @@ bool freetrack::correct() if (use_npclient) start_dummy(); - return true; + return status_ok(); } OPENTRACK_DECLARE_PROTOCOL(freetrack, FTControls, freetrackDll) diff --git a/proto-ft/ftnoir_protocol_ft.h b/proto-ft/ftnoir_protocol_ft.h index 43c1c3fc..e2faacf3 100644 --- a/proto-ft/ftnoir_protocol_ft.h +++ b/proto-ft/ftnoir_protocol_ft.h @@ -49,7 +49,7 @@ class freetrack : public IProtocol public: freetrack(); ~freetrack() override; - bool correct(); + module_status check_status() override; void pose( const double *headpose ); QString game_name() override { QMutexLocker foo(&game_name_mutex); diff --git a/proto-iokit-foohid/iokitprotocol.cpp b/proto-iokit-foohid/iokitprotocol.cpp index 4af6ad5b..693ce31e 100644 --- a/proto-iokit-foohid/iokitprotocol.cpp +++ b/proto-iokit-foohid/iokitprotocol.cpp @@ -20,9 +20,22 @@ IOKitProtocol::IOKitProtocol() qWarning("%s\n", qPrintable(joystick->errorMessage())); } -bool IOKitProtocol::correct() +module_status IOKitProtocol::check_status() { - return joystick && !joystick->hasError(); + if (!joystick) + return QCoreApplication::translate("foohid", "Load failure"); + + if (joystick->hasError()) + { + QString msg = joystick->errorMessage(); + + if (msg.isEmpty()) + msg = QCoreApplication::translate("foohid", "Unknown error"); + + return error(msg); + } + + return status_ok(); } static uint8_t valueToStick(FooHIDJoystick *stick, double min, double value, double max) diff --git a/proto-iokit-foohid/iokitprotocol.h b/proto-iokit-foohid/iokitprotocol.h index f3f4089f..4c5b13a4 100644 --- a/proto-iokit-foohid/iokitprotocol.h +++ b/proto-iokit-foohid/iokitprotocol.h @@ -18,7 +18,7 @@ class IOKitProtocol : public IProtocol public: IOKitProtocol(); - bool correct() final; + module_status check_status() override; void pose(const double *headpose) final; QString game_name() final; diff --git a/proto-mouse/ftnoir_protocol_mouse.cpp b/proto-mouse/ftnoir_protocol_mouse.cpp index d03c6c66..80426460 100644 --- a/proto-mouse/ftnoir_protocol_mouse.cpp +++ b/proto-mouse/ftnoir_protocol_mouse.cpp @@ -82,9 +82,4 @@ int mouse::get_value(double val, double sensitivity, bool is_rotation) mouse::mouse() : last_x(0), last_y(0) {} -bool mouse::correct() -{ - return true; -} - OPENTRACK_DECLARE_PROTOCOL(mouse, MOUSEControls, mouseDll) diff --git a/proto-mouse/ftnoir_protocol_mouse.h b/proto-mouse/ftnoir_protocol_mouse.h index 4f0bf5a7..99557d17 100644 --- a/proto-mouse/ftnoir_protocol_mouse.h +++ b/proto-mouse/ftnoir_protocol_mouse.h @@ -29,7 +29,7 @@ class mouse : public IProtocol { public: mouse(); - bool correct() override; + module_status check_status() override { return status_ok(); } void pose( const double *headpose) override; QString game_name() override; diff --git a/proto-simconnect/ftnoir_protocol_sc.cpp b/proto-simconnect/ftnoir_protocol_sc.cpp index c37fa91c..787cf0e3 100644 --- a/proto-simconnect/ftnoir_protocol_sc.cpp +++ b/proto-simconnect/ftnoir_protocol_sc.cpp @@ -161,7 +161,7 @@ private: bool ok; }; -bool simconnect::correct() +module_status simconnect::check_status() { if (!SCClientLib.isLoaded()) { @@ -170,46 +170,39 @@ bool simconnect::correct() if (ctx.is_ok()) { SCClientLib.setFileName("SimConnect.dll"); - if (!SCClientLib.load()) { - qDebug() << "simconnect: dll load failed --" << SCClientLib.errorString(); - return false; - } + if (!SCClientLib.load()) + return error(tr("dll load failed -- %1").arg(SCClientLib.errorString())); } else - return false; + return error("can't load SDK -- check selected simconnect version"); } simconnect_open = (importSimConnect_Open) SCClientLib.resolve("SimConnect_Open"); if (simconnect_open == NULL) { - qDebug() << "simconnect: SimConnect_Open function not found in DLL!"; - return false; + return error("simconnect: SimConnect_Open function not found in DLL!"); } simconnect_set6DOF = (importSimConnect_CameraSetRelative6DOF) SCClientLib.resolve("SimConnect_CameraSetRelative6DOF"); if (simconnect_set6DOF == NULL) { - qDebug() << "simconnect: SimConnect_CameraSetRelative6DOF function not found in DLL!"; - return false; + return error("simconnect: SimConnect_CameraSetRelative6DOF function not found in DLL!"); } simconnect_close = (importSimConnect_Close) SCClientLib.resolve("SimConnect_Close"); if (simconnect_close == NULL) { - qDebug() << "simconnect: SimConnect_Close function not found in DLL!"; - return false; + return error("simconnect: SimConnect_Close function not found in DLL!"); } simconnect_calldispatch = (importSimConnect_CallDispatch) SCClientLib.resolve("SimConnect_CallDispatch"); if (simconnect_calldispatch == NULL) { - qDebug() << "simconnect: SimConnect_CallDispatch function not found in DLL!"; - return false; + return error("simconnect: SimConnect_CallDispatch function not found in DLL!"); } simconnect_subscribetosystemevent = (importSimConnect_SubscribeToSystemEvent) SCClientLib.resolve("SimConnect_SubscribeToSystemEvent"); if (simconnect_subscribetosystemevent == NULL) { - qDebug() << "simconnect: SimConnect_SubscribeToSystemEvent function not found in DLL!"; - return false; + return error("simconnect: SimConnect_SubscribeToSystemEvent function not found in DLL!"); } start(); - return true; + return status_ok(); } void simconnect::handle() diff --git a/proto-simconnect/ftnoir_protocol_sc.h b/proto-simconnect/ftnoir_protocol_sc.h index 151dd741..4174bc0c 100644 --- a/proto-simconnect/ftnoir_protocol_sc.h +++ b/proto-simconnect/ftnoir_protocol_sc.h @@ -39,7 +39,7 @@ class simconnect : public IProtocol, private QThread public: simconnect(); ~simconnect() override; - bool correct(); + module_status check_status() override; void pose(const double* headpose); void handle(); QString game_name() { diff --git a/proto-udp/ftnoir_ftncontrols.ui b/proto-udp/ftnoir_ftncontrols.ui index 28f8ccdf..d6a4dfce 100644 --- a/proto-udp/ftnoir_ftncontrols.ui +++ b/proto-udp/ftnoir_ftncontrols.ui @@ -9,15 +9,15 @@ <rect> <x>0</x> <y>0</y> - <width>411</width> - <height>169</height> + <width>372</width> + <height>106</height> </rect> </property> <property name="windowTitle"> <string>UDP protocol settings</string> </property> <property name="windowIcon"> - <iconset resource="../gui/main-facetracknoir.qrc"> + <iconset resource="../gui/opentrack-res.qrc"> <normaloff>:/images/facetracknoir.png</normaloff>:/images/facetracknoir.png</iconset> </property> <property name="layoutDirection"> @@ -26,222 +26,176 @@ <property name="autoFillBackground"> <bool>false</bool> </property> - <layout class="QVBoxLayout" name="_vertical_layout"> - <item> - <layout class="QGridLayout" name="gridLayout"> - <item row="1" column="4"> - <widget class="QSpinBox" name="spinIPFourthNibble"> - <property name="maximumSize"> - <size> - <width>60</width> - <height>16777215</height> - </size> - </property> - <property name="maximum"> - <number>255</number> - </property> - <property name="singleStep"> - <number>1</number> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QSpinBox" name="spinIPFirstNibble"> - <property name="maximumSize"> - <size> - <width>60</width> - <height>16777215</height> - </size> - </property> - <property name="maximum"> - <number>255</number> - </property> - <property name="singleStep"> - <number>1</number> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="QSpinBox" name="spinIPSecondNibble"> - <property name="maximumSize"> - <size> - <width>60</width> - <height>16777215</height> - </size> - </property> - <property name="maximum"> - <number>255</number> - </property> - <property name="singleStep"> - <number>1</number> - </property> - </widget> - </item> - <item row="1" column="3"> - <widget class="QSpinBox" name="spinIPThirdNibble"> - <property name="maximumSize"> - <size> - <width>60</width> - <height>16777215</height> - </size> - </property> - <property name="maximum"> - <number>255</number> - </property> - <property name="singleStep"> - <number>1</number> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string>IP-address remote PC</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_5"> - <property name="text"> - <string>Port-number</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QSpinBox" name="spinPortNumber"> - <property name="minimum"> - <number>1000</number> - </property> - <property name="maximum"> - <number>10000</number> - </property> - </widget> - </item> - </layout> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="1" column="0"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> </property> - </spacer> - </item> - <item> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Enter IP-address and port-number for the remote PC.</string> - </property> - <property name="wordWrap"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Remember: you may have to change firewall-settings too!</string> - </property> - </widget> - </item> - </layout> + </widget> </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <spacer name="horizontalSpacer_2"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <property name="sizeConstraint"> - <enum>QLayout::SetDefaultConstraint</enum> - </property> - <item> - <widget class="QPushButton" name="btnOK"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>100</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>100</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string>OK</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="btnCancel"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> + <item row="0" column="0"> + <widget class="QFrame" name="frame"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <layout class="QGridLayout" name="gridLayout"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="horizontalSpacing"> + <number>22</number> + </property> + <item row="0" column="1"> + <widget class="QFrame" name="frame_2"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="spacing"> + <number>12</number> </property> - <property name="minimumSize"> - <size> - <width>100</width> - <height>0</height> - </size> + <property name="leftMargin"> + <number>0</number> </property> - <property name="maximumSize"> - <size> - <width>100</width> - <height>16777215</height> - </size> + <property name="topMargin"> + <number>0</number> </property> - <property name="text"> - <string>Cancel</string> + <property name="bottomMargin"> + <number>0</number> </property> - </widget> - </item> - </layout> - </item> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>10</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> + <item> + <widget class="QSpinBox" name="spinIPFirstNibble"> + <property name="maximumSize"> + <size> + <width>60</width> + <height>16777215</height> + </size> + </property> + <property name="maximum"> + <number>255</number> + </property> + <property name="singleStep"> + <number>1</number> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="spinIPSecondNibble"> + <property name="maximumSize"> + <size> + <width>60</width> + <height>16777215</height> + </size> + </property> + <property name="maximum"> + <number>255</number> + </property> + <property name="singleStep"> + <number>1</number> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="spinIPThirdNibble"> + <property name="maximumSize"> + <size> + <width>60</width> + <height>16777215</height> + </size> + </property> + <property name="maximum"> + <number>255</number> + </property> + <property name="singleStep"> + <number>1</number> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="spinIPFourthNibble"> + <property name="maximumSize"> + <size> + <width>60</width> + <height>16777215</height> + </size> + </property> + <property name="maximum"> + <number>255</number> + </property> + <property name="singleStep"> + <number>1</number> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="1" column="1"> + <widget class="QSpinBox" name="spinPortNumber"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimum"> + <number>1024</number> + </property> + <property name="maximum"> + <number>65535</number> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label_4"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Remote IP address</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_5"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Port</string> + </property> + </widget> + </item> + </layout> + </widget> </item> </layout> </widget> @@ -251,13 +205,28 @@ <tabstop>spinIPThirdNibble</tabstop> <tabstop>spinIPFourthNibble</tabstop> <tabstop>spinPortNumber</tabstop> - <tabstop>btnOK</tabstop> - <tabstop>btnCancel</tabstop> </tabstops> <resources> - <include location="../gui/main-facetracknoir.qrc"/> + <include location="../gui/opentrack-res.qrc"/> </resources> <connections/> + <designerdata> + <property name="gridDeltaX"> + <number>5</number> + </property> + <property name="gridDeltaY"> + <number>5</number> + </property> + <property name="gridSnapX"> + <bool>true</bool> + </property> + <property name="gridSnapY"> + <bool>true</bool> + </property> + <property name="gridVisible"> + <bool>false</bool> + </property> + </designerdata> <slots> <slot>startEngineClicked()</slot> <slot>stopEngineClicked()</slot> diff --git a/proto-udp/ftnoir_protocol_ftn.cpp b/proto-udp/ftnoir_protocol_ftn.cpp index b659e3b5..a1f445f0 100644 --- a/proto-udp/ftnoir_protocol_ftn.cpp +++ b/proto-udp/ftnoir_protocol_ftn.cpp @@ -14,21 +14,29 @@ udp::udp() { + set_dest_address(); + QObject::connect(s.b.get(), &bundle_::changed, this, &udp::set_dest_address); } void udp::pose(const double *headpose) { - int destPort = s.port; - QHostAddress destIP(QString("%1.%2.%3.%4").arg( - QString::number(static_cast<int>(s.ip1)), - QString::number(static_cast<int>(s.ip2)), - QString::number(static_cast<int>(s.ip3)), - QString::number(static_cast<int>(s.ip4)))); - outSocket.writeDatagram((const char *) headpose, sizeof( double[6] ), destIP, destPort); + outSocket.writeDatagram((const char *) headpose, sizeof(double[6]), dest_ip, dest_port); } -bool udp::correct() -{ - return outSocket.bind(QHostAddress::Any, 0, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint); +void udp::set_dest_address() +{ + dest_port = s.port; + dest_ip = QHostAddress((s.ip1.to<unsigned>() & 0xff) << 24 | + (s.ip2.to<unsigned>() & 0xff) << 16 | + (s.ip3.to<unsigned>() & 0xff) << 8 | + (s.ip4.to<unsigned>() & 0xff) << 0 ); +} + +module_status udp::check_status() +{ + if (outSocket.bind(QHostAddress::Any, 0, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint)) + return status_ok(); + else + return error(tr("Can't bind socket: %1").arg(outSocket.errorString())); } OPENTRACK_DECLARE_PROTOCOL(udp, FTNControls, udpDll) diff --git a/proto-udp/ftnoir_protocol_ftn.h b/proto-udp/ftnoir_protocol_ftn.h index b234cd89..7838f01a 100644 --- a/proto-udp/ftnoir_protocol_ftn.h +++ b/proto-udp/ftnoir_protocol_ftn.h @@ -31,11 +31,13 @@ struct settings : opts { {} }; -class udp : public IProtocol +class udp : public QObject, public IProtocol { + Q_OBJECT + public: udp(); - bool correct(); + module_status check_status() override; void pose(const double *headpose); QString game_name() { return QCoreApplication::translate("udp_proto", "UDP over network"); @@ -43,12 +45,19 @@ public: private: QUdpSocket outSocket; settings s; + + QHostAddress dest_ip { 127u << 24 | 1u }; + unsigned short dest_port = 65535; + +private slots: + void set_dest_address(); }; // Widget that has controls for FTNoIR protocol client-settings. class FTNControls: public IProtocolDialog { Q_OBJECT + public: FTNControls(); void register_protocol(IProtocol *) {} diff --git a/proto-udp/ftnoir_protocol_ftn_dialog.cpp b/proto-udp/ftnoir_protocol_ftn_dialog.cpp index 70416a69..51ce483c 100644 --- a/proto-udp/ftnoir_protocol_ftn_dialog.cpp +++ b/proto-udp/ftnoir_protocol_ftn_dialog.cpp @@ -21,8 +21,8 @@ FTNControls::FTNControls() tie_setting(s.ip4, ui.spinIPFourthNibble); tie_setting(s.port, ui.spinPortNumber); - connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK())); - connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel())); + connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &FTNControls::doOK); + connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &FTNControls::doCancel); } // diff --git a/proto-vjoystick/vjoystick.cpp b/proto-vjoystick/vjoystick.cpp index 557b5e99..9ff64998 100644 --- a/proto-vjoystick/vjoystick.cpp +++ b/proto-vjoystick/vjoystick.cpp @@ -125,6 +125,21 @@ vjoystick_proto::~vjoystick_proto() { } +module_status vjoystick_proto::check_status() +{ + switch (h.get_state()) + { + case state_notent: + return error("vjoystick #1 doesn't exist"); + case state_fail: + return error("can't initialize vjoystick"); + case state_success: + return status_ok(); + default: + return error("unknown error"); + } +} + void vjoystick_proto::pose(const double *pose) { if (h.get_state() != state_success) diff --git a/proto-vjoystick/vjoystick.h b/proto-vjoystick/vjoystick.h index 49302030..0eac2ed2 100644 --- a/proto-vjoystick/vjoystick.h +++ b/proto-vjoystick/vjoystick.h @@ -53,7 +53,7 @@ class vjoystick_proto : public IProtocol public: vjoystick_proto(); ~vjoystick_proto() override; - bool correct() override { return h.get_state() == state_success; } + module_status check_status() override; void pose( const double *headpose ) override; QString game_name() override { return "Virtual joystick"; } private: diff --git a/proto-wine/ftnoir_protocol_wine.cpp b/proto-wine/ftnoir_protocol_wine.cpp index b1b8ecef..36c01c25 100644 --- a/proto-wine/ftnoir_protocol_wine.cpp +++ b/proto-wine/ftnoir_protocol_wine.cpp @@ -54,9 +54,12 @@ void wine::pose( const double *headpose ) } } -bool wine::correct() +module_status wine::check_status() { - return lck_shm.success(); + if (lck_shm.success()) + return status_ok(); + else + return error(QCoreApplication::translate("wine", "Can't open shared memory mapping")); } OPENTRACK_DECLARE_PROTOCOL(wine, FTControls, wineDll) diff --git a/proto-wine/ftnoir_protocol_wine.h b/proto-wine/ftnoir_protocol_wine.h index e996a2c2..d435ffb6 100644 --- a/proto-wine/ftnoir_protocol_wine.h +++ b/proto-wine/ftnoir_protocol_wine.h @@ -18,9 +18,11 @@ public: wine(); ~wine() override; - bool correct() override; + module_status check_status() override; void pose(const double* headpose) override; - QString game_name() override { + + QString game_name() override + { QMutexLocker foo(&game_name_mutex); return connected_game; } diff --git a/tracker-aruco/ftnoir_tracker_aruco.cpp b/tracker-aruco/ftnoir_tracker_aruco.cpp index 37e34246..a1bde523 100644 --- a/tracker-aruco/ftnoir_tracker_aruco.cpp +++ b/tracker-aruco/ftnoir_tracker_aruco.cpp @@ -73,7 +73,7 @@ aruco_tracker::~aruco_tracker() camera.release(); } -void aruco_tracker::start_tracker(QFrame* videoframe) +module_status aruco_tracker::start_tracker(QFrame* videoframe) { videoframe->show(); videoWidget = std::make_unique<cv_video_widget>(videoframe); @@ -83,6 +83,8 @@ void aruco_tracker::start_tracker(QFrame* videoframe) videoframe->setLayout(layout.get()); videoWidget->show(); start(); + + return status_ok(); } void aruco_tracker::getRT(cv::Matx33d& r_, cv::Vec3d& t_) diff --git a/tracker-aruco/ftnoir_tracker_aruco.h b/tracker-aruco/ftnoir_tracker_aruco.h index fd42d722..72f52eb8 100644 --- a/tracker-aruco/ftnoir_tracker_aruco.h +++ b/tracker-aruco/ftnoir_tracker_aruco.h @@ -65,7 +65,7 @@ struct settings : opts { class aruco_dialog; -class aruco_tracker : protected QThread, public ITracker +class aruco_tracker : protected virtual QThread, public ITracker { Q_OBJECT friend class aruco_dialog; @@ -73,7 +73,7 @@ class aruco_tracker : protected QThread, public ITracker public: aruco_tracker(); ~aruco_tracker() override; - void start_tracker(QFrame* frame) override; + module_status start_tracker(QFrame* frame) override; void data(double *data) override; void run() override; void getRT(cv::Matx33d &r, cv::Vec3d &t); diff --git a/tracker-freepie-udp/ftnoir_tracker_freepie-udp.cpp b/tracker-freepie-udp/ftnoir_tracker_freepie-udp.cpp index d24b938c..ab2b5b72 100644 --- a/tracker-freepie-udp/ftnoir_tracker_freepie-udp.cpp +++ b/tracker-freepie-udp/ftnoir_tracker_freepie-udp.cpp @@ -104,10 +104,12 @@ void tracker_freepie::run() { } } -void tracker_freepie::start_tracker(QFrame*) +module_status tracker_freepie::start_tracker(QFrame*) { start(); sock.moveToThread(this); + + return status_ok(); } void tracker_freepie::data(double *data) diff --git a/tracker-freepie-udp/ftnoir_tracker_freepie-udp.h b/tracker-freepie-udp/ftnoir_tracker_freepie-udp.h index 51a710f8..1b609470 100644 --- a/tracker-freepie-udp/ftnoir_tracker_freepie-udp.h +++ b/tracker-freepie-udp/ftnoir_tracker_freepie-udp.h @@ -33,7 +33,7 @@ class tracker_freepie : public ITracker, private QThread public: tracker_freepie(); ~tracker_freepie() override; - void start_tracker(QFrame *) override; + module_status start_tracker(QFrame *) override; void data(double *data) override; protected: void run() override; diff --git a/tracker-fusion/fusion.cpp b/tracker-fusion/fusion.cpp index 07f6483f..0b81b682 100644 --- a/tracker-fusion/fusion.cpp +++ b/tracker-fusion/fusion.cpp @@ -22,10 +22,7 @@ static auto get_modules() return Modules(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH); } -fusion_tracker::fusion_tracker() : - rot_tracker_data{}, - pos_tracker_data{}, - other_frame(new QFrame) +fusion_tracker::fusion_tracker() { } @@ -52,11 +49,14 @@ const QString& fusion_tracker::caption() return caption; } -void fusion_tracker::start_tracker(QFrame* frame) +module_status fusion_tracker::start_tracker(QFrame* frame) { assert(!rot_tracker && !pos_tracker); assert(!rot_dylib && !pos_dylib); + QString err; + module_status status; + fusion_settings s; const QString rot_tracker_name = s.rot_tracker_name().toString(); const QString pos_tracker_name = s.pos_tracker_name().toString(); @@ -65,14 +65,15 @@ void fusion_tracker::start_tracker(QFrame* frame) assert(pos_tracker_name != own_name); if (rot_tracker_name.isEmpty() || pos_tracker_name.isEmpty()) - goto fail; + { + err = tr("Trackers not selected."); + goto end; + } if (rot_tracker_name == pos_tracker_name) { - QMessageBox::warning(nullptr, caption(), - tr("Select different trackers for rotation and position."), - QMessageBox::Close); - goto cleanup; + err = tr("Select different trackers for rotation and position."); + goto end; } { @@ -95,17 +96,28 @@ void fusion_tracker::start_tracker(QFrame* frame) } if (!rot_dylib || !pos_dylib) - goto fail; + goto end; rot_tracker = make_dylib_instance<ITracker>(rot_dylib); pos_tracker = make_dylib_instance<ITracker>(pos_dylib); - pos_tracker->start_tracker(frame); + status = pos_tracker->start_tracker(frame); + + if (!status.is_ok()) + { + err = pos_dylib->name + QStringLiteral(":\n ") + status.error; + goto end; + } if (frame->layout() == nullptr) { - rot_tracker->start_tracker(frame); + status = rot_tracker->start_tracker(frame); other_frame = nullptr; + if (!status.is_ok()) + { + err = rot_dylib->name + QStringLiteral(":\n ") + status.error; + goto end; + } } else { @@ -121,14 +133,11 @@ void fusion_tracker::start_tracker(QFrame* frame) } - return; - -fail: - QMessageBox::warning(nullptr, - caption(), tr("Select rotation and position trackers."), - QMessageBox::Close); -cleanup: - other_frame = nullptr; +end: + if (!err.isEmpty()) + return error(err); + else + return status_ok(); } void fusion_tracker::data(double *data) @@ -203,4 +212,4 @@ fusion_settings::fusion_settings() : { } -OPENTRACK_DECLARE_TRACKER(fusion_tracker, fusion_dialog, fusion_metadata)
\ No newline at end of file +OPENTRACK_DECLARE_TRACKER(fusion_tracker, fusion_dialog, fusion_metadata) diff --git a/tracker-fusion/fusion.h b/tracker-fusion/fusion.h index 28e584da..96a1a496 100644 --- a/tracker-fusion/fusion.h +++ b/tracker-fusion/fusion.h @@ -19,7 +19,7 @@ class fusion_tracker : public QObject, public ITracker { Q_OBJECT - double rot_tracker_data[6], pos_tracker_data[6]; + double rot_tracker_data[6] {}, pos_tracker_data[6] {}; std::unique_ptr<QFrame> other_frame; std::shared_ptr<dylib> rot_dylib, pos_dylib; @@ -28,7 +28,7 @@ class fusion_tracker : public QObject, public ITracker public: fusion_tracker(); ~fusion_tracker() override; - void start_tracker(QFrame*) override; + module_status start_tracker(QFrame*) override; void data(double* data) override; static const QString& caption(); diff --git a/tracker-hatire/ftnoir_tracker_hat.cpp b/tracker-hatire/ftnoir_tracker_hat.cpp index 6e1b6586..29381eaa 100644 --- a/tracker-hatire/ftnoir_tracker_hat.cpp +++ b/tracker-hatire/ftnoir_tracker_hat.cpp @@ -43,27 +43,27 @@ void hatire::get_info( int *tps ) *tps=frame_cnt; frame_cnt=0; } -void hatire::start_tracker(QFrame*) +module_status hatire::start_tracker(QFrame*) { - CptError=0; - frame_cnt=0; + CptError=0; + frame_cnt=0; t.Log("Starting Tracker"); serial_result ret = t.init_serial_port(); + t.start(); + switch (ret.code) { case result_ok: - break; + return status_ok(); case result_error: - QMessageBox::warning(0, tr("Error"), ret.error, QMessageBox::Ok,QMessageBox::NoButton); - break; + return error(ret.error); case result_open_error: - QMessageBox::warning(0, tr("Error"), tr("Unable to open ComPort: %1").arg(ret.error), QMessageBox::Ok,QMessageBox::NoButton); - break; + return error(tr("Unable to open ComPort: %1").arg(ret.error)); + default: + return error("Unknown error"); } - - t.start(); } void hatire::serial_info() diff --git a/tracker-hatire/ftnoir_tracker_hat.h b/tracker-hatire/ftnoir_tracker_hat.h index fa8b8448..45b3f250 100644 --- a/tracker-hatire/ftnoir_tracker_hat.h +++ b/tracker-hatire/ftnoir_tracker_hat.h @@ -22,7 +22,7 @@ public: hatire(); ~hatire(); - void start_tracker(QFrame*); + module_status start_tracker(QFrame*); void data(double *data); //void center(); //bool notifyZeroed(); diff --git a/tracker-hydra/ftnoir_tracker_hydra.cpp b/tracker-hydra/ftnoir_tracker_hydra.cpp index d1e2fb36..69bb71e9 100644 --- a/tracker-hydra/ftnoir_tracker_hydra.cpp +++ b/tracker-hydra/ftnoir_tracker_hydra.cpp @@ -33,9 +33,11 @@ Hydra_Tracker::~Hydra_Tracker() sixenseExit(); } -void Hydra_Tracker::start_tracker(QFrame*) +module_status Hydra_Tracker::start_tracker(QFrame*) { sixenseInit(); + + return status_ok(); } void Hydra_Tracker::data(double *data) diff --git a/tracker-hydra/ftnoir_tracker_hydra.h b/tracker-hydra/ftnoir_tracker_hydra.h index 15016e4e..f6b9a099 100644 --- a/tracker-hydra/ftnoir_tracker_hydra.h +++ b/tracker-hydra/ftnoir_tracker_hydra.h @@ -16,8 +16,9 @@ class Hydra_Tracker : public ITracker public: Hydra_Tracker(); ~Hydra_Tracker(); - void start_tracker(QFrame *) override; + module_status start_tracker(QFrame *) override; void data(double *data) override; + private: settings s; QMutex mutex; diff --git a/tracker-joystick/ftnoir_tracker_joystick.cpp b/tracker-joystick/ftnoir_tracker_joystick.cpp index 498b4e42..42c2214a 100644 --- a/tracker-joystick/ftnoir_tracker_joystick.cpp +++ b/tracker-joystick/ftnoir_tracker_joystick.cpp @@ -26,10 +26,6 @@ joystick::~joystick() { } -void joystick::start_tracker(QFrame*) -{ -} - void joystick::data(double *data) { int map[6] = { diff --git a/tracker-joystick/ftnoir_tracker_joystick.h b/tracker-joystick/ftnoir_tracker_joystick.h index aea45983..bba4ad3e 100644 --- a/tracker-joystick/ftnoir_tracker_joystick.h +++ b/tracker-joystick/ftnoir_tracker_joystick.h @@ -41,7 +41,7 @@ class joystick : public ITracker public: joystick(); ~joystick(); - void start_tracker(QFrame *); + module_status start_tracker(QFrame *) { return status_ok(); } void data(double *data); settings s; QString guid; diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp index ac514813..5975f701 100644 --- a/tracker-pt/ftnoir_tracker_pt.cpp +++ b/tracker-pt/ftnoir_tracker_pt.cpp @@ -153,7 +153,7 @@ void Tracker_PT::set_fov(int value) camera.set_fov(value); } -void Tracker_PT::start_tracker(QFrame* video_frame) +module_status Tracker_PT::start_tracker(QFrame* video_frame) { //video_frame->setAttribute(Qt::WA_NativeWindow); preview_size = video_frame->size(); @@ -172,6 +172,8 @@ void Tracker_PT::start_tracker(QFrame* video_frame) maybe_reopen_camera(); start(QThread::HighPriority); + + return status_ok(); } void Tracker_PT::data(double *data) diff --git a/tracker-pt/ftnoir_tracker_pt.h b/tracker-pt/ftnoir_tracker_pt.h index 6c2923c0..ad7f56ff 100644 --- a/tracker-pt/ftnoir_tracker_pt.h +++ b/tracker-pt/ftnoir_tracker_pt.h @@ -40,12 +40,13 @@ using namespace types; class Tracker_PT : public QThread, public ITracker { Q_OBJECT + friend class camera_dialog; friend class ::TrackerDialog_PT; public: Tracker_PT(); ~Tracker_PT() override; - void start_tracker(QFrame* parent_window) override; + module_status start_tracker(QFrame* parent_window) override; void data(double* data) override; Affine pose(); diff --git a/tracker-pt/ftnoir_tracker_pt_dialog.cpp b/tracker-pt/ftnoir_tracker_pt_dialog.cpp index 0746a85e..2c3cbd07 100644 --- a/tracker-pt/ftnoir_tracker_pt_dialog.cpp +++ b/tracker-pt/ftnoir_tracker_pt_dialog.cpp @@ -63,7 +63,7 @@ TrackerDialog_PT::TrackerDialog_PT() tie_setting(s.auto_threshold, ui.auto_threshold); - connect( ui.tcalib_button,SIGNAL(toggled(bool)), this,SLOT(startstop_trans_calib(bool))); + connect(ui.tcalib_button,SIGNAL(toggled(bool)), this, SLOT(startstop_trans_calib(bool))); connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); diff --git a/tracker-rift-025/ftnoir_tracker_rift_025.cpp b/tracker-rift-025/ftnoir_tracker_rift_025.cpp index 92ae36ea..8d4a6e8a 100644 --- a/tracker-rift-025/ftnoir_tracker_rift_025.cpp +++ b/tracker-rift-025/ftnoir_tracker_rift_025.cpp @@ -41,8 +41,10 @@ rift_tracker_025::~rift_tracker_025() System::Destroy(); } -void rift_tracker_025::start_tracker(QFrame*) +module_status rift_tracker_025::start_tracker(QFrame*) { + QString err; + System::Init(Log::ConfigureDefaultLog(LogMask_All)); pManager = DeviceManager::Create(); if (pManager != NULL) @@ -59,29 +61,19 @@ void rift_tracker_025::start_tracker(QFrame*) pSFusion->AttachToSensor(pSensor); } else - { - QMessageBox::warning(nullptr, - QCoreApplication::translate("rift_tracker_025", "Error"), - QCoreApplication::translate("rift_tracker_025", "Unable to create Rift sensor"), - QMessageBox::Ok,QMessageBox::NoButton); - } + err = tr("Unable to create Rift sensor"); } else - { - QMessageBox::warning(nullptr, - QCoreApplication::translate("rift_tracker_025", "Error"), - QCoreApplication::translate("rift_tracker_025", "Unable to enumerate Rift tracker"), - QMessageBox::Ok,QMessageBox::NoButton); - } + err = tr("Unable to enumerate Rift tracker"); } else - { - QMessageBox::warning(nullptr, - QCoreApplication::translate("rift_tracker_025", "Error"), - QCoreApplication::translate("rift_tracker_025", "Unable to start Rift tracker"), - QMessageBox::Ok,QMessageBox::NoButton); - } + err = tr("Unable to start Rift tracker"); + + if (err.isEmpty()) + return status_ok(); + else + return error(err); } diff --git a/tracker-rift-025/ftnoir_tracker_rift_025.h b/tracker-rift-025/ftnoir_tracker_rift_025.h index b65d3e56..37ffcdaa 100644 --- a/tracker-rift-025/ftnoir_tracker_rift_025.h +++ b/tracker-rift-025/ftnoir_tracker_rift_025.h @@ -21,12 +21,14 @@ struct settings : opts { {} }; -class rift_tracker_025 : public ITracker +class rift_tracker_025 : public QObject, public ITracker { + Q_OBJECT + public: rift_tracker_025(); virtual ~rift_tracker_025() override; - void start_tracker(QFrame *) override; + module_status start_tracker(QFrame *) override; void data(double *data) override; private: double old_yaw; diff --git a/tracker-rift-042/ftnoir_tracker_rift_042.cpp b/tracker-rift-042/ftnoir_tracker_rift_042.cpp index 0e52812d..c8ced38f 100644 --- a/tracker-rift-042/ftnoir_tracker_rift_042.cpp +++ b/tracker-rift-042/ftnoir_tracker_rift_042.cpp @@ -36,22 +36,17 @@ rift_tracker_042::~rift_tracker_042() ovr_Shutdown(); } -void rift_tracker_042::start_tracker(QFrame*) +module_status rift_tracker_042::start_tracker(QFrame*) { ovr_Initialize(); hmd = ovrHmd_Create(0); if (hmd) { ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, ovrTrackingCap_Orientation); + return status_ok(); } else - { - QMessageBox::warning(nullptr, - "Error", - QCoreApplication::translate("rift_tracker_042", "Unable to start Rift tracker: %1").arg(ovrHmd_GetLastError(nullptr)), - QMessageBox::Ok, - QMessageBox::NoButton); - } + return error(tr("Unable to start Rift tracker: %1").arg(ovrHmd_GetLastError(nullptr))); } diff --git a/tracker-rift-042/ftnoir_tracker_rift_042.h b/tracker-rift-042/ftnoir_tracker_rift_042.h index 82081085..630878b9 100644 --- a/tracker-rift-042/ftnoir_tracker_rift_042.h +++ b/tracker-rift-042/ftnoir_tracker_rift_042.h @@ -21,12 +21,14 @@ struct settings : opts { {} }; -class rift_tracker_042 : public ITracker +class rift_tracker_042 : public QObject, public ITracker { + Q_OBJECT + public: rift_tracker_042(); virtual ~rift_tracker_042() override; - void start_tracker(QFrame *) override; + module_status start_tracker(QFrame *) override; void data(double *data) override; private: double old_yaw; diff --git a/tracker-rift-080/ftnoir_tracker_rift_080.cpp b/tracker-rift-080/ftnoir_tracker_rift_080.cpp index 00f3d5b3..4d351dbc 100644 --- a/tracker-rift-080/ftnoir_tracker_rift_080.cpp +++ b/tracker-rift-080/ftnoir_tracker_rift_080.cpp @@ -35,7 +35,7 @@ rift_tracker_080::~rift_tracker_080() ovr_Shutdown(); } -void rift_tracker_080::start_tracker(QFrame*) +module_status rift_tracker_080::start_tracker(QFrame*) { ovrResult code; ovrGraphicsLuid luid = {{0}}; @@ -52,7 +52,7 @@ void rift_tracker_080::start_tracker(QFrame*) ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, ovrTrackingCap_Orientation); - return; + return status_ok(); error: ovrErrorInfo err; err.Result = code; @@ -63,11 +63,7 @@ error: if (strerror.size() == 0) strerror = "Unknown reason"; - QMessageBox::warning(nullptr, - "Error", - QStringLiteral("Unable to start Rift tracker: %1").arg(strerror), - QMessageBox::Ok, - QMessageBox::NoButton); + return error(strerror); } void rift_tracker_080::data(double *data) diff --git a/tracker-rift-080/ftnoir_tracker_rift_080.h b/tracker-rift-080/ftnoir_tracker_rift_080.h index e5ad9c3a..e7fccb5e 100644 --- a/tracker-rift-080/ftnoir_tracker_rift_080.h +++ b/tracker-rift-080/ftnoir_tracker_rift_080.h @@ -25,7 +25,7 @@ class rift_tracker_080 : public ITracker public: rift_tracker_080(); ~rift_tracker_080() override; - void start_tracker(QFrame *) override; + module_status start_tracker(QFrame *) override; void data(double *data) override; private: double old_yaw; diff --git a/tracker-rift-140/rift-140.cpp b/tracker-rift-140/rift-140.cpp index ebcc7654..9880cb1e 100644 --- a/tracker-rift-140/rift-140.cpp +++ b/tracker-rift-140/rift-140.cpp @@ -35,7 +35,7 @@ rift_tracker_140::~rift_tracker_140() } } -void rift_tracker_140::start_tracker(QFrame*) +module_status rift_tracker_140::start_tracker(QFrame*) { if (OVR_FAILURE(ovr_Initialize(nullptr))) goto error; @@ -43,7 +43,7 @@ void rift_tracker_140::start_tracker(QFrame*) if(OVR_FAILURE(ovr_Create(&hmd, &luid))) goto error; - return; + return status_ok(); error: hmd = nullptr; @@ -56,11 +56,7 @@ error: ovr_Shutdown(); - QMessageBox::warning(nullptr, - "Error", - QCoreApplication::translate("rift_tracker_140", "Unable to start Rift tracker: %1").arg(strerror), - QMessageBox::Ok, - QMessageBox::NoButton); + return error(strerror); } void rift_tracker_140::data(double *data) diff --git a/tracker-rift-140/rift-140.hpp b/tracker-rift-140/rift-140.hpp index 47eb7cd2..13bebed4 100644 --- a/tracker-rift-140/rift-140.hpp +++ b/tracker-rift-140/rift-140.hpp @@ -25,7 +25,7 @@ class rift_tracker_140 : public ITracker public: rift_tracker_140(); ~rift_tracker_140() override; - void start_tracker(QFrame *) override; + module_status start_tracker(QFrame *) override; void data(double *data) override; private: double old_yaw; diff --git a/tracker-rs/ftnoir_tracker_rs.cpp b/tracker-rs/ftnoir_tracker_rs.cpp index 89659086..ebcdac33 100644 --- a/tracker-rs/ftnoir_tracker_rs.cpp +++ b/tracker-rs/ftnoir_tracker_rs.cpp @@ -44,7 +44,7 @@ void RSTracker::configurePreviewFrame() mImageWidget->show(); } -void RSTracker::start_tracker(QFrame* previewFrame) +module_status RSTracker::start_tracker(QFrame* previewFrame) { qDebug() << "tracker_rs: starting tracker"; @@ -55,6 +55,8 @@ void RSTracker::start_tracker(QFrame* previewFrame) startPreview(); mTrackerWorkerThread.start(QThread::HighPriority); + + return status_ok(); } void RSTracker::startPreview(){ diff --git a/tracker-rs/ftnoir_tracker_rs.h b/tracker-rs/ftnoir_tracker_rs.h index 083794ed..bcf787a0 100644 --- a/tracker-rs/ftnoir_tracker_rs.h +++ b/tracker-rs/ftnoir_tracker_rs.h @@ -21,7 +21,7 @@ class RSTracker : public QObject, public ITracker public: RSTracker(); ~RSTracker(); - void start_tracker(QFrame *) override; + module_status start_tracker(QFrame *) override; void data(double *data) override; public slots: diff --git a/tracker-s2bot/ftnoir_tracker_s2bot.cpp b/tracker-s2bot/ftnoir_tracker_s2bot.cpp index 6621e605..8bd1f5db 100644 --- a/tracker-s2bot/ftnoir_tracker_s2bot.cpp +++ b/tracker-s2bot/ftnoir_tracker_s2bot.cpp @@ -85,11 +85,13 @@ void tracker_s2bot::run() { timer.stop(); } -void tracker_s2bot::start_tracker(QFrame*) +module_status tracker_s2bot::start_tracker(QFrame*) { start(); timer.moveToThread(this); m_nam->moveToThread(this); + + return status_ok(); } void tracker_s2bot::data(double *data) diff --git a/tracker-s2bot/ftnoir_tracker_s2bot.h b/tracker-s2bot/ftnoir_tracker_s2bot.h index d4d3fd2a..f0493284 100644 --- a/tracker-s2bot/ftnoir_tracker_s2bot.h +++ b/tracker-s2bot/ftnoir_tracker_s2bot.h @@ -30,12 +30,12 @@ struct settings : opts { {} }; -class tracker_s2bot : public ITracker, private QThread +class tracker_s2bot : public ITracker, private virtual QThread { public: tracker_s2bot(); ~tracker_s2bot() override; - void start_tracker(QFrame *) override; + module_status start_tracker(QFrame *) override; void data(double *data) override; protected: void run() override; diff --git a/tracker-steamvr/steamvr.cpp b/tracker-steamvr/steamvr.cpp index d250197b..82a38fb7 100644 --- a/tracker-steamvr/steamvr.cpp +++ b/tracker-steamvr/steamvr.cpp @@ -183,16 +183,16 @@ steamvr::~steamvr() { } -void steamvr::start_tracker(QFrame*) +module_status steamvr::start_tracker(QFrame*) { - with_vr_lock([this](vr_t v, error_t e) + return with_vr_lock([this](vr_t v, error_t e) { + QString err; + if (!v) { - QMessageBox::warning(nullptr, - tr("SteamVR init error"), device_list::strerror(e), - QMessageBox::Close, QMessageBox::NoButton); - return; + err = device_list::strerror(e); + return error(err); } const QString serial = s.device_serial().toString(); @@ -201,13 +201,7 @@ void steamvr::start_tracker(QFrame*) const int sz = specs.count(); if (sz == 0) - { - QMessageBox::warning(nullptr, - tr("SteamVR init error"), - tr("No HMD connected"), - QMessageBox::Close, QMessageBox::NoButton); - return; - } + err = tr("No HMD connected"); device_index = -1; @@ -220,13 +214,13 @@ void steamvr::start_tracker(QFrame*) } } - if (device_index == -1) - { - QMessageBox::warning(nullptr, - tr("SteamVR init error"), - tr("Can't find device with that serial"), - QMessageBox::Close, QMessageBox::NoButton); - } + if (device_index == -1 && err.isEmpty()) + err = tr("Can't find device with that serial"); + + if (err.isEmpty()) + return status_ok(); + else + return error(err); }); } diff --git a/tracker-steamvr/steamvr.hpp b/tracker-steamvr/steamvr.hpp index 0592dec9..c8712b20 100644 --- a/tracker-steamvr/steamvr.hpp +++ b/tracker-steamvr/steamvr.hpp @@ -76,7 +76,7 @@ class steamvr : public QObject, public ITracker public: steamvr(); ~steamvr() override; - void start_tracker(QFrame *) override; + module_status start_tracker(QFrame *) override; void data(double *data) override; bool center() override; diff --git a/tracker-test/test.cpp b/tracker-test/test.cpp index c662051e..d37d7373 100644 --- a/tracker-test/test.cpp +++ b/tracker-test/test.cpp @@ -30,9 +30,11 @@ test_tracker::~test_tracker() { } -void test_tracker::start_tracker(QFrame*) +module_status test_tracker::start_tracker(QFrame*) { t.start(); + + return status_ok(); } #ifdef EMIT_NAN diff --git a/tracker-test/test.h b/tracker-test/test.h index 01133617..1b432be2 100644 --- a/tracker-test/test.h +++ b/tracker-test/test.h @@ -10,7 +10,7 @@ class test_tracker : public ITracker public: test_tracker(); ~test_tracker() override; - void start_tracker(QFrame *) override; + module_status start_tracker(QFrame *) override; void data(double *data) override; private: diff --git a/tracker-tobii-eyex/tobii-eyex.cpp b/tracker-tobii-eyex/tobii-eyex.cpp index e35c849e..604931d6 100644 --- a/tracker-tobii-eyex/tobii-eyex.cpp +++ b/tracker-tobii-eyex/tobii-eyex.cpp @@ -217,10 +217,8 @@ void tobii_eyex_tracker::event_handler(TX_CONSTHANDLE async_data_handle, TX_USER txReleaseObject(&event_handle); } -void tobii_eyex_tracker::start_tracker(QFrame*) +module_status tobii_eyex_tracker::start_tracker(QFrame*) { - dbg_verbose("start tracker"); - bool status = true; status &= txInitializeEyeX(TX_EYEXCOMPONENTOVERRIDEFLAG_NONE, nullptr, nullptr, nullptr, nullptr) == TX_RESULT_OK; @@ -231,9 +229,9 @@ void tobii_eyex_tracker::start_tracker(QFrame*) status &= txEnableConnection(dev_ctx) == TX_RESULT_OK; if (!status) - dbg_verbose("connection can't be established. device missing?"); + return error(QCoreApplication::translate("tobii", "Connection can't be established. device missing?")); else - dbg_verbose("api initialized"); + return status_ok(); } tobii_eyex_tracker::num tobii_eyex_tracker::gain(num x) diff --git a/tracker-tobii-eyex/tobii-eyex.hpp b/tracker-tobii-eyex/tobii-eyex.hpp index a86a4a76..8583acf0 100644 --- a/tracker-tobii-eyex/tobii-eyex.hpp +++ b/tracker-tobii-eyex/tobii-eyex.hpp @@ -28,7 +28,7 @@ class tobii_eyex_tracker : public ITracker public: tobii_eyex_tracker(); ~tobii_eyex_tracker() override; - void start_tracker(QFrame *) override; + module_status start_tracker(QFrame *) override; void data(double *data) override; bool center() override { diff --git a/tracker-udp/ftnoir_tracker_udp.cpp b/tracker-udp/ftnoir_tracker_udp.cpp index b3df5e60..41aa96c2 100644 --- a/tracker-udp/ftnoir_tracker_udp.cpp +++ b/tracker-udp/ftnoir_tracker_udp.cpp @@ -29,9 +29,6 @@ void udp::run() QByteArray datagram; datagram.resize(sizeof(last_recv_pose)); - if (!sock.bind(QHostAddress::Any, quint16(s.port), QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint)) - return; - while (!isInterruptionRequested()) { if (sock.hasPendingDatagrams()) @@ -69,10 +66,15 @@ void udp::run() } } -void udp::start_tracker(QFrame*) +module_status udp::start_tracker(QFrame*) { - start(); + if (!sock.bind(QHostAddress::Any, quint16(s.port), QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint)) + return error(tr("Can't bind socket -- %1").arg(sock.errorString())); + sock.moveToThread(this); + start(); + + return status_ok(); } void udp::data(double *data) diff --git a/tracker-udp/ftnoir_tracker_udp.h b/tracker-udp/ftnoir_tracker_udp.h index 0167a005..8e8a385c 100644 --- a/tracker-udp/ftnoir_tracker_udp.h +++ b/tracker-udp/ftnoir_tracker_udp.h @@ -19,12 +19,12 @@ struct settings : opts { {} }; -class udp : public ITracker, protected QThread +class udp : protected QThread, public ITracker { public: udp(); ~udp() override; - void start_tracker(QFrame *) override; + module_status start_tracker(QFrame *) override; void data(double *data) override; protected: void run() override; |