From 010d82e9392bd2fb5cafe6fbae03c9cdc301a2f8 Mon Sep 17 00:00:00 2001 From: Wim Vriend Date: Sat, 4 Jun 2011 12:37:46 +0000 Subject: Eagle Dynamics API implemented, added some 'nice to haves'. git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@87 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb --- FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.cpp | 57 ++++++++++++++++++++++++++----- FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.h | 4 +++ FTNoIR_Protocol_FT/FTTypes.h | 5 +++ 3 files changed, 57 insertions(+), 9 deletions(-) (limited to 'FTNoIR_Protocol_FT') diff --git a/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.cpp b/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.cpp index 4d0ef950..e6100956 100644 --- a/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.cpp +++ b/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.cpp @@ -39,6 +39,7 @@ /** constructor **/ FTNoIR_Protocol_FT::FTNoIR_Protocol_FT() { + comhandle = 0; loadSettings(); ProgramName = ""; } @@ -54,7 +55,7 @@ FTNoIR_Protocol_FT::~FTNoIR_Protocol_FT() // // Free the DLL's // - FTClientLib.unload(); + //////FTClientLib.unload(); } /** helper to Auto-destruct **/ @@ -94,6 +95,9 @@ float headRotX; float headRotY; float headRotZ; +PDWORD_PTR MsgResult = 0; + + // // Scale the Raw measurements to the client measurements. // @@ -149,6 +153,19 @@ float headRotZ; //qDebug() << "FTServer says: pMemData.DataID =" << pMemData->data.DataID; //qDebug() << "FTServer says: ProgramName =" << pMemData->ProgramName; + + // + // Check if the handle that was sent to the Game, was changed (on x64, this will be done by the ED-API) + // If the "Report Program Name" command arrives (which is a '1', for now), raise the event from here! + // + if (hMainWindow != pMemData->handle) { // Handle in memory-mapping was changed! + comhandle = (__int32) pMemData->handle; // Get the command from the Game. + if (comhandle == 1) { // "Report Program Name" + SendMessageTimeout( (HWND) hMainWindow, RegisterWindowMessageA(FT_PROGRAMID), 0, 0, 0, 2000, MsgResult); + pMemData->handle = 0; // Reset the command, to enable future commands... + } + } + ReleaseMutex(hFTMutex); } @@ -198,13 +215,13 @@ bool FTNoIR_Protocol_FT::checkServerInstallationOK( HANDLE handle ) // // Load the DLL and map to the functions in it. // - FTClientLib.setFileName(aFileName); - FTClientLib.load(); - provider = (importProvider) FTClientLib.resolve("FTProvider"); - if (provider) { - pProvider = provider(); - qDebug() << "FTCheckClientDLL says: Provider =" << pProvider; - } + ////////FTClientLib.setFileName(aFileName); + ////////FTClientLib.load(); + ////////provider = (importProvider) FTClientLib.resolve("FTProvider"); + ////////if (provider) { + //////// pProvider = provider(); + //////// qDebug() << "FTCheckClientDLL says: Provider =" << pProvider; + ////////} } else { QMessageBox::information(0, "FaceTrackNoIR error", QString("Necessary file (FreeTrackClient.dll) was NOT found!\n")); @@ -249,10 +266,11 @@ bool FTNoIR_Protocol_FT::FTCreateMapping( HANDLE handle ) // hFTMemMap = OpenFileMappingA( FILE_MAP_ALL_ACCESS , false , (LPCSTR) FT_MM_DATA ); if ( ( hFTMemMap != 0 ) ) { - qDebug() << "FTCreateMapping says: FileMapping Created again:" << hFTMemMap; + qDebug() << "FTCreateMapping says: FileMapping Opened:" << hFTMemMap; pMemData = (FTMemMap *) MapViewOfFile(hFTMemMap, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(TFreeTrackData) + sizeof(hFTMemMap) + 100); if (pMemData != NULL) { pMemData->handle = handle; // The game uses the handle, to send a message that the Program-Name was set! + hMainWindow = handle; } hFTMutex = CreateMutexA(NULL, false, FREETRACK_MUTEX); } @@ -285,6 +303,27 @@ void FTNoIR_Protocol_FT::FTDestroyMapping() } +// +// Return a name, if present the name from the Game, that is connected... +// +void FTNoIR_Protocol_FT::getNameFromGame( char *dest ) +{ + sprintf_s(dest, 99, "FreeTrack interface"); + + qDebug() << "FTNoIR_Protocol_FT::getNameFromGame says: Started, pMemData = " << pMemData << ", mutex = " << hFTMutex; + + // + // Check if the pointer is OK and wait for the Mutex. + // +// if ( (pMemData != NULL) && (WaitForSingleObject(hFTMutex, 100) == WAIT_OBJECT_0) ) { + if (pMemData != NULL) { + qDebug() << "FTNoIR_Protocol_FT::getNameFromGame says: Inside MemData"; + sprintf_s(dest, 99, "%s", pMemData->ProgramName); + } + + return; +} + //////////////////////////////////////////////////////////////////////////////// // Factory function that creates instances if the Protocol object. diff --git a/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.h b/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.h index 7b23fcba..02e9525f 100644 --- a/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.h +++ b/FTNoIR_Protocol_FT/FTNoIR_Protocol_FT.h @@ -53,6 +53,7 @@ public: bool checkServerInstallationOK( HANDLE handle ); void sendHeadposeToGame( T6DOF *headpose ); + void getNameFromGame( char *dest ); // Take care dest can handle up to 100 chars... private: bool FTCreateMapping(HANDLE handle); @@ -62,6 +63,9 @@ private: FTMemMap *pMemData; HANDLE hFTMutex; + HANDLE hMainWindow; // Save the handle to FaceTrackNoIR main-window + __int32 comhandle; // Handle on x32, command on x64 + // Private properties QString ProgramName; QLibrary FTClientLib; diff --git a/FTNoIR_Protocol_FT/FTTypes.h b/FTNoIR_Protocol_FT/FTTypes.h index a6dcb6c9..c83ce90d 100644 --- a/FTNoIR_Protocol_FT/FTTypes.h +++ b/FTNoIR_Protocol_FT/FTTypes.h @@ -75,7 +75,12 @@ typedef TFreeTrackData * PFreetrackData; struct FTMemMap { TFreeTrackData data; + +#ifdef WIN64 + __int32 command; +#else HANDLE handle; +#endif char ProgramName[100]; }; typedef FTMemMap * PFTMemMap; -- cgit v1.2.3