Rise
The Vieneo Province
FreeTrack.cpp
Go to the documentation of this file.
1 #include "FreeTrack.h"
2 
3 #include "Viewscreen.h"
4 
6 {
7  viewscreen = prmViewscreen;
9  pData = &data;
10 
11  // load DLL file
12  hinstLib = LoadLibrary(L"FreeTrackClient.dll");
13  if (hinstLib == nullptr)
14  logger->Log("FreeTrack: Unable to load DLL", Logger::Level::Fatal);
15 
16  logger->Log("FreeTrack: DLL loaded!");
17 
18  // get function pointers
19  getData = reinterpret_cast<importGetData>(GetProcAddress(hinstLib, "FTGetData"));
20  getDllVersion = reinterpret_cast<importGetDllVersion>(GetProcAddress(hinstLib, "FTGetDllVersion"));
21  reportID = reinterpret_cast<importReportID>(GetProcAddress(hinstLib, "FTReportName"));
22  provider = reinterpret_cast<importProvider>(GetProcAddress(hinstLib, "FTProvider"));
23 
24  // check they are valid
25  if (getData == nullptr)
26  logger->Log("FreeTrack: Unable to find 'FTGetData' function", Logger::Level::Fatal);
27  if (getDllVersion == nullptr)
28  logger->Log("FreeTrack: Unable to find 'FTGetDllVersion' function", Logger::Level::Fatal);
29  if (reportID == nullptr)
30  logger->Log("FreeTrack: Unable to find 'FTReportID' function", Logger::Level::Fatal);
31  if (reportID == nullptr)
32  logger->Log("FreeTrack: Unable to find 'FTProvider' function", Logger::Level::Fatal);
33 
34  // print the address of each function
35  char msg[99];
36  sprintf_s(msg, 99, "FreeTrack: FTGetData is at address: 0x%p", getData);
37  logger->Log(msg);
38  sprintf_s(msg, 99, "FreeTrack: FTGetDllVersion is at address: 0x%p", getDllVersion);
39  logger->Log(msg);
40  sprintf_s(msg, 99, "FreeTrack: FTReportID is at address: 0x%p", reportID);
41  logger->Log(msg);
42  sprintf_s(msg, 99, "FreeTrack: FTProvider is at address: 0x%p", provider);
43  logger->Log(msg);
44 
45  // call each function and display result
46  sprintf_s(msg, 99, "FreeTrack: DLL Version: %s", getDllVersion());
47  logger->Log(msg);
48 }
49 
51 {
52  try
53  {
54  if (getData(pData))
55  {
59 
60  // 30 cm (11.811 inches) gives us a value of 75 by default? converted to km
61  x = -pData->x * 0.0000004f;
62  y = -pData->z * 0.0000004f;
63  z = pData->y * 0.0000004f;
64  }
65  }
66  catch (...)
67  {
68  logger->Log("FreeTrack: Poll unhandled exception!", Logger::Level::Error);
69  }
70 }
71 
73 {
74  if (!hinstLib)
75  return;
76 
77  // unload DLL file
78  FreeLibrary(hinstLib);
79 }
float rolltilt
Definition: Viewscreen.h:313
Logger * logger
Definition: FreeTrack.h:27
float targetLeftright
Definition: Viewscreen.h:311
void Poll()
Definition: FreeTrack.cpp:50
bool(WINAPI * importGetData)(FreeTrackData *data)
Definition: FreeTrack.h:64
char *(WINAPI * importGetDllVersion)()
Definition: FreeTrack.h:65
HINSTANCE hinstLib
Definition: FreeTrack.h:29
importReportID reportID
Definition: FreeTrack.h:72
importProvider provider
Definition: FreeTrack.h:73
char *(WINAPI * importProvider)()
Definition: FreeTrack.h:67
float x
Definition: FreeTrack.h:80
Viewscreen * viewscreen
Definition: FreeTrack.h:26
importGetData getData
Definition: FreeTrack.h:70
void(WINAPI * importReportID)(int name)
Definition: FreeTrack.h:66
float targetUpdown
Definition: Viewscreen.h:312
float z
Definition: FreeTrack.h:80
FreeTrackData data
Definition: FreeTrack.h:76
importGetDllVersion getDllVersion
Definition: FreeTrack.h:71
float y
Definition: FreeTrack.h:80
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition: Logger.cpp:11
FreeTrack(Viewscreen *prmViewscreen)
Definition: FreeTrack.cpp:5
FreeTrackData * pData
Definition: FreeTrack.h:77
Logger * logger
Definition: Viewscreen.h:293