private IEnumerator CheckForHeadsetCoroutine() { var wait = new WaitForSecondsRealtime(0.5f); while (true) { ErrorCode err; err = m_headset.IsHardwareConnected(out m_isHmdConnected); if (err != ErrorCode.None && err != ErrorCode.Connect_NotConnected) { Debug.Log("An error occurred checking for hardware connected: " + err); } if (m_isHmdConnected) { break; } // Try again in a half second yield return(wait); } Debug.Log("Connected to FOVE hardware."); StartCoroutine(FoveUpdateCoroutine()); }
private bool UpdateHmdDataInternal() { var isHmdConnectedChanged = false; // First chech and update the HMD connection status // If the HMD happens to be disconnected we trigger the associated event and abort the update process // If the HMD status changed to connected, we delay the trigger of the associated event after the update of other data { var isHmdConnected = Headset.IsHardwareConnected(); if (isHmdConnected.error == ErrorCode.Hardware_Disconnected) // this returns an error whereas it is was we are querying, so we just ignore it... { isHmdConnected.error = ErrorCode.None; } if (isHmdConnected != wasHardwareConnected) { isHmdConnectedChanged = true; wasHardwareConnected = isHmdConnected; if (!isHmdConnected) { // trigger the hmd disconnected event before returning var handler = HardwareDisconnected; if (handler != null) { handler.Invoke(); } return(false); // abort the update and mark it as failure } } } // Fetch the new eye tracking data from the service var fetchResult = Headset.FetchEyeTrackingData(); if (fetchResult.error == ErrorCode.Connect_NotConnected) { return(false); } // Fetch the new pose data from the service fetchResult = Headset.FetchPoseData(); if (fetchResult.error == ErrorCode.Connect_NotConnected) { return(false); } // HMD pose // It is taken from the UnityFunction native plugin to be sure to return // the same pose as the one used to perform the rendering hmdPose = UnityFuncs.GetLastPose(); headPosition = hmdPose.position.ToVector3() * worldScale; standingPosition = hmdPose.standingPosition.ToVector3() * worldScale; headRotation = hmdPose.orientation.ToQuaternion(); // Update the eyes & position textures TryUpdateTexture(Headset.GetEyesImage, ref eyesImage, ref eyesTexture); TryUpdateTexture(Headset.GetPositionImage, ref positionImage, ref positionTexture); // update the mirror texture native pointer if is exists // we need this update because of the rolling buffer if (mirrorTexture.value != null) { int dummy; IntPtr texPtr; GetMirrorTexturePtr(out texPtr, out dummy, out dummy); mirrorTexture.value.UpdateExternalTexture(texPtr); } // Call user custom data update callbacks var addInUpdateCallback = AddInUpdate; if (addInUpdateCallback != null) { addInUpdateCallback(); } // Trigger the event callbacks now that have updated all the HMD data if (isHmdConnectedChanged) { if (!wasHardwareConnected) { throw new Exception("Internal error: Unexpected hmd connection status"); } var handler = HardwareConnected; if (handler != null) { handler.Invoke(); } } var hwdReady = IsHardwareReady(); if (hwdReady.IsValid && wasHardwareReady != hwdReady) { wasHardwareReady = hwdReady; var handler = hwdReady ? HardwareIsReady : null; if (handler != null) { handler.Invoke(); } } var isCalibrating = IsEyeTrackingCalibrating(); if (isCalibrating.IsValid && isCalibrating != wasCalibrating) { if (wasCalibrating) { var handler = EyeTrackingCalibrationStarted; if (handler != null) { handler.Invoke(); } } else { var handler = EyeTrackingCalibrationEnded; if (handler != null) { handler.Invoke(GetEyeTrackingCalibrationState()); } } wasCalibrating = isCalibrating; } var userAttention = IsUserShiftingAttention(); if (userAttention.IsValid && wasShiftingAttention != userAttention) { wasShiftingAttention = userAttention; var handler = IsUserShiftingAttentionChanged; if (handler != null) { handler.Invoke(wasShiftingAttention); } } UpdateEyeState(Eye.Left); UpdateEyeState(Eye.Right); var userPresent = IsUserPresent(); if (userPresent.IsValid && wasUserPresent != userPresent) { wasUserPresent = userPresent; var handler = UserPresenceChanged; if (handler != null) { handler.Invoke(wasUserPresent); } } var adjusmentGuiVisible = IsHmdAdjustmentGuiVisible(); if (adjusmentGuiVisible.IsValid && wasHmdAdjustmentVisible != adjusmentGuiVisible) { wasHmdAdjustmentVisible = adjusmentGuiVisible; var handler = HmdAdjustmentGuiVisibilityChanged; if (handler != null) { handler.Invoke(wasHmdAdjustmentVisible); } } return(true); }