//protected Peripheralstatus peripheralstatus = null; //protected Peripheralstatus prevperipheralstatus = null; public virtual bool OpenPeripheral(DPNP_DEVICE_TYPE type, int index) { if (DpnDevice._instance == null) { DpnDevice.create(); } #if UNITY_ANDROID && !UNITY_EDITOR if (type == DPNP_DEVICE_TYPE.DPNP_DEVICE_TYPE_HEAD_TRACKER) { peripheral = DpnDevice.OpenPeripheral(string.Empty, this); return(true); } #endif int count = DpnPeripheral.DpnupQueryDeviceCount(type); if (count < 0 || index >= count) { return(false); } string devicename = DpnPeripheral.DpnupGetDeviceId(type, index); if (devicename != null) { return(OpenPeripheral(devicename)); } return(false); }
/// <summary> /// Run DeePoon HMD /// </summary> public static void create() { if (_instance != null) { _instance.gameObject.SetActive(true); return; } #if UNITY_ANDROID && !UNITY_EDITOR _java_activity.Init(); #endif Composer.Init(); //create a new DeviceObject GameObject device_object = new GameObject (Common.DeePoonDeviceGameObjectName , typeof(DpnDevice)); if (DpnManager.DPVRPointer) { GameObject eventSystem = new GameObject("EventSystem", typeof(EventSystem)); eventSystem.AddComponent <DpnPointerInputModule>(); eventSystem.transform.SetParent(device_object.transform); } //Don't destroy it. DontDestroyOnLoad(device_object); //get device _instance = device_object.GetComponent <DpnDevice>(); }
public void ClosePeripheral() { if (peripheral == null) { return; } DpnDevice.ClosePeripheral(this); }
/// <summary> /// Run DeePoon HMD /// </summary> public static void create() { if (_instance != null) { _instance.gameObject.SetActive(true); return; } #if UNITY_ANDROID && !UNITY_EDITOR _java_activity.Init(); #endif Composer.Init(); //create a new DeviceObject GameObject device_object = new GameObject (Common.DeePoonDeviceGameObjectName , typeof(DpnDevice)); if (DpnManager.DPVRPointer) { EventSystem eventSystem = FindObjectOfType <EventSystem>(); if (eventSystem == null) { Debug.LogWarning("DpnEventSystem is needed after version 0.7.5."); GameObject gameObject = new GameObject("DpnEventSystem", typeof(EventSystem)); eventSystem = gameObject.GetComponent <EventSystem>(); } { DpnStandaloneInputModule inputModule = eventSystem.GetComponent <DpnStandaloneInputModule>(); if (inputModule == null) { Debug.LogWarning("DpnStandaloneInputModule component must be in the EventSystem, after version 0.7.5."); eventSystem.gameObject.AddComponent <DpnStandaloneInputModule>(); } } } //Don't destroy it. DontDestroyOnLoad(device_object); //get device _instance = device_object.GetComponent <DpnDevice>(); }
public virtual bool OpenPeripheral(string deviceId) { if (DpnDevice._instance == null) { DpnDevice.create(); } #if UNITY_ANDROID && UNITY_EDITOR if (DpnManager.androidEditorUseHmd) { DpnPeripheral peripheral = DpnDevice.OpenPeripheral(deviceId, this); return(peripheral != null); } else { peripheral = null; return(true); } #else DpnPeripheral peripheral = DpnDevice.OpenPeripheral(deviceId, this); return(peripheral != null); #endif }
public static void DpnpHandleDeviceEvent(IntPtr device, int event_mask, IntPtr user_data) { DpnPeripheral dev = null; foreach (KeyValuePair <string, PeripheralList> i in DpnDevice.GetPeripherals()) { if (i.Value.peripheral._device == device) { dev = i.Value.peripheral; break; } } dev.peripheralstatus.cacheLock.EnterWriteLock(); try { if ((event_mask & ((int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_CONNECT | (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_DISCONNECT | (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_USB_PLUGIN | (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_USB_UNPLUG | (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_HDMI_PLUGIN | (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_HDMI_UNPLUG | (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_BASE_A_TRACK | (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_BASE_A_UNTRACK | (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_BASE_B_TRACK | (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_BASE_B_UNTRACK)) != 0x0) { // set device connection state // if ((event_mask & (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_HDMI_PLUGIN) != 0x0) { dev.peripheralstatus.device_status |= (int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_HDMI_PLUGIN; dev.peripheralstatus.device_status &= ~(int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_HDMI_UNPLUG; } if ((event_mask & (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_USB_PLUGIN) != 0x0) { dev.peripheralstatus.device_status |= (int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_USB_PLUGIN; dev.peripheralstatus.device_status &= ~(int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_USB_UNPLUG; } if ((event_mask & (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_HDMI_UNPLUG) != 0x0) { dev.peripheralstatus.device_status |= (int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_HDMI_UNPLUG; dev.peripheralstatus.device_status &= ~(int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_HDMI_PLUGIN; } if ((event_mask & (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_USB_UNPLUG) != 0x0) { dev.peripheralstatus.device_status |= (int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_USB_UNPLUG; dev.peripheralstatus.device_status &= ~(int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_USB_PLUGIN; } if ((event_mask & (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_BASE_A_TRACK) != 0x0) { dev.peripheralstatus.device_status |= (int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_BASE_A_TRACK; dev.peripheralstatus.device_status &= ~(int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_BASE_A_UNTRACK; } if ((event_mask & (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_BASE_A_UNTRACK) != 0x0) { dev.peripheralstatus.device_status |= (int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_BASE_A_UNTRACK; dev.peripheralstatus.device_status &= ~(int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_BASE_A_TRACK; } if ((event_mask & (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_BASE_B_TRACK) != 0x0) { dev.peripheralstatus.device_status |= (int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_BASE_B_TRACK; dev.peripheralstatus.device_status &= ~(int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_BASE_B_UNTRACK; } if ((event_mask & (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_BASE_B_UNTRACK) != 0x0) { dev.peripheralstatus.device_status |= (int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_BASE_B_UNTRACK; dev.peripheralstatus.device_status &= ~(int)DPNP_DEVICE_STATUS.DPNP_DEVICE_STATUS_BASE_B_TRACK; } } if (((event_mask & (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_POSE_UPDATE) != 0) && (dev.peripheralInfo.pose_count > 0)) { for (int i = 0; i < dev.peripheralInfo.pose_count; i++) { float[] pose = dev.peripheralstatus.pose_state[i]; dev.DpnupReadDevicePose(i, pose); } } if (((event_mask & (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_POSITION_UPDATE) != 0) && (dev.peripheralInfo.position_count > 0)) { for (int i = 0; i < dev.peripheralInfo.position_count; i++) { float[] position = dev.peripheralstatus.position_state[i]; dev.DpnupReadDevicePosition(i, position); } } if (((event_mask & (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_TIME_UPDATE) != 0) && (dev.peripheralInfo.time_count > 0)) { for (int i = 0; i < dev.peripheralInfo.time_count; i++) { double[] time = dev.peripheralstatus.time_state[i]; time[0] = dev.DpnupReadDeviceTime(i); } } if (((event_mask & (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_QUATERNION_UPDATE) != 0) && (dev.peripheralInfo.quaternion_count > 0)) { for (int i = 0; i < dev.peripheralInfo.quaternion_count; i++) { float[] quaternion = dev.peripheralstatus.quaternion_state[i]; dev.DpnupReadDeviceQuaternion(i, quaternion); } } if (((event_mask & (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_VECTOR_UPDATE) != 0) && (dev.peripheralInfo.vector_count > 0)) { for (int i = 0; i < dev.peripheralInfo.vector_count; i++) { float[] vector = dev.peripheralstatus.vector_state[i]; dev.DpnupReadDeviceVector(i, vector); } } if (((event_mask & (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_AXIS_UPDATE) != 0) && (dev.peripheralInfo.axis_count > 0)) { for (int i = 0; i < dev.peripheralInfo.axis_count; i++) { float[] axis = dev.peripheralstatus.axis_state[i]; axis[0] = dev.DpnupReadDeviceAxis(i); } } if (((event_mask & (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_BUTTON_UPDATE) != 0) && (dev.peripheralInfo.button_count > 0)) { for (int i = 0; i < dev.peripheralInfo.button_count; i++) { int[] button = dev.peripheralstatus.button_state[i]; button[0] = dev.DpnupReadDeviceButton(i); } } } finally { dev.peripheralstatus.cacheLock.ExitWriteLock(); } }