summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_tracker_hatire/ftnoir_tracker_hat.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2013-11-27 02:32:24 +0100
committerStanislaw Halik <sthalik@misaki.pl>2013-11-27 02:32:24 +0100
commit09aeee333b807be87f456fa226fc0442d5a37364 (patch)
tree71f36a0ae58ca751ccd61671cdbb1fd58c877ac3 /ftnoir_tracker_hatire/ftnoir_tracker_hat.cpp
parent8e00d5a1599cc60a823191ed5351d68066682b16 (diff)
make hatire actually buildable
Remove 'captain obvious' comments, references to <windows.h>, fix spelling errors, use UI layouts, and so on Signed-off-by: Stanislaw Halik <sthalik@misaki.pl>
Diffstat (limited to 'ftnoir_tracker_hatire/ftnoir_tracker_hat.cpp')
-rw-r--r--ftnoir_tracker_hatire/ftnoir_tracker_hat.cpp251
1 files changed, 73 insertions, 178 deletions
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 <http://www.gnu.org/licenses/>. *
-* *
-********************************************************************************/
-
+/* code by Furax49, awaiting copyright information */
#include "ftnoir_tracker_hat.h"
+#include "facetracknoir/global-settings.h"
#include <QMessageBox>
#include <QDebug>
-#include <QCoreApplication>
-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<QString>();
- // Create events
- m_StopThread = CreateEvent(0, TRUE, FALSE, 0);
- m_WaitThread = CreateEvent(0, TRUE, FALSE, 0);
-
- ListErrInf = new QList<QString>();
-
- // 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;
}