예제 #1
0
        private void detectTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                detectTimer.Enabled = false;
                var vrSet = new PSVR(Settings.Instance.EnableUDPBroadcast);
                PSVRController.DeviceConnected(vrSet);
                vrSet.SensorDataUpdate += VrSet_SensorDataUpdate;
                vrSet.Removed          += VrSet_Removed;

                Task.Run(() =>
                {
                    PSVRController.HeadsetOn();
                    PSVRController.EnableVRMode();
                    Thread.Sleep(1500);
                    PSVRController.EnableCinematicMode();
                    Thread.Sleep(1500);
                    PSVRController.ApplyCinematicSettings();
                });

                lblStatus.Text       = "VR set found";
                grpFunctions.Enabled = true;
                grpCinematic.Enabled = true;
                grpLeds.Enabled      = true;
            }
            catch (Exception ex) { detectTimer.Enabled = true; }
        }
예제 #2
0
        private void detectTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                detectTimer.Enabled = false;
                var vrSet = new PSVR(Settings.Instance.EnableUDPBroadcast);
                PSVRController.DeviceConnected(vrSet);
                vrSet.SensorDataUpdate += VrSet_SensorDataUpdate;
                vrSet.Removed          += VrSet_Removed;
                vrSet.INReport         += VrSet_CommandResponse;
                ThreadPool.QueueUserWorkItem((a) =>
                {
                    PSVRController.RequestDeviceInfo();
                    PSVRController.HeadsetOn();
                    PSVRController.EnableVRMode();
                    Thread.Sleep(1500);
                    PSVRController.EnableCinematicMode();
                    Thread.Sleep(1500);
                    PSVRController.ApplyCinematicSettings();
                });

                lblStatus.Text       = "VR set found";
                grpFunctions.Enabled = true;
                grpCinematic.Enabled = true;
                grpLeds.Enabled      = true;
            }
            catch { detectTimer.Enabled = true; }
        }
예제 #3
0
 private void VrSet_Removed(object sender, EventArgs e)
 {
     BeginInvoke((Action)(() =>
     {
         grpFunctions.Enabled = false;
         vrSet = null;
         lblStatus.Text = "Waiting for PS VR...";
         detectTimer.Enabled = true;
     }));
 }
예제 #4
0
 public static void DeviceDisconnected()
 {
     lock (locker)
     {
         if (dev != null)
         {
             dev.Dispose();
             dev = null;
         }
     }
 }
예제 #5
0
        public static void DeviceConnected(PSVR Device)
        {
            lock (locker)
            {
                if (dev != null)
                {
                    dev.Dispose();
                    dev = null;
                }

                dev = Device;
            }
        }
예제 #6
0
 private void detectTimer_Tick(object sender, EventArgs e)
 {
     try
     {
         vrSet = new PSVR();
         vrSet.SensorDataUpdate += VrSet_SensorDataUpdate;
         vrSet.Removed          += VrSet_Removed;
         vrSet.SendCommand(PSVRCommand.GetHeadsetOn());
         vrSet.SendCommand(PSVRCommand.GetEnterVRMode());
         Thread.Sleep(1500);
         vrSet.SendCommand(PSVRCommand.GetExitVRMode());
         detectTimer.Enabled  = false;
         lblStatus.Text       = "VR set found";
         grpFunctions.Enabled = true;
     }
     catch { detectTimer.Enabled = true; }
 }
예제 #7
0
        private void ProcessRawInput(ref Message m)
        {
            uint dwSize = 0;

            RawInput.GetRawInputData(m.LParam, (uint)RawInput.RID.INPUT, IntPtr.Zero, ref dwSize, (uint)Marshal.SizeOf(typeof(RawInput.RAWINPUTHEADER)));

            IntPtr buffer = Marshal.AllocHGlobal((int)dwSize);

            try
            {
                if (buffer == IntPtr.Zero)
                {
                    return;
                }

                if (
                    RawInput.GetRawInputData(m.LParam, (uint)RawInput.RID.INPUT, buffer, ref dwSize,
                                             (uint)Marshal.SizeOf(typeof(RawInput.RAWINPUTHEADER))) != dwSize)
                {
                    return;
                }
            } catch (Exception ex) {
            }
            RawInput.RAWINPUT raw = (RawInput.RAWINPUT)Marshal.PtrToStructure(buffer, typeof(RawInput.RAWINPUT));

            int offset = 0;

            byte[] bRawData;
            byte[] newArray;
            string RawCode;

            switch (raw.header.dwType)
            {
            case (int)RawInput.RawInputType.HID:
                RawInput.RAWHID hid = raw.hid;
                offset = Marshal.SizeOf(typeof(RawInput.RAWINPUTHEADER)) + Marshal.SizeOf(typeof(RawInput.RAWHID));

                bRawData = new byte[offset + raw.hid.dwSizeHid];
                Marshal.Copy(buffer, bRawData, 0, bRawData.Length);

                newArray = new byte[raw.hid.dwSizeHid];
                Array.Copy(bRawData, offset, newArray, 0, newArray.Length);

                RawCode = BitConverter.ToString(newArray);


                if (false)
                {
                    //this blocks UI...
                    if (listBox1.Items.Count > 30)
                    {
                        listBox1.Items.RemoveAt(30);
                    }
                    listBox1.Items.Insert(0, string.Format("{0}\r\n", RawCode));
                }
                else
                {
                    Debug.WriteLine(RawCode);
                }
                //DS4State state = DS4.parse(newArray);
                PSVRState state = PSVR.parse(newArray);
                currentState = state;
                break;

            case (int)RawInput.RawInputType.Mouse:
                RawInput.RAWMOUSE mouse = raw.mouse;
                offset = Marshal.SizeOf(typeof(RawInput.RAWINPUTHEADER)) + Marshal.SizeOf(typeof(RawInput.RAWMOUSE));

                bRawData = new byte[offset + Marshal.SizeOf(typeof(RawInput.RAWMOUSE))];
                Marshal.Copy(buffer, bRawData, 0, bRawData.Length);

                newArray = new byte[Marshal.SizeOf(typeof(RawInput.RAWMOUSE))];
                Array.Copy(bRawData, offset, newArray, 0, newArray.Length);

                RawCode = BitConverter.ToString(newArray);
                //textBox1.AppendText(string.Format("RAW HID DATA: {0}\r\n", RawCode));
                if (listBox1.Items.Count > 30)
                {
                    listBox1.Items.RemoveAt(30);
                }
                listBox1.Items.Insert(0, string.Format("{0}\r\n", RawCode));

                break;

            case (int)RawInput.RawInputType.Keyboard:
                break;
            }
        }