summaryrefslogtreecommitdiffhomepage
path: root/freetrackclient
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-09-17 12:47:48 +0200
committerStanislaw Halik <sthalik@misaki.pl>2014-09-17 12:47:48 +0200
commit2b50200ca979cbf33d8e67503db341a6f62d1604 (patch)
tree0182422f1c91df3c405bfee58815413662bddd4d /freetrackclient
parent679f424c250a38473c82bf1f997b75fbea4d3758 (diff)
ftclient: compile as C, cleanup
Diffstat (limited to 'freetrackclient')
-rw-r--r--freetrackclient/freetrackclient.c (renamed from freetrackclient/freetrackclient.cpp)95
1 files changed, 11 insertions, 84 deletions
diff --git a/freetrackclient/freetrackclient.cpp b/freetrackclient/freetrackclient.c
index 816e7b65..007d073f 100644
--- a/freetrackclient/freetrackclient.cpp
+++ b/freetrackclient/freetrackclient.c
@@ -20,43 +20,31 @@
#define NP_AXIS_MAX 16383
#include <stdarg.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
-//#include <tchar.h>
#include "ftnoir_protocol_ft/fttypes.h"
-#define FT_EXPORT(t) extern "C" __declspec(dllexport) t __stdcall
+#define FT_EXPORT(t) __declspec(dllexport) t __stdcall
-//
-// Functions to create/open the file-mapping
-// and to destroy it again.
-//
-static float scale2AnalogLimits( float x, float min_x, float max_x );
-static float getDegreesFromRads ( float rads );
FT_EXPORT(bool) FTCreateMapping(void);
#if 0
static FILE *debug_stream = fopen("c:\\FreeTrackClient.log", "a");
#define dbg_report(...) if (debug_stream) { fprintf(debug_stream, __VA_ARGS__); fflush(debug_stream); }
#else
-#define dbg_report(...)
+#define dbg_report(...) ((void)0)
#endif
-//
-// Handles to 'handle' the memory mapping
-//
static HANDLE hFTMemMap = 0;
-static FTMemMap *pMemData = 0;
+static FTHeap *pMemData = 0;
static HANDLE hFTMutex = 0;
static const char* dllVersion = "1.0.0.0";
static const char* dllProvider = "FreeTrack";
-//
-// DllMain gets called, when the DLL is (un)loaded or a process attaches.
-//
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason) {
@@ -80,37 +68,24 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
return TRUE;
}
-/******************************************************************
- * FTGetData (FreeTrackClient.1)
- */
-
-#pragma comment(linker, "/export:FTGetData@4=FTGetData")
-FT_EXPORT(bool) FTGetData(PFreetrackData data)
+FT_EXPORT(bool) FTGetData(FTData* data)
{
// dbg_report("NP_GetData called.");
- if (FTCreateMapping() == false) return false;
+ if (FTCreateMapping() == false)
+ return false;
- if (hFTMutex && WaitForSingleObject(hFTMutex, 5) == WAIT_OBJECT_0) {
+ if (hFTMutex && WaitForSingleObject(hFTMutex, 16) == WAIT_OBJECT_0) {
if (pMemData) {
- //
- // Limit the range of DataID
- //
- if (pMemData->data.DataID > 1000) {
+ if (pMemData->data.DataID > (1 << 29)) {
pMemData->data.DataID = 0;
}
data->DataID = pMemData->data.DataID;
-
}
ReleaseMutex(hFTMutex);
}
return true;
}
-/******************************************************************
- * FTReportName (FreeTrackClient.2)
- */
-#pragma comment(linker, "/export:FTReportName@4=FTReportName")
-//
// For some mysterious reason, the previously existing function FTReportID has been changed to FTReportName, but with an integer as argument.
// The Delphi-code from the FreeTrack repo suggest a char * as argument, so it cost me an afternoon to figure it out (and keep ArmA2 from crashing).
// Thanks guys!
@@ -120,10 +95,6 @@ FT_EXPORT(void) FTReportName( int name )
dbg_report("FTReportName request (ID = %d).\n", name);
}
-/******************************************************************
- * FTGetDllVersion (FreeTrackClient.3)
- */
-#pragma comment(linker, "/export:FTGetDllVersion@0=FTGetDllVersion")
FT_EXPORT(const char*) FTGetDllVersion(void)
{
dbg_report("FTGetDllVersion request.\n");
@@ -131,10 +102,6 @@ FT_EXPORT(const char*) FTGetDllVersion(void)
return dllVersion;
}
-/******************************************************************
- * FTProvider (FreeTrackClient.4)
- */
-#pragma comment(linker, "/export:FTProvider@0=FTProvider")
FT_EXPORT(const char*) FTProvider(void)
{
dbg_report("FTProvider request.\n");
@@ -149,25 +116,14 @@ FT_EXPORT(const char*) FTProvider(void)
//
FT_EXPORT(bool) FTCreateMapping(void)
{
- //
- // Memory-mapping already exists!
- //
if ( pMemData != NULL ) {
return true;
}
dbg_report("FTCreateMapping request (pMemData == NULL).\n");
- //
- // A FileMapping is used to create 'shared memory' between the FTClient and the FTServer.
- //
- // Try to create a FileMapping to the Shared Memory. This is done to check if it's already there (what
- // may mean the face-tracker program is already running).
- //
- // If one already exists: close it and open the file-mapping to the existing one.
- //
hFTMemMap = CreateFileMappingA( INVALID_HANDLE_VALUE , 00 , PAGE_READWRITE , 0 ,
- sizeof( FTMemMap ),
+ sizeof( FTHeap ),
(LPCSTR) FT_MM_DATA );
if (hFTMemMap == NULL)
@@ -176,15 +132,12 @@ FT_EXPORT(bool) FTCreateMapping(void)
return false;
}
- pMemData = (FTMemMap *) MapViewOfFile(hFTMemMap, FILE_MAP_WRITE, 0, 0, sizeof( FTMemMap ) );
+ pMemData = (FTHeap*) MapViewOfFile(hFTMemMap, FILE_MAP_WRITE, 0, 0, sizeof( FTHeap ) );
hFTMutex = CreateMutexA(NULL, false, FREETRACK_MUTEX);
return true;
}
-//
-// Destory the FileMapping to the shared memory
-//
FT_EXPORT(void) FTDestroyMapping(void)
{
if ( pMemData != NULL ) {
@@ -196,29 +149,3 @@ FT_EXPORT(void) FTDestroyMapping(void)
pMemData = 0;
hFTMemMap = 0;
}
-
-//
-// 4 convenience
-//
-static float getDegreesFromRads ( float rads ) {
- return (rads * 57.295781f);
-}
-
-//
-// Scale the measured value to the TIR values
-//
-static float scale2AnalogLimits( float x, float min_x, float max_x ) {
-double y;
-double local_x;
-
- local_x = x;
- if (local_x > max_x) {
- local_x = max_x;
- }
- if (local_x < min_x) {
- local_x = min_x;
- }
- y = ( NP_AXIS_MAX * local_x ) / max_x;
-
- return (float) y;
-}