Home › Forums › Software Development › Checking whether if the eye tracker is connected › Reply To: Checking whether if the eye tracker is connected
Hello again,
I tried to use the state-change handler and I have an error. Here’s what I do :
success = txCreateGlobalInteractorSnapshot(
_context,
InteractorId,
&g_hGlobalInteractorSnapshot,
&hInteractor) == TX_RESULT_OK;
success &= txCreateGazePointDataBehavior(hInteractor, ¶ms) == TX_RESULT_OK;
success &= txCreateStateBag(_context, &hStateBag, TX_STATEPATH_EYETRACKINGSTATE) == TX_RESULT_OK;
First I create a state bag in my context. Everything is going well at this point but I show you in case I don’t do it the right way. Then I register my State Handler :
bool EyeXHost::RegisterStateChangedHandler()
{
auto stateChangedTrampoline = [](TX_CONSTHANDLE hState, TX_USERPARAM userParam)
{
static_cast<EyeXHost*>(userParam)->OnEngineStateChanged(hState);
};
bool success = txRegisterStateChangedHandler(_context, &_stateChangedTicket, TX_STATEPATH_USERPRESENCE, stateChangedTrampoline, this) == TX_RESULT_OK;
return success;
}
Same way that I do for the engine connection which works fine. Then on the method OnEngineStateChanged :
void EyeXHost::OnEngineStateChanged(TX_CONSTHANDLE hState)
{
TX_HANDLE hStateBag = TX_EMPTY_HANDLE;
TX_BOOL success;
TX_INTEGER eyeTrackingState;
txGetAsyncDataContent(hState, &hStateBag);
success = txGetStateValueAsInteger(hStateBag, TX_STATEPATH_EYETRACKINGSTATE, &eyeTrackingState) == TX_RESULT_OK;
if (success) {
switch (eyeTrackingState) {
case TX_EYETRACKINGDEVICESTATUS_TRACKING:
printf("Eye Tracking Device Status: 'CONNECTED'");
connectionSuccess = true;
break;
case TX_EYETRACKINGDEVICESTATUS_DEVICENOTCONNECTED:
printf("Eye Tracking Device Status: 'NOT CONNECTED'");
connectionSuccess = false;
break;
default:
connectionSuccess = true;
}
}
else
printf("ERROR");
txReleaseObject(&hStateBag);
}
At this point I always get “ERROR”. But I don’t really understand why txGetStateValueAsInteger won’t return true. It works with the interactor and the Engine Connection callback so I’m not really sure where that come from. If you have any idea it would be great. Sorry if it’s a simple mistake.