summaryrefslogtreecommitdiffhomepage
path: root/FaceTrackNoIR
diff options
context:
space:
mode:
authorWim Vriend <facetracknoir@gmail.com>2010-12-30 18:13:00 +0000
committerWim Vriend <facetracknoir@gmail.com>2010-12-30 18:13:00 +0000
commit26a42de2b739b8bf2cf9f1e1c849a681c1fcdc89 (patch)
treea44dfec3a52af472c14fe9009dfe9cbff507a097 /FaceTrackNoIR
parent016d79347d429c291ea65eb95663e200e1e601f2 (diff)
Spent the day removing some bad-bugs in the fake TrackIR protocol and the SCServer protocol. Seems to work now?!
git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@34 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb
Diffstat (limited to 'FaceTrackNoIR')
-rw-r--r--FaceTrackNoIR/Debug/BuildLog.htmbin24030 -> 30344 bytes
-rw-r--r--FaceTrackNoIR/Debug/FTServer.objbin93596 -> 112552 bytes
-rw-r--r--FaceTrackNoIR/Debug/FaceTrackNoIR.exe.intermediate.manifest5
-rw-r--r--FaceTrackNoIR/Debug/main.objbin166199 -> 167871 bytes
-rw-r--r--FaceTrackNoIR/Debug/moc_FTServer.objbin67454 -> 66888 bytes
-rw-r--r--FaceTrackNoIR/Debug/moc_tracker.objbin160647 -> 166418 bytes
-rw-r--r--FaceTrackNoIR/Debug/mt.dep2
-rw-r--r--FaceTrackNoIR/Debug/tracker.objbin321759 -> 410641 bytes
-rw-r--r--FaceTrackNoIR/FGServer.cpp50
-rw-r--r--FaceTrackNoIR/FGServer.h6
-rw-r--r--FaceTrackNoIR/FTIRServer.cpp83
-rw-r--r--FaceTrackNoIR/FTIRServer.h7
-rw-r--r--FaceTrackNoIR/FTIRTypes.h30
-rw-r--r--FaceTrackNoIR/FTServer.h2
-rw-r--r--FaceTrackNoIR/FaceTrackNoIR.cpp4
-rw-r--r--FaceTrackNoIR/FaceTrackNoIR.vcproj6
-rw-r--r--FaceTrackNoIR/SCServer.cpp174
-rw-r--r--FaceTrackNoIR/SCServer.h46
-rw-r--r--FaceTrackNoIR/tracker.cpp100
-rw-r--r--FaceTrackNoIR/tracker.h1
20 files changed, 386 insertions, 130 deletions
diff --git a/FaceTrackNoIR/Debug/BuildLog.htm b/FaceTrackNoIR/Debug/BuildLog.htm
index 7c0bed45..41cc6d85 100644
--- a/FaceTrackNoIR/Debug/BuildLog.htm
+++ b/FaceTrackNoIR/Debug/BuildLog.htm
Binary files differ
diff --git a/FaceTrackNoIR/Debug/FTServer.obj b/FaceTrackNoIR/Debug/FTServer.obj
index ec5b2a12..7b150608 100644
--- a/FaceTrackNoIR/Debug/FTServer.obj
+++ b/FaceTrackNoIR/Debug/FTServer.obj
Binary files differ
diff --git a/FaceTrackNoIR/Debug/FaceTrackNoIR.exe.intermediate.manifest b/FaceTrackNoIR/Debug/FaceTrackNoIR.exe.intermediate.manifest
index 386d1d84..1970430c 100644
--- a/FaceTrackNoIR/Debug/FaceTrackNoIR.exe.intermediate.manifest
+++ b/FaceTrackNoIR/Debug/FaceTrackNoIR.exe.intermediate.manifest
@@ -7,6 +7,11 @@
</dependency>
<dependency>
<dependentAssembly>
+ <assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50727.4053' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
+ </dependentAssembly>
+ </dependency>
+ <dependency>
+ <dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50727.762' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
</dependentAssembly>
</dependency>
diff --git a/FaceTrackNoIR/Debug/main.obj b/FaceTrackNoIR/Debug/main.obj
index 337e15e3..8c10111b 100644
--- a/FaceTrackNoIR/Debug/main.obj
+++ b/FaceTrackNoIR/Debug/main.obj
Binary files differ
diff --git a/FaceTrackNoIR/Debug/moc_FTServer.obj b/FaceTrackNoIR/Debug/moc_FTServer.obj
index 40b920e8..430d91b2 100644
--- a/FaceTrackNoIR/Debug/moc_FTServer.obj
+++ b/FaceTrackNoIR/Debug/moc_FTServer.obj
Binary files differ
diff --git a/FaceTrackNoIR/Debug/moc_tracker.obj b/FaceTrackNoIR/Debug/moc_tracker.obj
index f7e97e64..c444fd14 100644
--- a/FaceTrackNoIR/Debug/moc_tracker.obj
+++ b/FaceTrackNoIR/Debug/moc_tracker.obj
Binary files differ
diff --git a/FaceTrackNoIR/Debug/mt.dep b/FaceTrackNoIR/Debug/mt.dep
index 944d12c9..e3b3d65c 100644
--- a/FaceTrackNoIR/Debug/mt.dep
+++ b/FaceTrackNoIR/Debug/mt.dep
@@ -1 +1 @@
-Manifest resource last updated at 13:41:52.12 on vr 03-09-2010
+Manifest resource last updated at 19:09:04.43 on do 30-12-2010
diff --git a/FaceTrackNoIR/Debug/tracker.obj b/FaceTrackNoIR/Debug/tracker.obj
index fdc49f4e..2c70374a 100644
--- a/FaceTrackNoIR/Debug/tracker.obj
+++ b/FaceTrackNoIR/Debug/tracker.obj
Binary files differ
diff --git a/FaceTrackNoIR/FGServer.cpp b/FaceTrackNoIR/FGServer.cpp
index 9f362e52..dfcb3d21 100644
--- a/FaceTrackNoIR/FGServer.cpp
+++ b/FaceTrackNoIR/FGServer.cpp
@@ -60,6 +60,24 @@ FGServer::~FGServer() {
//
void FGServer::sendHeadposeToGame() {
int no_bytes;
+QHostAddress sender;
+quint16 senderPort;
+
+ //
+ // Create UDP-sockets if they don't exist already.
+ // They must be created here, because they must be in the Tracker thread (Tracker::run())
+ //
+ if (inSocket == 0) {
+ qDebug() << "FGServer::sendHeadposeToGame creating sockets";
+ inSocket = new QUdpSocket();
+ // Connect the inSocket to the port, to receive messages
+// inSocket->bind(QHostAddress::LocalHost, 5551);
+ inSocket->bind(QHostAddress::Any, destPort+1);
+ }
+
+ if (outSocket == 0) {
+ outSocket = new QUdpSocket();
+ }
//
// Copy the Raw measurements directly to the client.
@@ -86,31 +104,19 @@ int no_bytes;
qDebug() << "FGServer::writePendingDatagrams says: nothing send!";
}
-}
-
-//
-// Callback function registered in the run() method.
-// Retrieve all pending Datagrams (typically 1) and send a reply, containing the headpose-data.
-//
-void FGServer::readPendingDatagrams()
-{
-QHostAddress sender;
-quint16 senderPort;
-
//
- // Read data from FlightGear
+ // FlightGear keeps sending data, so we must read that here.
//
while (inSocket->hasPendingDatagrams()) {
+
QByteArray datagram;
datagram.resize(inSocket->pendingDatagramSize());
-// qDebug() << "FGServer::readPendingDatagrams says: size =" << inSocket->pendingDatagramSize();
-
inSocket->readDatagram( (char * ) &cmd, sizeof(cmd), &sender, &senderPort);
-// qDebug() << "FGServer::readPendingDatagrams says: data =" << cmd;
fg_cmd = cmd; // Let's just accept that command for now...
if ( cmd > 0 ) {
+ qDebug() << "FGServer::sendHeadposeToGame hasPendingDatagrams, cmd = " << cmd;
headTracker->handleGameCommand ( cmd ); // Send it upstream, for the Tracker to handle
}
}
@@ -130,18 +136,10 @@ bool FGServer::checkServerInstallationOK( HANDLE handle )
TestData.p = 0.0f;
TestData.r = 0.0f;
TestData.status = 0;
- fg_cmd = 0;
-
- // Create UDP-sockets
- inSocket = new QUdpSocket();
- outSocket = new QUdpSocket();
-
- // Connect the inSocket to the port, to receive readyRead messages
-// inSocket->bind(QHostAddress::LocalHost, 5551);
- inSocket->bind(QHostAddress::Any, destPort+1);
+ fg_cmd = 1;
- // Connect the inSocket to the member-function, to read FlightGear commands
- connect(inSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()), Qt::DirectConnection);
+ inSocket = 0;
+ outSocket = 0;
return true;
}
diff --git a/FaceTrackNoIR/FGServer.h b/FaceTrackNoIR/FGServer.h
index 9fd52eb3..8e7d8b21 100644
--- a/FaceTrackNoIR/FGServer.h
+++ b/FaceTrackNoIR/FGServer.h
@@ -37,7 +37,7 @@
#include <QFile>
#include <QApplication>
#include <QDebug>
-#include <QThread>
+//#include <QThread>
#include <QMutex>
#include <QLibrary>
#include <QUdpSocket>
@@ -63,9 +63,6 @@ protected:
bool checkServerInstallationOK( HANDLE handle );
void sendHeadposeToGame();
-private slots:
- void readPendingDatagrams();
-
private:
Tracker *headTracker; // For upstream messages...
TFlightGearData TestData;
@@ -75,7 +72,6 @@ private:
qint32 fg_cmd; // Command from FlightGear
QHostAddress destIP; // Destination IP-address
int destPort; // Destination port-number
-
void loadSettings();
};
diff --git a/FaceTrackNoIR/FTIRServer.cpp b/FaceTrackNoIR/FTIRServer.cpp
index 54570fcd..7268d1dc 100644
--- a/FaceTrackNoIR/FTIRServer.cpp
+++ b/FaceTrackNoIR/FTIRServer.cpp
@@ -32,24 +32,80 @@
FTIRServer::FTIRServer() {
loadSettings();
ProgramName = "";
+ dummyTrackIR = 0;
+ viewsStart = 0;
+ viewsStop = 0;
}
/** destructor **/
FTIRServer::~FTIRServer() {
//
+ // Destroy the File-mapping
+ //
+ FTIRDestroyMapping();
+
+ //
// Free the DLL's
//
FTIRClientLib.unload();
- FTIRViewsLib.unload();
+ if (viewsStop != NULL) {
+ viewsStop();
+ FTIRViewsLib.unload();
+ }
//
// Kill the dummy TrackIR process.
//
qDebug() << "FTIRServer::~FTIRServer() about to kill TrackIR.exe process";
- if (dummyTrackIR) {
- dummyTrackIR->kill();
+ try {
+ if (dummyTrackIR) {
+ dummyTrackIR->kill();
+ }
+ }
+ catch (...)
+ {
+ qDebug() << "~FTIRServer says: some error occurred";
}
+
+}
+
+/** destructor **/
+void FTIRServer::stopServer() {
+
+ ////
+ //// Destroy the File-mapping
+ ////
+ //FTIRDestroyMapping();
+
+ ////
+ //// Free the DLL's
+ ////
+ //try {
+ // FTIRClientLib.unload();
+ // if (useTIRViews && FTIRViewsLib.isLoaded()) {
+ // FTIRViewsLib.unload();
+ // }
+ //}
+ //catch (...)
+ //{
+ // qDebug() << "~FTIRServer says: some error occurred";
+ //}
+
+ ////
+ //// Kill the dummy TrackIR process.
+ ////
+ //qDebug() << "FTIRServer::~FTIRServer() about to kill TrackIR.exe process";
+ //try {
+ // if (dummyTrackIR) {
+ // dummyTrackIR->kill();
+ // }
+ //}
+ //catch (...)
+ // {
+ // qDebug() << "~FTIRServer says: some error occurred";
+ //}
+
}
//
@@ -124,9 +180,26 @@ void FTIRServer::FTIRDestroyMapping()
UnmapViewOfFile ( pMemData );
}
- CloseHandle( hFTIRMutex );
- CloseHandle( hFTIRMemMap );
+ if (hFTIRMutex != 0) {
+ CloseHandle( hFTIRMutex );
+ }
+ hFTIRMutex = 0;
+
+ if (hFTIRMemMap != 0) {
+ CloseHandle( hFTIRMemMap );
+ }
hFTIRMemMap = 0;
+
+}
+
+//
+// Get the program-name from the client (Game!).
+//
+QString FTIRServer::GetProgramName() {
+QString *str;
+
+ str = new QString("Test");
+ return *str;
}
//
diff --git a/FaceTrackNoIR/FTIRServer.h b/FaceTrackNoIR/FTIRServer.h
index bdf31cc6..98bba55c 100644
--- a/FaceTrackNoIR/FTIRServer.h
+++ b/FaceTrackNoIR/FTIRServer.h
@@ -31,7 +31,6 @@
#include <QFile>
#include <QApplication>
#include <QDebug>
-#include <QThread>
#include <QMutex>
#include <QLibrary>
#include <QProcess>
@@ -53,11 +52,13 @@ public:
// public member methods
FTIRServer();
~FTIRServer();
+ QString GetProgramName();
// protected member methods
protected:
bool checkServerInstallationOK( HANDLE handle );
void sendHeadposeToGame();
+ void stopServer();
private:
bool FTIRCreateMapping(HANDLE handle);
@@ -75,10 +76,10 @@ private:
QString ProgramName;
QLibrary FTIRClientLib;
QLibrary FTIRViewsLib;
- bool useTIRViews;
QProcess *dummyTrackIR;
+ bool useTIRViews;
- static float scale2AnalogLimits( float x, float min_x, float max_x );
+ float scale2AnalogLimits( float x, float min_x, float max_x );
void loadSettings();
public:
diff --git a/FaceTrackNoIR/FTIRTypes.h b/FaceTrackNoIR/FTIRTypes.h
index bd19769b..f238762c 100644
--- a/FaceTrackNoIR/FTIRTypes.h
+++ b/FaceTrackNoIR/FTIRTypes.h
@@ -143,22 +143,22 @@ typedef FTIRMemMap * PFTIRMemMap;
// the client -- this function receives head tester reports from the game client API
//
typedef NPRESULT (__stdcall *PF_NOTIFYCALLBACK)( unsigned short, unsigned short );
-
-// Typedefs for game client API functions (useful for declaring pointers to these
-// functions within the client for use during GetProcAddress() ops)
//
-typedef NPRESULT (__stdcall *PF_NP_REGISTERWINDOWHANDLE)( HWND );
-typedef NPRESULT (__stdcall *PF_NP_UNREGISTERWINDOWHANDLE)( void );
-typedef NPRESULT (__stdcall *PF_NP_REGISTERPROGRAMPROFILEID)( unsigned short );
-typedef NPRESULT (__stdcall *PF_NP_QUERYVERSION)( unsigned short* );
-typedef NPRESULT (__stdcall *PF_NP_REQUESTDATA)( unsigned short );
-typedef NPRESULT (__stdcall *PF_NP_GETDATA)( LPTRACKIRDATA );
-typedef NPRESULT (__stdcall *PF_NP_REGISTERNOTIFY)( PF_NOTIFYCALLBACK );
-typedef NPRESULT (__stdcall *PF_NP_UNREGISTERNOTIFY)( void );
-typedef NPRESULT (__stdcall *PF_NP_STARTCURSOR)( void );
-typedef NPRESULT (__stdcall *PF_NP_STOPCURSOR)( void );
-typedef NPRESULT (__stdcall *PF_NP_STARTDATATRANSMISSION)( void );
-typedef NPRESULT (__stdcall *PF_NP_STOPDATATRANSMISSION)( void );
+//// Typedefs for game client API functions (useful for declaring pointers to these
+//// functions within the client for use during GetProcAddress() ops)
+////
+//typedef NPRESULT (__stdcall *PF_NP_REGISTERWINDOWHANDLE)( HWND );
+//typedef NPRESULT (__stdcall *PF_NP_UNREGISTERWINDOWHANDLE)( void );
+//typedef NPRESULT (__stdcall *PF_NP_REGISTERPROGRAMPROFILEID)( unsigned short );
+//typedef NPRESULT (__stdcall *PF_NP_QUERYVERSION)( unsigned short* );
+//typedef NPRESULT (__stdcall *PF_NP_REQUESTDATA)( unsigned short );
+//typedef NPRESULT (__stdcall *PF_NP_GETDATA)( LPTRACKIRDATA );
+//typedef NPRESULT (__stdcall *PF_NP_REGISTERNOTIFY)( PF_NOTIFYCALLBACK );
+//typedef NPRESULT (__stdcall *PF_NP_UNREGISTERNOTIFY)( void );
+//typedef NPRESULT (__stdcall *PF_NP_STARTCURSOR)( void );
+//typedef NPRESULT (__stdcall *PF_NP_STOPCURSOR)( void );
+//typedef NPRESULT (__stdcall *PF_NP_STARTDATATRANSMISSION)( void );
+//typedef NPRESULT (__stdcall *PF_NP_STOPDATATRANSMISSION)( void );
//// Function Prototypes ///////////////////////////////////////////////
//
diff --git a/FaceTrackNoIR/FTServer.h b/FaceTrackNoIR/FTServer.h
index ba1dfeb2..68b0cabb 100644
--- a/FaceTrackNoIR/FTServer.h
+++ b/FaceTrackNoIR/FTServer.h
@@ -37,7 +37,7 @@
#include <QFile>
#include <QApplication>
#include <QDebug>
-#include <QThread>
+//#include <QThread>
#include <QMutex>
#include <QLibrary>
#include <QUdpSocket>
diff --git a/FaceTrackNoIR/FaceTrackNoIR.cpp b/FaceTrackNoIR/FaceTrackNoIR.cpp
index 4c63d93b..241b27e2 100644
--- a/FaceTrackNoIR/FaceTrackNoIR.cpp
+++ b/FaceTrackNoIR/FaceTrackNoIR.cpp
@@ -538,6 +538,7 @@ void FaceTrackNoIR::stopTracker( ) {
if ( tracker ) {
qDebug() << "stopTracker says: Deleting tracker!";
delete tracker;
+ qDebug() << "stopTracker says: Tracker deleted!";
tracker = 0;
}
ui.btnStartTracker->setEnabled ( true );
@@ -547,6 +548,9 @@ void FaceTrackNoIR::stopTracker( ) {
// Enable/disable Protocol-server Settings
ui.btnShowServerControls->setEnabled ( true );
+
+ timMinimizeFTN->stop();
+
}
/** set the invert from the checkbox **/
diff --git a/FaceTrackNoIR/FaceTrackNoIR.vcproj b/FaceTrackNoIR/FaceTrackNoIR.vcproj
index 4a98b8b3..01a0b679 100644
--- a/FaceTrackNoIR/FaceTrackNoIR.vcproj
+++ b/FaceTrackNoIR/FaceTrackNoIR.vcproj
@@ -116,6 +116,7 @@
>
<Tool
Name="VCPreBuildEventTool"
+ CommandLine="postbuild.bat &quot;$(QTDIR)\plugins\designer\QBezierConfigurator.dll&quot; &quot;$(OutDir)&quot; $(ConfigurationName)"
/>
<Tool
Name="VCCustomBuildTool"
@@ -150,11 +151,11 @@
/>
<Tool
Name="VCLinkerTool"
- AdditionalDependencies="qtmaind.lib QtCored4.lib QtGuid4.lib QtNetworkd4.lib smft31.lib smftcpp.lib smftqt.lib Strmiids.lib"
+ AdditionalDependencies="qtmaind.lib QtCored4.lib QtGuid4.lib QtNetworkd4.lib smft32.lib smftcpp.lib smftqt.lib Strmiids.lib QBezierConfigurator.lib FSUIPC_User.lib"
OutputFile="$(OutDir)\$(ProjectName).exe"
AdditionalLibraryDirectories="$(QTDIR)\lib"
IgnoreAllDefaultLibraries="false"
- IgnoreDefaultLibraryNames="/NODEFAULTLIB:libc.lib;libcmt.lib;libcd.lib;libcmtd;msvcrtd.lib"
+ IgnoreDefaultLibraryNames="libc.lib;libcmt.lib;libcd.lib;libcmtd;msvcrtd.lib"
GenerateDebugInformation="true"
SubSystem="2"
/>
@@ -182,6 +183,7 @@
/>
<Tool
Name="VCPostBuildEventTool"
+ CommandLine="mt.exe -manifest &quot;$(InputDir)SCServer.manifest&quot; -outputresource:&quot;$(OutDir)\$(TargetFileName)&quot;;^#101"
/>
</Configuration>
</Configurations>
diff --git a/FaceTrackNoIR/SCServer.cpp b/FaceTrackNoIR/SCServer.cpp
index d55d11c3..baf3b078 100644
--- a/FaceTrackNoIR/SCServer.cpp
+++ b/FaceTrackNoIR/SCServer.cpp
@@ -30,25 +30,31 @@
SCServer::SCServer() {
ProgramName = "Microsoft FSX";
blnSimConnectActive = false;
- hSimConnect = NULL;
-
- prevPosX = 0.0f;
- prevPosY = 0.0f;
- prevPosZ = 0.0f;
- prevRotX = 0.0f;
- prevRotY = 0.0f;
- prevRotZ = 0.0f;
+ hSimConnect = 0;
+ //prevPosX = 0.0f;
+ //prevPosY = 0.0f;
+ //prevPosZ = 0.0f;
+ //prevRotX = 0.0f;
+ //prevRotY = 0.0f;
+ //prevRotZ = 0.0f;
}
/** destructor **/
SCServer::~SCServer() {
- //
- // Free the DLL
- //
- simconnect_close( hSimConnect );
- SCClientLib.unload();
+ qDebug() << "~SCServer says: inside" << SCServer::hSimConnect;
+
+ if (hSimConnect != 0) {
+ qDebug() << "~SCServer says: before simconnect_close";
+ if (SUCCEEDED( simconnect_close( SCServer::hSimConnect ) ) ) {
+ qDebug() << "~SCServer says: close SUCCEEDED";
+ }
+ }
+
+ qDebug() << "~SCServer says: before unload";
+// SCClientLib.unload();
+ qDebug() << "~SCServer says: finished";
}
//
@@ -57,11 +63,23 @@ SCServer::~SCServer() {
void SCServer::sendHeadposeToGame() {
//
- // It's only usefull to send data, if the connection was made.
+ // It's only useful to send data, if the connection was made.
//
if (!blnSimConnectActive) {
if (SUCCEEDED(simconnect_open(&hSimConnect, "FaceTrackNoIR", NULL, 0, 0, 0))) {
- qDebug() << "SCServer::run() says: SimConnect active!";
+ qDebug() << "SCServer::sendHeadposeToGame() says: SimConnect active!";
+
+ //set up the events we want to listen for
+ HRESULT hr;
+
+ simconnect_subscribetosystemevent(hSimConnect, EVENT_PING, "Frame");
+
+ hr = simconnect_mapclienteventtosimevent(hSimConnect, EVENT_INIT, "");
+ hr = simconnect_addclienteventtonotificationgroup(hSimConnect, GROUP0, EVENT_INIT, false);
+ hr = simconnect_setnotificationgrouppriority(hSimConnect, GROUP0, SIMCONNECT_GROUP_PRIORITY_HIGHEST);
+ ////hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "VK_COMMA", EVENT_INIT);
+ ////hr = SimConnect_SetInputGroupState(hSimConnect, INPUT0, SIMCONNECT_STATE_ON);
+
blnSimConnectActive = true;
}
}
@@ -84,6 +102,8 @@ void SCServer::sendHeadposeToGame() {
prevRotX = virtRotX;
prevRotY = virtRotY;
prevRotZ = virtRotZ;
+
+ simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, NULL);
}
}
@@ -160,23 +180,139 @@ bool SCServer::checkServerInstallationOK( HANDLE handle )
//
simconnect_open = (importSimConnect_Open) SCClientLib.resolve("SimConnect_Open");
if (simconnect_open == NULL) {
- qDebug() << "SCServer::run() says: SimConnect_Open function not found in DLL!";
+ qDebug() << "SCServer::checkServerInstallationOK() says: SimConnect_Open function not found in DLL!";
return false;
}
simconnect_set6DOF = (importSimConnect_CameraSetRelative6DOF) SCClientLib.resolve("SimConnect_CameraSetRelative6DOF");
if (simconnect_set6DOF == NULL) {
- qDebug() << "SCServer::run() says: SimConnect_CameraSetRelative6DOF function not found in DLL!";
+ qDebug() << "SCServer::checkServerInstallationOK() says: SimConnect_CameraSetRelative6DOF function not found in DLL!";
return false;
}
simconnect_close = (importSimConnect_Close) SCClientLib.resolve("SimConnect_Close");
if (simconnect_close == NULL) {
- qDebug() << "SCServer::run() says: SimConnect_Close function not found in DLL!";
+ qDebug() << "SCServer::checkServerInstallationOK() says: SimConnect_Close function not found in DLL!";
+ return false;
+ }
+
+ //return true;
+
+ simconnect_calldispatch = (importSimConnect_CallDispatch) SCClientLib.resolve("SimConnect_CallDispatch");
+ if (simconnect_calldispatch == NULL) {
+ qDebug() << "SCServer::checkServerInstallationOK() says: SimConnect_CallDispatch function not found in DLL!";
+ return false;
+ }
+
+ simconnect_subscribetosystemevent = (importSimConnect_SubscribeToSystemEvent) SCClientLib.resolve("SimConnect_SubscribeToSystemEvent");
+ if (simconnect_subscribetosystemevent == NULL) {
+ qDebug() << "SCServer::checkServerInstallationOK() says: SimConnect_SubscribeToSystemEvent function not found in DLL!";
+ return false;
+ }
+
+ simconnect_mapclienteventtosimevent = (importSimConnect_MapClientEventToSimEvent) SCClientLib.resolve("SimConnect_MapClientEventToSimEvent");
+ if (simconnect_subscribetosystemevent == NULL) {
+ qDebug() << "SCServer::checkServerInstallationOK() says: SimConnect_MapClientEventToSimEvent function not found in DLL!";
+ return false;
+ }
+
+ simconnect_addclienteventtonotificationgroup = (importSimConnect_AddClientEventToNotificationGroup) SCClientLib.resolve("SimConnect_AddClientEventToNotificationGroup");
+ if (simconnect_subscribetosystemevent == NULL) {
+ qDebug() << "SCServer::checkServerInstallationOK() says: SimConnect_AddClientEventToNotificationGroup function not found in DLL!";
return false;
}
- qDebug() << "SCServer::run() says: SimConnect functions resolved in DLL!";
+ simconnect_setnotificationgrouppriority = (importSimConnect_SetNotificationGroupPriority) SCClientLib.resolve("SimConnect_SetNotificationGroupPriority");
+ if (simconnect_subscribetosystemevent == NULL) {
+ qDebug() << "SCServer::checkServerInstallationOK() says: SimConnect_SetNotificationGroupPriority function not found in DLL!";
+ return false;
+ }
+
+ qDebug() << "SCServer::checkServerInstallationOK() says: SimConnect functions resolved in DLL!";
return true;
}
+//
+// Get the program-name from the client (Game!).
+//
+QString SCServer::GetProgramName() {
+QString *str;
+
+ str = new QString("FSX");
+ return *str;
+}
+
+
+void CALLBACK SCServer::processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)
+{
+// HRESULT hr;
+
+ switch(pData->dwID)
+ {
+ case SIMCONNECT_RECV_ID_EVENT:
+ {
+ SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*)pData;
+
+ qDebug() << "SCServer::processNextSimconnectEvent() says: SimConnect active!";
+ //switch(evt->uEventID)
+ //{
+ // //case EVENT_CAMERA_RIGHT:
+
+ // // cameraBank = normalize180( cameraBank + 5.0f);
+
+ // // hr = SimConnect_CameraSetRelative6DOF(hSimConnect, 0.0f, 0.0f, 0.0f,
+ // // SIMCONNECT_CAMERA_IGNORE_FIELD,SIMCONNECT_CAMERA_IGNORE_FIELD, cameraBank);
+
+ // // printf("\nCamera Bank = %f", cameraBank);
+ // // break;
+
+ // //case EVENT_CAMERA_LEFT:
+ // //
+ // // cameraBank = normalize180( cameraBank - 5.0f);
+
+ // // hr = SimConnect_CameraSetRelative6DOF(hSimConnect, 0.0f, 0.0f, 0.0f,
+ // // SIMCONNECT_CAMERA_IGNORE_FIELD,SIMCONNECT_CAMERA_IGNORE_FIELD, cameraBank);
+ // //
+ // // printf("\nCamera Bank = %f", cameraBank);
+ // // break;
+
+ // //default:
+ // // break;
+ //}
+ //break;
+ }
+ case SIMCONNECT_RECV_ID_EVENT_FRAME:
+ {
+ qDebug() << "SCServer::processNextSimconnectEvent() says: Frame event!";
+ }
+
+ case SIMCONNECT_RECV_ID_EXCEPTION:
+ {
+ SIMCONNECT_RECV_EXCEPTION *except = (SIMCONNECT_RECV_EXCEPTION*)pData;
+
+ switch (except->dwException)
+ {
+ case SIMCONNECT_EXCEPTION_ERROR:
+ printf("\nCamera error");
+ break;
+
+ default:
+ printf("\nException");
+ break;
+ }
+ break;
+ }
+
+ case SIMCONNECT_RECV_ID_QUIT:
+ {
+ qDebug() << "SCServer::processNextSimconnectEvent() says: Quit event!";
+// quit = 1;
+ break;
+ }
+
+ default:
+ break;
+ }
+}
+
+
//END
diff --git a/FaceTrackNoIR/SCServer.h b/FaceTrackNoIR/SCServer.h
index eea55376..b48a9a07 100644
--- a/FaceTrackNoIR/SCServer.h
+++ b/FaceTrackNoIR/SCServer.h
@@ -29,28 +29,47 @@
//
#define SIMCONNECT_H_NOMANIFEST
#include "FTNoIR_cxx_protocolserver.h"
-#include "Windows.h"
-#include <stdlib.h>
+//#include "Windows.h"
+//#include <stdlib.h>
#include "SimConnect.h"
+#include <QApplication>
#include <QString>
#include <QMessageBox>
#include <QSettings>
#include <QFile>
-#include <QApplication>
#include <QDebug>
-#include <QThread>
-#include <QMutex>
#include <QLibrary>
typedef HRESULT (WINAPI *importSimConnect_Open)(HANDLE * phSimConnect, LPCSTR szName, HWND hWnd, DWORD UserEventWin32, HANDLE hEventHandle, DWORD ConfigIndex);
typedef HRESULT (WINAPI *importSimConnect_Close)(HANDLE hSimConnect);
typedef HRESULT (WINAPI *importSimConnect_CameraSetRelative6DOF)(HANDLE hSimConnect, float fDeltaX, float fDeltaY, float fDeltaZ, float fPitchDeg, float fBankDeg, float fHeadingDeg);
+typedef HRESULT (WINAPI *importSimConnect_CallDispatch)(HANDLE hSimConnect, DispatchProc pfcnDispatch, void * pContext);
+typedef HRESULT (WINAPI *importSimConnect_SubscribeToSystemEvent)(HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID EventID, const char * SystemEventName);
+typedef HRESULT (WINAPI *importSimConnect_MapClientEventToSimEvent)(HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID EventID, const char * EventName);
+typedef HRESULT (WINAPI *importSimConnect_AddClientEventToNotificationGroup)(HANDLE hSimConnect, SIMCONNECT_NOTIFICATION_GROUP_ID GroupID, SIMCONNECT_CLIENT_EVENT_ID EventID, BOOL bMaskable);
+typedef HRESULT (WINAPI *importSimConnect_SetNotificationGroupPriority)(HANDLE hSimConnect, SIMCONNECT_NOTIFICATION_GROUP_ID GroupID, DWORD uPriority);
using namespace std;
using namespace v4friend::ftnoir;
static const char* SC_CLIENT_FILENAME = "SimConnect.dll";
+enum GROUP_ID
+{
+ GROUP0=0,
+};
+
+enum EVENT_ID
+{
+ EVENT_PING=0,
+ EVENT_INIT,
+};
+
+enum INPUT_ID
+{
+ INPUT0=0,
+};
+
class SCServer : public ProtocolServerBase {
Q_OBJECT
@@ -60,9 +79,10 @@ public:
SCServer();
~SCServer();
+ QString GetProgramName();
+
// protected member methods
protected:
-// void run();
bool checkServerInstallationOK( HANDLE handle );
void sendHeadposeToGame();
@@ -71,13 +91,19 @@ private:
QString ProgramName;
QLibrary SCClientLib;
- bool blnSimConnectActive;
- HANDLE hSimConnect; // Handle to SimConnect
importSimConnect_Open simconnect_open; // SimConnect function(s) in DLL
importSimConnect_Close simconnect_close;
importSimConnect_CameraSetRelative6DOF simconnect_set6DOF;
+ importSimConnect_CallDispatch simconnect_calldispatch;
+ importSimConnect_SubscribeToSystemEvent simconnect_subscribetosystemevent;
+ importSimConnect_MapClientEventToSimEvent simconnect_mapclienteventtosimevent;
+ importSimConnect_AddClientEventToNotificationGroup simconnect_addclienteventtonotificationgroup;
+ importSimConnect_SetNotificationGroupPriority simconnect_setnotificationgrouppriority;
-float prevPosX, prevPosY, prevPosZ, prevRotX, prevRotY, prevRotZ;
+ HANDLE hSimConnect; // Handle to SimConnect
+ static void CALLBACK processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext);
+
+ bool blnSimConnectActive;
public:
void setVirtRotX(float rot) { virtRotX = -1.0f * rot; } // degrees
@@ -87,6 +113,8 @@ public:
void setVirtPosX(float pos) { virtPosX = pos/100.f; } // cm to meters
void setVirtPosY(float pos) { virtPosY = pos/100.f; }
void setVirtPosZ(float pos) { virtPosZ = -1.0f * pos/100.f; }
+
+
};
diff --git a/FaceTrackNoIR/tracker.cpp b/FaceTrackNoIR/tracker.cpp
index a43acd9a..a0154788 100644
--- a/FaceTrackNoIR/tracker.cpp
+++ b/FaceTrackNoIR/tracker.cpp
@@ -85,37 +85,47 @@ Tracker::Tracker( int clientID, int facetrackerID ) {
Tracker::hTrackMutex = CreateMutexA(NULL, false, "HeadPose_mutex");
- try {
- // Initialize the faceAPI Qt library
- sm::faceapi::qt::initialize();
- smLoggingSetFileOutputEnable( false );
+ switch (selectedTracker) {
+ case FT_SM_FACEAPI:
+ try {
+ // Initialize the faceAPI Qt library
+ sm::faceapi::qt::initialize();
+ smLoggingSetFileOutputEnable( false );
- // Initialize the API
- faceapi_scope = new APIScope;
+ // Initialize the API
+ faceapi_scope = new APIScope;
- // Create head-tracking engine v2 using first detected webcam
- CameraInfo::registerType(SM_API_CAMERA_TYPE_WDM);
- _engine = QSharedPointer<HeadTrackerV2>(new HeadTrackerV2());
+ // Create head-tracking engine v2 using first detected webcam
+ CameraInfo::registerType(SM_API_CAMERA_TYPE_WDM);
+ _engine = QSharedPointer<HeadTrackerV2>(new HeadTrackerV2());
- // starts the faceapi engine
- _engine->start();
- }
- catch (sm::faceapi::Error &e)
- {
- /* ERROR with camera */
- QMessageBox::warning(0,"faceAPI Error",e.what(),QMessageBox::Ok,QMessageBox::NoButton);
+ // starts the faceapi engine
+ _engine->start();
+ }
+ catch (sm::faceapi::Error &e)
+ {
+ /* ERROR with camera */
+ QMessageBox::warning(0,"faceAPI Error",e.what(),QMessageBox::Ok,QMessageBox::NoButton);
+ }
+ break;
+ case FT_FTNOIR:
+ break;
+
+ default:
+ break;
}
+
//
// Initialize all server-handles. Only start the server, that was selected in the GUI.
//
switch (selectedClient) {
case FREE_TRACK:
- server_Game = QSharedPointer<FTServer>(new FTServer ( )); // Create Free-track protocol-server
+ server_Game = QSharedPointer<FTServer>(new FTServer ( )); // Create Free-track protocol-server
break;
case FLIGHTGEAR:
- server_Game = QSharedPointer<FGServer>(new FGServer ( this )); // Create FlightGear protocol-server
+ server_Game = QSharedPointer<FGServer>(new FGServer ( this )); // Create FlightGear protocol-server
break;
case FTNOIR:
@@ -126,15 +136,15 @@ Tracker::Tracker( int clientID, int facetrackerID ) {
break;
case TRACKIR:
- server_Game = QSharedPointer<FTIRServer>(new FTIRServer ( )); // Create Fake-TIR protocol-server
+ server_Game = QSharedPointer<FTIRServer>(new FTIRServer ( )); // Create Fake-TIR protocol-server
break;
case SIMCONNECT:
- server_Game = QSharedPointer<SCServer>(new SCServer ( )); // Create SimConnect protocol-server
+ server_Game = QSharedPointer<SCServer>(new SCServer ( )); // Create SimConnect protocol-server
break;
case FSUIPC:
- server_Game = QSharedPointer<FSUIPCServer>(new FSUIPCServer ( )); // Create FSUIPC protocol-server
+ server_Game = QSharedPointer<FSUIPCServer>(new FSUIPCServer ( )); // Create FSUIPC protocol-server
break;
default:
@@ -148,11 +158,6 @@ Tracker::Tracker( int clientID, int facetrackerID ) {
/** destructor empty **/
Tracker::~Tracker() {
- // Stop the started server(s)
- if (server_Game) {
- server_Game->deleteLater();
- }
-
// Trigger thread to stop
::SetEvent(m_StopThread);
@@ -162,10 +167,21 @@ Tracker::~Tracker() {
// Close handles
::CloseHandle(m_StopThread);
::CloseHandle(m_WaitThread);
- ::CloseHandle( Tracker::hTrackMutex );
- _engine->stop();
- smAPIQuit();
+ if (Tracker::hTrackMutex != 0) {
+ ::CloseHandle( Tracker::hTrackMutex );
+ }
+
+ if (selectedTracker == FT_SM_FACEAPI) {
+ _engine->stop();
+ smAPIQuit();
+ }
+
+ // Stop the started server(s)
+ if (server_Game) {
+ server_Game->deleteLater();
+ }
+ qDebug() << "Tracker::~Tracker Finished...";
}
@@ -177,13 +193,15 @@ void Tracker::setup(QWidget *head, FaceTrackNoIR *parent) {
headPoseWidget = head;
mainApp = parent;
- //registers the faceapi callback for receiving headpose data **/
- registerHeadPoseCallback();
+ if (selectedTracker == FT_SM_FACEAPI) {
+ //registers the faceapi callback for receiving headpose data **/
+ registerHeadPoseCallback();
- // some parameteres [optional]
- smHTSetHeadPosePredictionEnabled( _engine->handle(), false);
- smHTSetLipTrackingEnabled( _engine->handle(), false);
- smLoggingSetFileOutputEnable( false );
+ // some parameteres [optional]
+ smHTSetHeadPosePredictionEnabled( _engine->handle(), false);
+ smHTSetLipTrackingEnabled( _engine->handle(), false);
+ smLoggingSetFileOutputEnable( false );
+ }
// set up the line edits for calling
headXLine = headPoseWidget->findChild<QLineEdit *>("headXLine");
@@ -203,9 +221,6 @@ void Tracker::setup(QWidget *head, FaceTrackNoIR *parent) {
DLL_Ok = server_Game->checkServerInstallationOK( mainApp->winId() );
if (!DLL_Ok) {
-// server_Game->start(); // Start the thread
- //}
- //else {
QMessageBox::information(mainApp, "FaceTrackNoIR error", "Protocol is not (correctly) installed!");
}
@@ -267,6 +282,7 @@ void Tracker::run() {
// Set event
::SetEvent(m_WaitThread);
+ qDebug() << "Tracker::run terminated run()";
return;
}
@@ -507,7 +523,7 @@ void Tracker::run() {
server_Game->setHeadPosZ( posZ );
}
- // FlightGear
+ // All Protocol server(s)
if (server_Game) {
server_Game->setVirtRotX ( rotX ); // degrees
server_Game->setVirtRotY ( rotY );
@@ -614,11 +630,7 @@ bool Tracker::handleGameCommand ( int command ) {
switch ( command ) {
case 1: // reset headtracker
- if ( _engine ) {
- _engine->stop();
- Tracker::set_initial = false;
- _engine->start();
- }
+ Tracker::do_center = true;
break;
default:
break;
diff --git a/FaceTrackNoIR/tracker.h b/FaceTrackNoIR/tracker.h
index 6a3fca93..18c629de 100644
--- a/FaceTrackNoIR/tracker.h
+++ b/FaceTrackNoIR/tracker.h
@@ -182,6 +182,7 @@ public:
~Tracker();
void setup(QWidget *head, FaceTrackNoIR *parent);
+
void registerHeadPoseCallback();
bool handleGameCommand ( int command );
QString getGameProgramName(); // Get the ProgramName from the game and display it.