@@ -35,8 +35,11 @@ DLLEXPORT DWORD __stdcall GetControllersData(__out TController *MyController, __
3535DLLEXPORT DWORD __stdcall SetControllerData (__in int dwIndex, __in WORD MotorSpeed);
3636DLLEXPORT DWORD __stdcall SetCentering (__in int dwIndex);
3737
38+ #define TOVR_SUCCESS 1
39+ #define TOVR_FAILURE 0
40+
3841HANDLE hSerial;
39- bool HMDConnected = false , RInit = false ;
42+ bool HMDConnected = false , RazorInit = false , HMDInitCentring = false ;
4043float RazorIMU[3 ], yprOffset[3 ]; // yaw, pitch, roll
4144double fPos [3 ];
4245std::thread *pRRthread = NULL ;
@@ -47,10 +50,15 @@ void RazorIMURead()
4750
4851 while (HMDConnected) {
4952 ReadFile (hSerial, &RazorIMU, sizeof (RazorIMU), &bytesRead, 0 );
53+ if (HMDInitCentring == false )
54+ if (RazorIMU[0 ] != 0 || RazorIMU[1 ] != 0 || RazorIMU[2 ] != 0 ) {
55+ SetCentering (0 );
56+ HMDInitCentring = true ;
57+ }
5058 }
5159}
5260
53- void RazorInit (){
61+ void RazorStart (){
5462 CRegKey key;
5563 TCHAR _driversPath[MAX_PATH];
5664 LONG status = key.Open (HKEY_CURRENT_USER, _T (" Software\\ TrueOpenVR" ));
@@ -95,7 +103,7 @@ void RazorInit(){
95103 }
96104}
97105
98- float MyOffset (float f, float f2)
106+ float OffsetYPR (float f, float f2)
99107{
100108 f -= f2;
101109 if (f < -180 ) {
@@ -135,9 +143,9 @@ BOOL APIENTRY DllMain(HMODULE hModule,
135143
136144DLLEXPORT DWORD __stdcall GetHMDData (__out THMD *myHMD)
137145{
138- if (RInit == false ) {
139- RInit = true ;
140- RazorInit ();
146+ if (RazorInit == false ) {
147+ RazorInit = true ;
148+ RazorStart ();
141149 }
142150
143151 if (HMDConnected) {
@@ -168,11 +176,11 @@ DLLEXPORT DWORD __stdcall GetHMDData(__out THMD *myHMD)
168176 myHMD->X = fPos [0 ];
169177 myHMD->Y = fPos [1 ];
170178 myHMD->Z = fPos [2 ];
171- myHMD->Yaw = MyOffset (RazorIMU[2 ], yprOffset[2 ]);
172- myHMD->Pitch = MyOffset (RazorIMU[0 ], yprOffset[0 ]) * -1 ;
173- myHMD->Roll = MyOffset (RazorIMU[1 ], yprOffset[1 ]) * -1 ;
179+ myHMD->Yaw = OffsetYPR (RazorIMU[2 ], yprOffset[2 ]);
180+ myHMD->Pitch = OffsetYPR (RazorIMU[0 ], yprOffset[0 ]) * -1 ;
181+ myHMD->Roll = OffsetYPR (RazorIMU[1 ], yprOffset[1 ]) * -1 ;
174182
175- return 1 ;
183+ return TOVR_SUCCESS ;
176184 }
177185 else {
178186 myHMD->X = 0 ;
@@ -187,7 +195,7 @@ DLLEXPORT DWORD __stdcall GetHMDData(__out THMD *myHMD)
187195 myHMD->Pitch = 0 ;
188196 myHMD->Roll = 0 ;
189197
190- return 0 ;
198+ return TOVR_FAILURE ;
191199 }
192200}
193201
@@ -221,12 +229,12 @@ DLLEXPORT DWORD __stdcall GetControllersData(__out TController *myController, __
221229 myController2->ThumbX = 0 ;
222230 myController2->ThumbY = 0 ;
223231
224- return 0 ;
232+ return TOVR_FAILURE ;
225233}
226234
227235DLLEXPORT DWORD __stdcall SetControllerData (__in int dwIndex, __in WORD MotorSpeed)
228236{
229- return 0 ;
237+ return TOVR_FAILURE ;
230238}
231239
232240DLLEXPORT DWORD __stdcall SetCentering (__in int dwIndex)
@@ -236,10 +244,10 @@ DLLEXPORT DWORD __stdcall SetCentering(__in int dwIndex)
236244 yprOffset[1 ] = RazorIMU[1 ];
237245 yprOffset[2 ] = RazorIMU[2 ];
238246
239- return 1 ;
247+ return TOVR_SUCCESS ;
240248 }
241249 else {
242- return 0 ;
250+ return TOVR_FAILURE ;
243251 }
244252
245253}
0 commit comments