diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-04-29 11:30:37 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-04-29 11:30:37 +0200 |
commit | 38dd6e55d20adfd830d834c394fc6ce7373a4805 (patch) | |
tree | 0a94bf051ff0bc153abebaa74e474748c2d4d8a6 /tracker-hatire/ftnoir_tracker_hat.h | |
parent | 4db6f6334d13ed5e8696dfa0208b42b3e9a2352a (diff) |
tracker/hatire: move io to a separate thread
We can't have async io on the main thread because QSerialPort's
readyRead() signal can fire constantly, thus consuming all CPU time.
We can't sleep in the main thread either as that blocks too many things.
We can't ignore readyRead() invocations over a threshold as that'll make
us lose some of data notifications.
Refactor hatire to put IO on a thread. Since this is a separate Qt event
loop, we may sleep in there.
Further, add a debug mode reading data from a file, as if it came from a
serial-attached device.
Issue: #327
Diffstat (limited to 'tracker-hatire/ftnoir_tracker_hat.h')
-rw-r--r-- | tracker-hatire/ftnoir_tracker_hat.h | 122 |
1 files changed, 22 insertions, 100 deletions
diff --git a/tracker-hatire/ftnoir_tracker_hat.h b/tracker-hatire/ftnoir_tracker_hat.h index 2472428b..4767d291 100644 --- a/tracker-hatire/ftnoir_tracker_hat.h +++ b/tracker-hatire/ftnoir_tracker_hat.h @@ -1,13 +1,10 @@ -#ifndef FTNOIR_TRACKER_HAT_H -#define FTNOIR_TRACKER_HAT_H +#pragma once -#ifdef OPENTRACK_API -# include "opentrack/plugin-support.hpp" -#else -# include "..\ftnoir_tracker_base\ftnoir_tracker_base.h" -#endif +#include "thread.hpp" +#include "opentrack/plugin-support.hpp" #include "ftnoir_tracker_hat_settings.h" #include "ftnoir_arduino_type.h" + #include <QObject> #include <QPalette> #include <QtGui> @@ -15,59 +12,42 @@ #include <QMessageBox> #include <QtSerialPort/QSerialPort> #include <QtSerialPort/QSerialPortInfo> -#include <QMutex> -#include <QMutexLocker> #include <QSettings> -#define VER_FILEVERSION_STR "Version 2.1.1\0" +#define VER_FILEVERSION_STR "Version 2.1.1" -class FTNoIR_Tracker : public QObject, public ITracker +class hatire : public QObject, public ITracker { Q_OBJECT + public: - FTNoIR_Tracker(); - ~FTNoIR_Tracker(); + hatire(); + ~hatire(); -#ifdef OPENTRACK_API void start_tracker(QFrame*); void data(double *data); - int preferredHz(); // unused - void center(); // unused -#else - void Initialize( QFrame *videoframe ); - void StartTracker(HWND parent_window); - void StopTracker(bool exit); - bool GiveHeadPoseData(THeadPoseData *data); - void notifyCenter(); -#endif + //void center(); void applysettings(const TrackerSettings& settings); - bool notifyZeroed(); + //bool notifyZeroed(); void reset(); - void SerialInfo(); - void sendcmd(const QByteArray &cmd); void get_info( int *tps ); - -private Q_SLOTS: - void SerialRead(); - void Log(QString message); - -signals: - void sendMsgInfo(const QByteArray &MsgInfo); - + void serial_info(); + void send_serial_command(const QByteArray& x); private: - QSerialPort *ComPort; - TArduinoData ArduinoData, HAT ; // Trame from Arduino - QByteArray dataRead; - QByteArray dataToSend; + TArduinoData ArduinoData, HAT; QByteArray Begin; QByteArray End; - QMutex mutex; - int frame_cnt; - bool new_frame; + hatire_thread t; + thread_settings ts; + + // XXX move to settings api -sh 20160410 TrackerSettings settings; + int frame_cnt; + bool new_frame; + bool bEnableRoll; bool bEnablePitch; bool bEnableYaw; @@ -81,7 +61,6 @@ private: bool bInvertX; bool bInvertY; bool bInvertZ; - bool bEnableLogging; int iRollAxe; int iPitchAxe; @@ -90,68 +69,11 @@ private: int iYAxe; int iZAxe; - QByteArray sCmdStart; - QByteArray sCmdStop; - QByteArray sCmdInit; - QByteArray sCmdReset; - QByteArray sCmdCenter; - QByteArray sCmdZero; - - int iDelayInit; - int iDelayStart; - int iDelaySeq; - - bool bBigEndian; - - QString sSerialPortName; - QSerialPort::BaudRate iBaudRate; - QSerialPort::DataBits iDataBits; - QSerialPort::Parity iParity; - QSerialPort::StopBits iStopBits; - QSerialPort::FlowControl iFlowControl; - - QFile flDiagnostics; -#ifdef OPENTRACK_API - int iFpsArduino; -#endif - int CptError; - - + volatile int CptError; }; - -//******************************************************************************************************* -// FaceTrackNoIR Tracker DLL. Functions used to get general info on the Tracker -//******************************************************************************************************* -#if defined(OPENTRACK_API) class TrackerDll : public Metadata { QString name() { return QString("Hatire Arduino"); } QIcon icon() { return QIcon(":/images/hat.png"); } }; -#else -class TrackerDll : -public Metadata -public ITrackerDll -{ -public: - TrackerDll(); - ~TrackerDll(); - - void Initialize(); - - QString name(); - QIcon icon(); - void getFullName(QString *strToBeFilled); - void getShortName(QString *strToBeFilled); - void getDescription(QString *strToBeFilled); - void getIcon(QIcon *icon); - -private: - QString trackerFullName; // Trackers' name and description - QString trackerShortName; - QString trackerDescription; -}; -#endif - -#endif // FTNOIR_TRACKER_HAT_H |