Ejemplo n.º 1
0
        public static DpnPeripheral OpenPeripheralDevice(string deviceId)
        {
            DpnPeripheral peripheral = DpnPeripheral.DpnupOpenDevice(deviceId);

            if (peripheral != null)
            {
                if (deviceId != string.Empty)
                {
                    Debug.Log("OpenDevice " + deviceId + " successes.");
                }
                peripheral.DpnupGetDeviceInfo();
                peripheral.DpnupUpdateDeviceState();
                //int event_mask = (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_POSE_UPDATE | (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_POSITION_UPDATE | (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_TIME_UPDATE |
                //(int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_AXIS_UPDATE | (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_BUTTON_UPDATE | (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_CONNECT | (int)DPNP_EVENT_TYPE.DPNP_EVENT_TYPE_DISCONNECT |
                //(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_USB_PLUGIN | (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_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;
                //peripheral.DpnupRegisterEventNotificationFunction(null, event_mask, IntPtr.Zero);
                return(peripheral);
            }
            else
            {
                Debug.Log("OpenDevice " + deviceId + " fail!");
                return(null);
            }
        }
Ejemplo n.º 2
0
        //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);
        }
        public static DpnPeripheral OpenPeripheral(string deviceId, DpnBasePeripheral basePeripheral)
        {
            if (deviceId == null)
            {
                return(null);
            }
            if (s_Peripherals.ContainsKey(deviceId))
            {
                if (s_Peripherals[deviceId].list.Contains(basePeripheral))
                {
                    return(basePeripheral.peripheral);
                }
                else
                {
                    basePeripheral.peripheral = s_Peripherals[deviceId].peripheral;
                    s_Peripherals[deviceId].list.Add(basePeripheral);
                    return(basePeripheral.peripheral);
                }
            }
            DpnPeripheral temp = DpnPeripheral.OpenPeripheralDevice(deviceId);

            if (temp == null)
            {
                return(null);
            }
            basePeripheral.peripheral = temp;
            s_Peripherals.Add(deviceId, new PeripheralList(temp));
            s_Peripherals[deviceId].list.Add(basePeripheral);
            return(basePeripheral.peripheral);
        }
 public static void ClosePeripheral(DpnBasePeripheral basePeripheral)
 {
     if (!s_Peripherals[basePeripheral.peripheral._deviceId].list.Contains(basePeripheral))
     {
         return;
     }
     s_Peripherals[basePeripheral.peripheral._deviceId].list.Remove(basePeripheral);
     if (s_Peripherals[basePeripheral.peripheral._deviceId].list.Count == 0)
     {
         DpnPeripheral.ClosePeripheralDevice(basePeripheral.peripheral);
         s_Peripherals.Remove(basePeripheral.peripheral._deviceId);
     }
     basePeripheral.peripheral = null;
     return;
 }
Ejemplo n.º 5
0
        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
        }
Ejemplo n.º 6
0
 public static void ClosePeripheralDevice(DpnPeripheral peripheral)
 {
     //peripheral.DpnupRegisterEventNotificationFunction(null, 0, IntPtr.Zero);
     peripheral.DpnupCloseDevice();
 }
Ejemplo n.º 7
0
        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();
            }
        }
 public PeripheralList(DpnPeripheral t)
 {
     peripheral = t;
     list       = new List <DpnBasePeripheral>();
 }
Ejemplo n.º 9
0
 public DPVR_Steam_Controller_Peripheral(DpnPeripheral _peripheral, DPVRControllerType type)
 {
     peripheral  = _peripheral;
     device_type = type;
 }