From 09aeee333b807be87f456fa226fc0442d5a37364 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 27 Nov 2013 02:32:24 +0100 Subject: make hatire actually buildable Remove 'captain obvious' comments, references to , fix spelling errors, use UI layouts, and so on Signed-off-by: Stanislaw Halik --- ftnoir_tracker_hatire/ftnoir_arduino_type.h | 21 +- ftnoir_tracker_hatire/ftnoir_hatcontrols.ui | 1675 +++++++++----------- ftnoir_tracker_hatire/ftnoir_tracker_hat.cpp | 251 +-- ftnoir_tracker_hatire/ftnoir_tracker_hat.h | 59 +- .../ftnoir_tracker_hat_dialog.cpp | 121 +- ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.h | 37 +- ftnoir_tracker_hatire/ftnoir_tracker_hat_dll.cpp | 57 +- .../ftnoir_tracker_hat_settings.cpp | 48 +- .../ftnoir_tracker_hat_settings.h | 16 +- 9 files changed, 887 insertions(+), 1398 deletions(-) diff --git a/ftnoir_tracker_hatire/ftnoir_arduino_type.h b/ftnoir_tracker_hatire/ftnoir_arduino_type.h index 4d19043b..7f550579 100644 --- a/ftnoir_tracker_hatire/ftnoir_arduino_type.h +++ b/ftnoir_tracker_hatire/ftnoir_arduino_type.h @@ -1,31 +1,30 @@ #ifndef FTNOIR_TARDUINO_TYPE_H #define FTNOIR_TARDUINO_TYPE_H -// Arduino trame structure +#include + +// Arduino frame structure #pragma pack(push,2) struct TArduinoData { quint16 Begin; // Header trame 0xAAAA; - quint16 Code; // 0->999 Num Trame >=2000 Info >=3000 Init >=5000 Start Command >=9000 Error + quint16 Code; // 0->999 Num Frame >=2000 Info >=3000 Init >=5000 Start Command >=9000 Error float Gyro[3]; float Acc[3]; - quint16 End; // End trame 0x5555; + quint16 End; // End frame 0x5555; } ; #pragma pack(pop) - inline QDataStream & operator >> ( QDataStream& in, TArduinoData& out ) { in.setByteOrder(QDataStream::LittleEndian ); in.setFloatingPointPrecision(QDataStream::SinglePrecision ); - in >> (quint16)out.Begin >> (quint16)out.Code - >> (float)out.Gyro[0] >> (float)out.Gyro[1] >> (float)out.Gyro[2] - >> (float)out.Acc[0] >> (float)out.Acc[1] >> (float)out.Acc[2] - >> (quint16)out.End; + in >> out.Begin >> out.Code + >> out.Gyro[0] >> out.Gyro[1] >> out.Gyro[2] + >> out.Acc[0] >> out.Acc[1] >> out.Acc[2] + >> out.End; return in; } - - -#endif \ No newline at end of file +#endif diff --git a/ftnoir_tracker_hatire/ftnoir_hatcontrols.ui b/ftnoir_tracker_hatire/ftnoir_hatcontrols.ui index 86f9e48a..8882fffb 100644 --- a/ftnoir_tracker_hatire/ftnoir_hatcontrols.ui +++ b/ftnoir_tracker_hatire/ftnoir_hatcontrols.ui @@ -41,1015 +41,784 @@ false - - - - 0 - 480 - 361 - 27 - - - - - - - - 0 - 0 - - - - - 80 - 25 - - - - - 80 - 25 - - - - OK - - - - - - - - 80 - 25 - - - - - 80 - 25 - - - - Save - - - - - - - - 0 - 0 - - - - - 80 - 25 - - - - - 80 - 25 - - - - Cancel - - - - - - - - - 0 - 0 - 360 - 470 - - - - - 360 - 470 - - - - - 360 - 470 - - - - 0 - - - true - - - - - :/images/hat.ico:/images/hat.ico - - - General - - - - - 10 - 350 - 331 - 91 - - - - Information - - - - - 10 - 20 - 311 - 51 - - - - - QFormLayout::AllNonFixedFieldsGrow - - - 10 - - - 10 - - - 0 - - - 0 - - - 0 - - - - - - 31 - 0 - - - - - 60 - 13 - - - - Trame per seconde - - - tps : - - - - - - - - 60 - 16777215 - - - - Status : - - - - - - - - 170 - 0 - - - - - 60 - 16777215 - - - - - - - - - - - - 31 - 0 - - - - - 60 - 13 - - - - 00 - - - - - - - - - - 10 - 130 - 331 - 211 - - + + + - 0 - 106 + 360 + 470 - - Axis Configuration + + + 360 + 470 + - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + 1 - - - - 10 - 20 - 311 - 181 - - - - - QLayout::SetMinAndMaxSize - - - 0 - - - 0 - - - 6 - - - - - - 20 - 16777215 - - - - Enable Axis - - - Qt::LeftToRight - - - - - - - - - - - 20 - 16777215 - - - - Enable Axis - - - Qt::LeftToRight - - - - - - - - - - - - - Associate Axis - - - - RotX - - - - - RotY - - - - - RotZ - - - - - - - - Yaw: - - - - - - - Associate Axis - - - - RotX - - - - - RotY - - - - - RotZ - - - - - - - - Associate Axis - - - - RotX - - - - - RotY - - - - - RotZ - - - - - - - - - 20 - 16777215 - - - - Enable Axis - - - Qt::LeftToRight - - - - - - - - - - Pitch: - - - - - - - Roll: - - - - - - - - 20 - 16777215 - - - - Invert Axis - - - Qt::LeftToRight - - - - - - - - - - - - - - 20 - 16777215 - - - - Invert Axis - - - Qt::LeftToRight - - - - - - - - - - - - - - 20 - 16777215 - - - - Invert Axis - - - Qt::LeftToRight - - - - - + + true + + + + + :/images/hat.ico:/images/hat.ico + + + General + + + + + + + + + + + 80 + 20 + + + + Center + + + + + + + + 80 + 20 + + + + Reset + + + + + + + + 0 + 0 + + + + + 100 + 16777215 + + + + false + + + QComboBox::AdjustToMinimumContentsLength + + + 0 + + + + + + + Arduino serial port + + + true + + + + - - - - Enable - - - - - - - Axis - - - - - - - Invert - - - - - - - X: - - - - - - + + + - 20 - 16777215 + 0 + 106 - - Enable Axis - - - Qt::LeftToRight - - - - + + Axis selection + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + 20 + 16777215 + + + + Enable Axis + + + Qt::LeftToRight + + + + + + + + + + + 20 + 16777215 + + + + Invert Axis + + + Qt::LeftToRight + + + + + + + + + + + + + Associate Axis + + + + X + + + + + Y + + + + + Z + + + + + + + + + 20 + 16777215 + + + + Enable Axis + + + Qt::LeftToRight + + + + + + + + + + X + + + + + + + Pitch + + + + + + + Z + + + + + + + + 20 + 16777215 + + + + Invert Axis + + + Qt::LeftToRight + + + + + + + + + + + + + Associate Axis + + + + Yaw + + + + + Pitch + + + + + Roll + + + + + + + + + 20 + 16777215 + + + + Enable Axis + + + Qt::LeftToRight + + + + + + + + + + Associate Axis + + + + X + + + + + Y + + + + + Z + + + + + + + + + 20 + 16777215 + + + + Invert Axis + + + Qt::LeftToRight + + + + + + + + + + + + + + 20 + 16777215 + + + + Enable Axis + + + Qt::LeftToRight + + + + + + + + + + + 20 + 16777215 + + + + Invert Axis + + + Qt::LeftToRight + + + + + + + + + + + + + Associate Axis + + + + Yaw + + + + + Pitch + + + + + Roll + + + + + + + + + 20 + 16777215 + + + + Enable Axis + + + Qt::LeftToRight + + + + + + + + + + Input + + + + + + + Invert + + + + + + + Yaw + + + + + + + + 20 + 16777215 + + + + Enable Axis + + + Qt::LeftToRight + + + + + + + + + + + + + Associate Axis + + + + X + + + + + Y + + + + + Z + + + + + + + + Associate Axis + + + + Yaw + + + + + Pitch + + + + + Roll + + + + + + + + + 20 + 16777215 + + + + Invert Axis + + + Qt::LeftToRight + + + + + + + + + + + + + Y + + + + + + + + 20 + 16777215 + + + + Invert Axis + + + Qt::LeftToRight + + + + + + + + + + + + + Roll + + + + + + + Enable + + + + + + + Output + + + + - - - - Associate Axis - - - - X - - - - - Y - - - - - Z - - + + + + Information + + + + + + + 31 + 0 + + + + + 60 + 13 + + + + Trame per seconde + + + tps : + + + + + + + + 170 + 0 + + + + + 60 + 16777215 + + + + + + + + + + + + 31 + 0 + + + + + 60 + 13 + + + + 00 + + + + + + + + 60 + 16777215 + + + + Status : + + + + - - - - - 20 - 16777215 - - - - Invert Axis - - - Qt::LeftToRight - - - - + + + + + About + + + + - + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">FTNoIR HAT Plugin<br />Version 1.0</span></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">by FuraX49</span></p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://hatire.sourceforge.net/"><span style=" font-weight:600; text-decoration: underline; color:#0000ff;">Manual (external)</span></a></p></body></html> - - - - - - Y: + + true - - - - - 20 - 16777215 - - - - Enable Axis - - - Qt::LeftToRight - + + - - - - - - Associate Axis + + :/images/hat_logo.png - - - X - - - - - Y - - - - - Z - - - - - - - 20 - 16777215 - - - - Invert Axis - - - Qt::LeftToRight - - - - - - - - + + - - - - Z: + + + + true - - - - - - - 20 - 16777215 - - - - Enable Axis - - - Qt::LeftToRight - - - + + 800 - - - - Associate Axis - - - - X - - - - - Y - - - - - Z - - - - - - - - - 20 - 16777215 - - - - Invert Axis - - - Qt::LeftToRight - - - - + + - + Send - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 16 - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 16 - - - - - - - - 10 - 90 - 331 - 31 - + + + + + + 0 + 0 + - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 13 - 16 - - - - - - - - - 80 - 20 - - - - Center - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 13 - 16 - - - - - - - - - 80 - 20 - - - - Reset - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 13 - 16 - - - - - - - - - - 10 - 10 - 331 - 31 - - - - - - - - 60 - 16777215 - - - - Serial Port : - - - - - - - - 100 - 16777215 - - - - false - - - QComboBox::AdjustToMinimumContentsLength - - - 0 - - - - - - - Qt::Horizontal - - - QSizePolicy::Minimum - - - - 40 - 20 - - - - - - - - - - 10 - 50 - 331 - 31 - + + + 80 + 25 + - - - 7 - - - - - Choose the Serial Com port where is connected ARDUINO. - - - true - - - - - - - - - About - - - - - 10 - 20 - 111 - 111 - + + + 80 + 25 + - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">FTNoIR HAT Plugin<br />Version 1.0</span></p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">by FuraX49</span></p> -<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://hatire.sourceforge.net/"><span style=" font-weight:600; text-decoration: underline; color:#0000ff;">Manual (external)</span></a></p></body></html> - - - true + OK - - - - 200 - 20 - 128 - 128 - + + + + + + 80 + 25 + - - + + + 80 + 25 + - - :/images/hat_logo.png + + Save - - - - 10 - 190 - 331 - 251 - - - - true + + + + + + 0 + 0 + - - 800 - - - - - - 10 - 160 - 241 - 20 - + + + 80 + 25 + - - - - - 260 - 160 - 75 - 23 - + + + 80 + 25 + - Send + Cancel - - + + btnCancel diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat.cpp b/ftnoir_tracker_hatire/ftnoir_tracker_hat.cpp index e961a10f..99baf75b 100644 --- a/ftnoir_tracker_hatire/ftnoir_tracker_hat.cpp +++ b/ftnoir_tracker_hatire/ftnoir_tracker_hat.cpp @@ -1,67 +1,45 @@ -/******************************************************************************** -* FaceTrackNoIR This program is a private project of some enthusiastic * -* gamers from Holland, who don't like to pay much for * -* head-tracking. * -* * -* Copyright (C) 2012 Wim Vriend (Developing) * -* Ron Hendriks (Researching and Testing) * -* * -* Homepage: http://facetracknoir.sourceforge.net/home/default.htm * -* * -* This program is free software; you can redistribute it and/or modify it * -* under the terms of the GNU General Public License as published by the * -* Free Software Foundation; either version 3 of the License, or (at your * -* option) any later version. * -* * -* This program is distributed in the hope that it will be useful, but * -* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * -* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * -* more details. * -* * -* You should have received a copy of the GNU General Public License along * -* with this program; if not, see . * -* * -********************************************************************************/ - +/* code by Furax49, awaiting copyright information */ #include "ftnoir_tracker_hat.h" +#include "facetracknoir/global-settings.h" #include #include -#include -FTNoIR_Tracker::FTNoIR_Tracker() +FTNoIR_Tracker::FTNoIR_Tracker() : + SerialPort(nullptr), + stop(false) { - SerialPort = NULL; - waitTimeout = 1000; TrackerSettings settings; settings.load_ini(); applysettings(settings); + //ListErrInf = new QList(); - // Create events - m_StopThread = CreateEvent(0, TRUE, FALSE, 0); - m_WaitThread = CreateEvent(0, TRUE, FALSE, 0); - - ListErrInf = new QList(); - - // prepare & reserve QByteArray datagram.reserve(30); + qDebug() << "FTNoIR_Tracker::Initialize() Open SerialPort"; + SerialPort = new QSerialPort(sSerialPortName); + if (SerialPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered ) == true) { + SerialPort->flush(); + SerialPort->setBaudRate(115200); + SerialPort->setParity(QSerialPort::NoParity); + SerialPort->setDataBits(QSerialPort::Data8); + SerialPort->setStopBits(QSerialPort::OneStop); + SerialPort->setFlowControl(QSerialPort::NoFlowControl); + //SerialPort->setTimeout(waitTimeout); + //SerialPort->setQueryMode(QextSerialPort::EventDriven); //Polling + SerialPort->putChar('S'); + } + else { + QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to open SerialPort",QMessageBox::Ok,QMessageBox::NoButton); + delete SerialPort; + SerialPort = NULL; + } } FTNoIR_Tracker::~FTNoIR_Tracker() { - // Trigger thread to stop - ::SetEvent(m_StopThread); - - // Wait until thread finished - if (isRunning()) { - ::WaitForSingleObject(m_WaitThread, INFINITE); - } - - // Close handles - ::CloseHandle(m_StopThread); - ::CloseHandle(m_WaitThread); - + stop = true; + wait(); if (SerialPort!=NULL) { if (SerialPort->isOpen() ) { SerialPort->putChar('s'); //Send STOP to Arduino @@ -104,163 +82,92 @@ void FTNoIR_Tracker::reset() { //send command to Arduino void FTNoIR_Tracker::sendcmd(QString* cmd) { - QReadLocker locker(&rwlock); + QMutexLocker locker(&lock); QByteArray bytes; if (SerialPort!=NULL) { if (SerialPort->isOpen() ) { - bytes.append(cmd->toAscii()); - SerialPort->write(bytes); + bytes.append(cmd->toLatin1()); + SerialPort->write(bytes); } } } // return FPS and last status -void FTNoIR_Tracker::get_info(QString* info, int* tps ){ - QReadLocker locker(&rwlock); +void FTNoIR_Tracker::get_info(QString*, int* tps ){ + QMutexLocker locker(&lock); *tps=HAT.Code; +#if 0 if (ListErrInf->size()>0) { *info=ListErrInf->takeFirst(); } else { *info= QString(); } +#endif } /** QThread run @override **/ void FTNoIR_Tracker::run() { - // - // Read the data that was received. - // - forever { - - // Check event for stop thread - if(::WaitForSingleObject(m_StopThread, 0) == WAIT_OBJECT_0) - { - // Set event - ::SetEvent(m_WaitThread); - qDebug() << "FTNoIR_Tracker::run() terminated run()"; - return; - } - if (SerialPort->bytesAvailable()>=30) { - QWriteLocker locker(&rwlock); + if (!SerialPort) + return; + while (!stop) + { + if (SerialPort->bytesAvailable()>=30) + { + QMutexLocker locker(&lock); datagram.clear(); datagram=SerialPort->read(30); - QDataStream datastream(datagram); - datastream>>ArduinoData; - - if (ArduinoData.Begin==0xAAAA && ArduinoData.End==0x5555 ) { - if (ArduinoData.Code <= 1000) { + QDataStream datastream(datagram); + datastream >> ArduinoData; + if (ArduinoData.Begin==0xAAAA && ArduinoData.End==0x5555 ) + { + if (ArduinoData.Code <= 1000) + { HAT=ArduinoData; - } else { - ListErrInf->push_back(QString::fromAscii(datagram.mid(4,24),24)) ; - } + } } else { SerialPort->read(1); } } - //for lower cpu load usleep(10000); } } -void FTNoIR_Tracker::Initialize( QFrame *videoframe ) -{ - qDebug() << "FTNoIR_Tracker::Initialize says: Starting "; - - // - // Create SerialPort if they don't exist already. - // They must be created here, because they must be in the new thread (FTNoIR_Tracker::run()) - // - - if (SerialPort == NULL) { - qDebug() << "FTNoIR_Tracker::Initialize() Open SerialPort"; - SerialPort = new QextSerialPort(sSerialPortName); - if (SerialPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered ) == true) { - SerialPort->flush(); - SerialPort->setBaudRate(BAUD115200); - SerialPort->setParity(PAR_NONE); - SerialPort->setDataBits(DATA_8); - SerialPort->setStopBits(STOP_1); - SerialPort->setFlowControl(FLOW_OFF); - SerialPort->setTimeout(waitTimeout); - SerialPort->setQueryMode(QextSerialPort::EventDriven); //Polling - // Send START to arduino - SerialPort->putChar('S'); - } - else { - QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to open SerialPort",QMessageBox::Ok,QMessageBox::NoButton); - delete SerialPort; - SerialPort = NULL; - } - } - return; -} - -void FTNoIR_Tracker::StartTracker( HWND parent_window ) +void FTNoIR_Tracker::StartTracker( QFrame* ) { start( QThread::TimeCriticalPriority ); return; } -void FTNoIR_Tracker::StopTracker( bool exit ) +bool FTNoIR_Tracker::GiveHeadPoseData(double* data) { - // - // OK, the thread is not stopped, doing this. That might be dangerous anyway... - // - if (exit || !exit) return; - return; -} + QMutexLocker locker(&lock); -// -// Return 6DOF info -// -bool FTNoIR_Tracker::GiveHeadPoseData(THeadPoseData *data) -{ - QReadLocker locker(&rwlock); - data->frame_number = HAT.Code; + const bool inversions[] = { + bInvertX, bInvertY, bInvertZ, bInvertYaw, bInvertPitch, bInvertRoll + }; - if (bEnableYaw) { - if (bInvertYaw ) data->yaw = HAT.Gyro[iYawAxe] * -1.0f; - else data->yaw = HAT.Gyro[iYawAxe]; - } - - if (bEnablePitch) { - if (bInvertPitch)data->pitch = HAT.Gyro[iPitchAxe] * -1.0f; - else data->pitch = HAT.Gyro[iPitchAxe]; - } - - if (bEnableRoll) { - if (bInvertRoll) data->roll = HAT.Gyro[iRollAxe] * -1.0f; - else data->roll = HAT.Gyro[iRollAxe]; - } - - if (bEnableX) { - if (bInvertX) data->x = HAT.Acc[iXAxe]* -1.0f; - else data->x = HAT.Acc[iXAxe]; - } + const bool enablement[] = { + bEnableX, bEnableY, bEnableZ, bEnableYaw, bEnablePitch, bEnableRoll + }; - if (bEnableY) { - if (bInvertY) data->y = HAT.Acc[iYAxe]* -1.0f; - else data->y = HAT.Acc[iYAxe]; - } + const int axes[] = { + iXAxis, iYAxis, iZAxis, iYawAxis, iPitchAxis, iRollAxis + }; - if (bEnableZ) { - if (bInvertZ) data->z = HAT.Acc[iZAxe]* -1.0f; - else data->z = HAT.Acc[iZAxe]; - } + for (int i = 0; i < 6; i++) + { + if (enablement[i]) + data[i] = HAT.Gyro[axes[i]] * (inversions[i] ? -1 : 1); + } - return true; + return true; } - - -// -// Apply modification Settings -// void FTNoIR_Tracker::applysettings(const TrackerSettings& settings){ qDebug()<<"Tracker:: Applying settings"; - QReadLocker locker(&rwlock); + QMutexLocker locker(&lock); sSerialPortName= settings.SerialPortName; bEnableRoll = settings.EnableRoll; @@ -278,27 +185,15 @@ void FTNoIR_Tracker::applysettings(const TrackerSettings& settings){ bInvertZ = settings.InvertZ; - iRollAxe= settings.RollAxe; - iPitchAxe= settings.PitchAxe; - iYawAxe= settings.YawAxe; - iXAxe= settings.XAxe; - iYAxe= settings.YAxe; - iZAxe= settings.ZAxe; + iRollAxis= settings.RollAxis; + iPitchAxis= settings.PitchAxis; + iYawAxis= settings.YawAxis; + iXAxis= settings.XAxis; + iYAxis= settings.YAxis; + iZAxis= settings.ZAxis; } - - - -//////////////////////////////////////////////////////////////////////////////// -// Factory function that creates instances if the Tracker object. - -// Export both decorated and undecorated names. -// GetTracker - Undecorated name, which can be easily used with GetProcAddress -// Win32 API function. -// _GetTracker@0 - Common name decoration for __stdcall functions in C language. -#pragma comment(linker, "/export:GetTracker=_GetTracker@0") - -FTNOIR_TRACKER_BASE_EXPORT ITrackerPtr __stdcall GetTracker() +extern "C" FTNOIR_TRACKER_BASE_EXPORT ITracker* CALLING_CONVENTION GetConstructor() { return new FTNoIR_Tracker; } diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat.h b/ftnoir_tracker_hatire/ftnoir_tracker_hat.h index 54e67f48..af583d11 100644 --- a/ftnoir_tracker_hatire/ftnoir_tracker_hat.h +++ b/ftnoir_tracker_hatire/ftnoir_tracker_hat.h @@ -1,33 +1,28 @@ #ifndef FTNOIR_TRACKER_HAT_H #define FTNOIR_TRACKER_HAT_H -#include "..\ftnoir_tracker_base\ftnoir_tracker_base.h" +#include "facetracknoir/global-settings.h" +#include "ftnoir_tracker_base/ftnoir_tracker_base.h" #include "ftnoir_tracker_hat_settings.h" #include "ftnoir_arduino_type.h" -#include -#include +#include #include -#include #include #include -#include "Windows.h" -#include "math.h" - -class QextSerialPort; -class QExtSerialEnumerator; +#include +#include +#include class FTNoIR_Tracker : public ITracker, QThread { public: FTNoIR_Tracker(); - ~FTNoIR_Tracker(); + virtual ~FTNoIR_Tracker() virt_override; - void Initialize( QFrame *videoframe ); - void StartTracker( HWND parent_window ); - void StopTracker( bool exit ); - bool GiveHeadPoseData(THeadPoseData *data); + virtual void StartTracker( QFrame* frame ) virt_override; + virtual bool GiveHeadPoseData(double *data) virt_override; void applysettings(const TrackerSettings& settings); void notifyCenter(); @@ -39,18 +34,12 @@ public: protected: void run(); // qthread override run method - private: - // Handles to neatly terminate thread... - HANDLE m_StopThread; - HANDLE m_WaitThread; - TArduinoData ArduinoData, HAT ; // Trame from Arduino QByteArray datagram; - QextSerialPort *SerialPort; - QReadWriteLock rwlock; - QList* ListErrInf ; - int waitTimeout; + QSerialPort* SerialPort; + volatile bool stop; + QMutex lock; QString sSerialPortName; // Port serial name bool bEnableRoll; bool bEnablePitch; @@ -67,28 +56,22 @@ private: bool bInvertZ; - int iRollAxe; - int iPitchAxe; - int iYawAxe; - int iXAxe; - int iYAxe; - int iZAxe; + int iRollAxis; + int iPitchAxis; + int iYawAxis; + int iXAxis; + int iYAxis; + int iZAxis; }; - -//******************************************************************************************************* -// FaceTrackNoIR Tracker DLL. Functions used to get general info on the Tracker -//******************************************************************************************************* -class FTNoIR_TrackerDll : public ITrackerDll +class FTNoIR_TrackerDll : public Metadata { public: FTNoIR_TrackerDll(); ~FTNoIR_TrackerDll(); - void Initialize(); - - void getFullName(QString *strToBeFilled); + void getFullName(QString *strToBeFilled); void getShortName(QString *strToBeFilled); void getDescription(QString *strToBeFilled); void getIcon(QIcon *icon); @@ -99,4 +82,4 @@ private: QString trackerDescription; }; -#endif // FTNOIR_TRACKER_HAT_H \ No newline at end of file +#endif // FTNOIR_TRACKER_HAT_H diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.cpp b/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.cpp index b889341f..1fa482c7 100644 --- a/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.cpp +++ b/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.cpp @@ -1,32 +1,9 @@ -/******************************************************************************** -* FaceTrackNoIR This program is a private project of some enthusiastic * -* gamers from Holland, who don't like to pay much for * -* head-tracking. * -* * -* Copyright (C) 2012 Wim Vriend (Developing) * -* Ron Hendriks (Researching and Testing) * -* * -* Homepage: http://facetracknoir.sourceforge.net/home/default.htm * -* * -* This program is free software; you can redistribute it and/or modify it * -* under the terms of the GNU General Public License as published by the * -* Free Software Foundation; either version 3 of the License, or (at your * -* option) any later version. * -* * -* This program is distributed in the hope that it will be useful, but * -* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * -* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * -* more details. * -* * -* You should have received a copy of the GNU General Public License along * -* with this program; if not, see . * -* * -********************************************************************************/ #include "ftnoir_tracker_hat.h" #include "ftnoir_tracker_hat_dialog.h" #include #include +#include //******************************************************************************************************* // FaceTrackNoIR Client Settings-dialog. @@ -35,21 +12,16 @@ // // Constructor for server-settings-dialog // -TrackerControls::TrackerControls() : settingsDirty(false), theTracker(NULL), timer(this), -QWidget() +TrackerControls::TrackerControls() : pre_frame(0), theTracker(NULL), settingsDirty(false), timer(this) { - settingsDirty= false; - theTracker = NULL; ui.setupUi( this ); - pre_trame = 0; settings.load_ini(); - // make SerialPort list - foreach (QextPortInfo PortInfo , QextSerialEnumerator::getPorts() ) { - ui.cbSerialPort->addItem(PortInfo.portName); + foreach (QSerialPortInfo PortInfo , QSerialPortInfo::availablePorts() ) { + ui.cbSerialPort->addItem(PortInfo.portName()); } - // Stop if no SerialPort dispo + if (ui.cbSerialPort->count()<1) { QMessageBox::critical(this,"FaceTrackNoIR Error", "No SerialPort avaible"); } else { @@ -77,21 +49,18 @@ QWidget() ui.chkInvertY->setChecked(settings.InvertY); ui.chkInvertZ->setChecked(settings.InvertZ); - - ui.cb_roll->setCurrentIndex(settings.RollAxe); - ui.cb_pitch->setCurrentIndex(settings.PitchAxe); - ui.cb_yaw->setCurrentIndex(settings.YawAxe); - ui.cb_x->setCurrentIndex(settings.XAxe); - ui.cb_y->setCurrentIndex(settings.YAxe); - ui.cb_z->setCurrentIndex(settings.ZAxe); - + ui.cb_roll->setCurrentIndex(settings.RollAxis); + ui.cb_pitch->setCurrentIndex(settings.PitchAxis); + ui.cb_yaw->setCurrentIndex(settings.YawAxis); + ui.cb_x->setCurrentIndex(settings.XAxis); + ui.cb_y->setCurrentIndex(settings.YAxis); + ui.cb_z->setCurrentIndex(settings.ZAxis); // Connect Qt signals to member-functions connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK())); connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel())); connect(ui.btnSave, SIGNAL(clicked()), this, SLOT(doSave())); - connect(ui.cbSerialPort, SIGNAL(currentIndexChanged(QString)), this,SLOT(set_mod_port(QString)) ); connect( ui.chkEnableRoll,SIGNAL(toggled(bool)), this,SLOT(set_ena_roll(bool)) ); @@ -108,7 +77,6 @@ QWidget() connect( ui.chkInvertY,SIGNAL(toggled(bool)), this,SLOT(set_inv_y(bool)) ); connect( ui.chkInvertZ,SIGNAL(toggled(bool)), this,SLOT(set_inv_z(bool)) ); - connect(ui.cb_roll, SIGNAL(currentIndexChanged(int)), this,SLOT(set_rot_roll(int))); connect(ui.cb_pitch, SIGNAL(currentIndexChanged(int)),this,SLOT(set_rot_pitch(int))); connect(ui.cb_yaw, SIGNAL(currentIndexChanged(int)), this,SLOT(set_rot_yaw(int))); @@ -127,13 +95,8 @@ QWidget() // Destructor for server-dialog // TrackerControls::~TrackerControls() { - delete this; } - -// -// Initialize tracker-client-dialog -// void TrackerControls::Initialize(QWidget *parent) { QPoint offsetpos(100, 100); if (parent) { @@ -142,35 +105,20 @@ void TrackerControls::Initialize(QWidget *parent) { show(); } - -// -// Apply online settings to tracker -// void TrackerControls::settings_changed() { settingsDirty = true; if (theTracker) theTracker->applysettings(settings); } - -// -// Center asked to ARDUINO -// void TrackerControls::doCenter() { if (theTracker) theTracker->center(); } -// -// Reset asked to ARDUINO -// void TrackerControls::doReset() { if (theTracker) theTracker->reset(); } - -// -// Send command to ARDUINO -// void TrackerControls::doSend() { if (theTracker) { if (!ui.lineSend->text().isEmpty()) { @@ -182,10 +130,6 @@ void TrackerControls::doSend() { } } - -// -// Display FPS and Status of Arduino. -// void TrackerControls::poll_tracker_info() { if (theTracker) @@ -202,13 +146,13 @@ void TrackerControls::poll_tracker_info() } - if (pre_tramesetText(QString::number(nb_trame*(1000/timer.interval()))); - pre_trame=num_trame; + pre_frame=num_trame; } } @@ -219,28 +163,15 @@ void TrackerControls::doSave() { settings.save_ini(); } - -// -// OK clicked on server-dialog -// void TrackerControls::doOK() { settingsDirty=false; settings.save_ini(); this->close(); } -// -// Cancel clicked on server-dialog -// void TrackerControls::doCancel() { - // - // Ask if changed Settings should be saved - // - if (settingsDirty) { + if (settingsDirty) { int ret = QMessageBox::question ( this, "Settings have changed", "Do you want to save the settings?", QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard ); - - // qDebug() << "doCancel says: answer =" << ret; - switch (ret) { case QMessageBox::Save: settings.save_ini(); @@ -250,10 +181,8 @@ void TrackerControls::doCancel() { close(); break; case QMessageBox::Cancel: - // Cancel was clicked break; default: - // should never be reached break; } } @@ -264,15 +193,13 @@ void TrackerControls::doCancel() { void TrackerControls::registerTracker(ITracker *tracker) { -// theTracker = (FTNoIR_Tracker *) tracker; - theTracker = static_cast(tracker); + theTracker = dynamic_cast(tracker); if (isVisible() && settingsDirty) theTracker->applysettings(settings); ui.cbSerialPort->setEnabled(false); timer.start(250); ui.lab_vstatus->setText("HAT START"); } - void TrackerControls::unRegisterTracker() { theTracker = NULL; ui.cbSerialPort->setEnabled(true); @@ -281,19 +208,7 @@ void TrackerControls::unRegisterTracker() { ui.lab_vtps->setText(""); } - - - -//////////////////////////////////////////////////////////////////////////////// -// Factory function that creates instances if the Tracker-settings dialog object. - -// Export both decorated and undecorated names. -// GetTrackerDialog - Undecorated name, which can be easily used with GetProcAddress -// Win32 API function. -// _GetTrackerDialog@0 - Common name decoration for __stdcall functions in C language. -#pragma comment(linker, "/export:GetTrackerDialog=_GetTrackerDialog@0") - -FTNOIR_TRACKER_BASE_EXPORT ITrackerDialogPtr __stdcall GetTrackerDialog( ) +extern "C" FTNOIR_TRACKER_BASE_EXPORT ITrackerDialog* CALLING_CONVENTION GetDialog() { return new TrackerControls; } diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.h b/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.h index c463f361..25bd839c 100644 --- a/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.h +++ b/ftnoir_tracker_hatire/ftnoir_tracker_hat_dialog.h @@ -1,7 +1,7 @@ #ifndef FTNOIR_TRACKER_HAT_DIALOG_H #define FTNOIR_TRACKER_HAT_DIALOG_H -#include "..\ftnoir_tracker_base\ftnoir_tracker_base.h" +#include "ftnoir_tracker_base/ftnoir_tracker_base.h" #include "ftnoir_tracker_hat_settings.h" #include "ftnoir_tracker_hat.h" #include "ui_ftnoir_hatcontrols.h" @@ -9,32 +9,25 @@ #include #include -// Widget that has controls for FTNoIR protocol client-settings. -class TrackerControls: public QWidget, Ui::UIHATControls, public ITrackerDialog +class TrackerControls: public QWidget, public ITrackerDialog { Q_OBJECT public: explicit TrackerControls(); - virtual ~TrackerControls(); + virtual ~TrackerControls() virt_override; - void Initialize(QWidget *parent); - void registerTracker(ITracker *tracker); - void unRegisterTracker() ; + void Initialize(QWidget *parent) virt_override; + void registerTracker(ITracker *tracker) virt_override; + void unRegisterTracker() virt_override; private: Ui::UIHATControls ui; - int pre_trame; + int pre_frame; FTNoIR_Tracker *theTracker; protected slots: - - /* - void set_mod_port(int val) { settings.SerialPortName = ui.cbSerialPort->itemText(val); - QMessageBox::warning(this,"FaceTrackNoIR Error", settings.SerialPortName); - settings_changed(); } -*/ - void set_mod_port(const QString & val) { settings.SerialPortName =val; + void set_mod_port(const QString & val) { settings.SerialPortName =val; QMessageBox::warning(this,"FaceTrackNoIR Error", settings.SerialPortName); settings_changed(); } void set_ena_roll(bool val) { settings.EnableRoll = val; settings_changed(); } @@ -52,12 +45,12 @@ protected slots: void set_inv_z(bool val) { settings.InvertZ = val; settings_changed(); } - void set_rot_roll(int val) { settings.RollAxe = val; settings_changed(); } - void set_rot_pitch(int val) { settings.PitchAxe = val; settings_changed(); } - void set_rot_yaw(int val) { settings.YawAxe = val; settings_changed(); } - void set_acc_x(int val) { settings.XAxe = val; settings_changed(); } - void set_acc_y(int val) { settings.YAxe = val; settings_changed(); } - void set_acc_z(int val) { settings.ZAxe = val; settings_changed(); } + void set_rot_roll(int val) { settings.RollAxis = val; settings_changed(); } + void set_rot_pitch(int val) { settings.PitchAxis = val; settings_changed(); } + void set_rot_yaw(int val) { settings.YawAxis = val; settings_changed(); } + void set_acc_x(int val) { settings.XAxis = val; settings_changed(); } + void set_acc_y(int val) { settings.YAxis = val; settings_changed(); } + void set_acc_z(int val) { settings.ZAxis = val; settings_changed(); } void doOK(); void doCancel(); @@ -75,4 +68,4 @@ protected: }; -#endif //FTNOIR_TRACKER_HAT_DIALOG_H \ No newline at end of file +#endif //FTNOIR_TRACKER_HAT_DIALOG_H diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat_dll.cpp b/ftnoir_tracker_hatire/ftnoir_tracker_hat_dll.cpp index 246eb397..c19f68d3 100644 --- a/ftnoir_tracker_hatire/ftnoir_tracker_hat_dll.cpp +++ b/ftnoir_tracker_hatire/ftnoir_tracker_hat_dll.cpp @@ -1,79 +1,38 @@ -/******************************************************************************** -* FaceTrackNoIR This program is a private project of some enthusiastic * -* gamers from Holland, who don't like to pay much for * -* head-tracking. * -* * -* Copyright (C) 2012 Wim Vriend (Developing) * -* Ron Hendriks (Researching and Testing) * -* * -* Homepage: http://facetracknoir.sourceforge.net/home/default.htm * -* * -* This program is free software; you can redistribute it and/or modify it * -* under the terms of the GNU General Public License as published by the * -* Free Software Foundation; either version 3 of the License, or (at your * -* option) any later version. * -* * -* This program is distributed in the hope that it will be useful, but * -* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * -* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * -* more details. * -* * -* You should have received a copy of the GNU General Public License along * -* with this program; if not, see . * -* * -********************************************************************************/ - #include "ftnoir_tracker_hat.h" -#include +#include #include FTNoIR_TrackerDll::FTNoIR_TrackerDll() { - //populate the description strings - trackerFullName = "Head Arduino Tracker"; + trackerFullName = "Hatire Arduino"; trackerShortName = "HAT"; - trackerDescription = "FaceTrackNoIR HAT"; + trackerDescription = "Hatire Arduino"; } FTNoIR_TrackerDll::~FTNoIR_TrackerDll() { - -} - -void FTNoIR_TrackerDll::Initialize() -{ - return; } void FTNoIR_TrackerDll::getFullName(QString *strToBeFilled) { *strToBeFilled = trackerFullName; -}; +} void FTNoIR_TrackerDll::getShortName(QString *strToBeFilled) { *strToBeFilled = trackerShortName; -}; +} void FTNoIR_TrackerDll::getDescription(QString *strToBeFilled) { *strToBeFilled = trackerDescription; -}; +} void FTNoIR_TrackerDll::getIcon(QIcon *icon) { *icon = QIcon(":/images/hat.ico"); -}; - -//////////////////////////////////////////////////////////////////////////////// -// Factory function that creates instances if the Tracker object. - -// Export both decorated and undecorated names. -// GetTrackerDll - Undecorated name, which can be easily used with GetProcAddress -// Win32 API function. -// _GetTrackerDll@0 - Common name decoration for __stdcall functions in C language. -#pragma comment(linker, "/export:GetTrackerDll=_GetTrackerDll@0") +} -FTNOIR_TRACKER_BASE_EXPORT ITrackerDllPtr __stdcall GetTrackerDll() +extern "C" FTNOIR_TRACKER_BASE_EXPORT Metadata* CALLING_CONVENTION GetMetadata() { return new FTNoIR_TrackerDll; } diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp b/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp index f8b342cc..1d2643ee 100644 --- a/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp +++ b/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.cpp @@ -1,27 +1,3 @@ -/******************************************************************************** -* FaceTrackNoIR This program is a private project of some enthusiastic * -* gamers from Holland, who don't like to pay much for * -* head-tracking. * -* * -* Copyright (C) 2012 Wim Vriend (Developing) * -* Ron Hendriks (Researching and Testing) * -* * -* Homepage: http://facetracknoir.sourceforge.net/home/default.htm * -* * -* This program is free software; you can redistribute it and/or modify it * -* under the terms of the GNU General Public License as published by the * -* Free Software Foundation; either version 3 of the License, or (at your * -* option) any later version. * -* * -* This program is distributed in the hope that it will be useful, but * -* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * -* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * -* more details. * -* * -* You should have received a copy of the GNU General Public License along * -* with this program; if not, see . * -* * -********************************************************************************/ #include #include @@ -54,12 +30,12 @@ void TrackerSettings::load_ini() InvertZ = iniFile.value( "InvertZ", 0 ).toBool(); - RollAxe=iniFile.value("RollAxe",1).toInt(); - PitchAxe=iniFile.value("PitchAxe",2).toInt(); - YawAxe=iniFile.value("YawAxe",0).toInt(); - XAxe=iniFile.value("XAxe",1).toInt(); - YAxe=iniFile.value("YAxe",2).toInt(); - ZAxe=iniFile.value("ZAxe",0).toInt(); + RollAxis=iniFile.value("RollAxis",1).toInt(); + PitchAxis=iniFile.value("PitchAxis",2).toInt(); + YawAxis=iniFile.value("YawAxis",0).toInt(); + XAxis=iniFile.value("XAxis",1).toInt(); + YAxis=iniFile.value("YAxis",2).toInt(); + ZAxis=iniFile.value("ZAxis",0).toInt(); iniFile.endGroup(); } @@ -91,12 +67,12 @@ void TrackerSettings::save_ini() const iniFile.setValue( "InvertY", InvertY ); iniFile.setValue( "InvertZ", InvertZ ); - iniFile.setValue ( "RollAxe", RollAxe ); - iniFile.setValue ( "PitchAxe", PitchAxe ); - iniFile.setValue ( "YawAxe",YawAxe ); - iniFile.setValue ( "XAxe", XAxe ); - iniFile.setValue ( "YAxe", YAxe ); - iniFile.setValue ( "ZAxe", ZAxe ); + iniFile.setValue ( "RollAxis", RollAxis ); + iniFile.setValue ( "PitchAxis", PitchAxis ); + iniFile.setValue ( "YawAxis",YawAxis ); + iniFile.setValue ( "XAxis", XAxis ); + iniFile.setValue ( "YAxis", YAxis ); + iniFile.setValue ( "ZAxis", ZAxis ); iniFile.endGroup(); } diff --git a/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.h b/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.h index a29fed6b..d6cf4fd9 100644 --- a/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.h +++ b/ftnoir_tracker_hatire/ftnoir_tracker_hat_settings.h @@ -8,6 +8,7 @@ #ifndef FTNOIR_TRACKER_HAT_SETTINGS_H #define FTNOIR_TRACKER_HAT_SETTINGS_H +#include //----------------------------------------------------------------------------- struct TrackerSettings @@ -29,16 +30,15 @@ struct TrackerSettings bool InvertZ; - int RollAxe; - int PitchAxe; - int YawAxe; - int XAxe; - int YAxe; - int ZAxe; + int RollAxis; + int PitchAxis; + int YawAxis; + int XAxis; + int YAxis; + int ZAxis; void load_ini(); void save_ini() const; }; - -#endif //FTNOIR_TRACKER_HAT_SETTINGS_H \ No newline at end of file +#endif //FTNOIR_TRACKER_HAT_SETTINGS_H -- cgit v1.2.3