GeekIMU/4.Software/GeekIMUDriver 1.0/Src/PipeHMD.cpp

105 lines
2.6 KiB
C++

#include <string>
#include <Windows.h>
#include <stdio.h>
#include <conio.h>
#include "PipeHMD.h"
#include "OVR_CAPI.h"
#include <time.h>
//extern void TimeLog(const char* str);
// {
// time_t t = time(0);
// char tmp[100];
// strftime(tmp, sizeof(tmp), "%a %b %d %Y %X - PipeTest Client VR", localtime(&t));
// char cmd[1024];
// //sprintf_s(cmd, "echo %s %s >>d:hmd.txt ", tmp, str);
// //system(cmd);
// sprintf_s(cmd, "echo %s %s >>d:pipetest.txt ", tmp, str);
// system(cmd);
// }
// void TimeLog(const char* str)
// {
// time_t t = time(0);
// char tmp[100];
// strftime(tmp, sizeof(tmp), "%a %b %d %Y %X - PipeTest Client CTL", localtime(&t));
// char cmd[1024];
// //sprintf_s(cmd, "echo %s %s >>d:hmd.txt ", tmp, str);
// //system(cmd);
// sprintf_s(cmd, "echo %s %s >>d:pipetest.txt ", tmp, str);
// system(cmd);
// }
using namespace std;
namespace DMPipe
{
PipeHMD::PipeHMD(string sname) :m_hPipe(INVALID_HANDLE_VALUE)
{
this->name = sname;
}
PipeHMD::~PipeHMD()
{
PipeHMD::Free();
}
BOOL PipeHMD::IsOpen()
{
unsigned int* temp_uint;
memset(reciveBuf, 0, sizeof(BOOL));
BOOL * result = (BOOL *)&reciveBuf[0];
result[0] = FALSE;
temp_uint = (unsigned int*)&writeBuf[0];
temp_uint[0] = COMMAND_DEVICE_IS_OPEN;
temp_uint[1] = 0;
temp_uint[2] = 0;
PipeProcess(sizeof(BOOL));
return result[0];
}
ovrSensorState PipeHMD::GetSensorData()
{
unsigned int* temp_uint;
memset(reciveBuf, 0, sizeof(BOOL));
ovrSensorState * result = (ovrSensorState *)&reciveBuf[0];
temp_uint = (unsigned int*)&writeBuf[0];
temp_uint[0] = COMMAND_GET_DATA;
temp_uint[1] = 0;
temp_uint[2] = 0;
PipeProcess(sizeof(ovrSensorState));
return result[0];
}
SensorPureData PipeHMD::GetPureSensorData()
{
memset(reciveBuf, 0, sizeof(BOOL));
SensorPureData * result = (SensorPureData *)&reciveBuf[0];
return result[0];
}
BOOL PipeHMD::EnterDFUMode()
{
unsigned int* temp_uint;
memset(reciveBuf, 0, sizeof(BOOL));
BOOL * result = (BOOL *)&reciveBuf[0];
result[0] = FALSE;
temp_uint = (unsigned int*)&writeBuf[0];
temp_uint[0] = COMMAND_DEVICE_ENTER_DFU_MODE;
temp_uint[1] = 0;
temp_uint[2] = 0;
PipeProcess(sizeof(BOOL));
return result[0];
}
BOOL PipeHMD::Calibration()
{
unsigned int* temp_uint;
memset(reciveBuf, 0, sizeof(BOOL));
BOOL * result = (BOOL *)&reciveBuf[0];
result[0] = FALSE;
temp_uint = (unsigned int*)&writeBuf[0];
temp_uint[0] = COMMAND_DEVICE_CALIBRATION;
temp_uint[1] = 0;
temp_uint[2] = 0;
PipeProcess(sizeof(BOOL));
return result[0];
}
void PipeHMD::SetName(string sname)
{
this->name = sname;
}
}