Beispiel #1
0
        public void DeferredPlugin(OutputDevice outputDevice, DS4 controller)
        {
            if (outputDevice is null || controller is null)
            {
                return;
            }

            Action tempAction = new Action(() =>
            {
                int slot = FindSlot();
                if (slot != -1)
                {
                    outputDevice.Connect();
                    outputDevices[slot] = outputDevice;
                    devictDict.Add(slot, outputDevice);
                    revDevictDict.Add(outputDevice, slot);
                    Task.Delay(DELAY_TIME).Wait();
                    controller.Output = outputDevice;
                }
            });

            lock (actionLock)
            {
                actions.Enqueue(tempAction);
            }

            PrepareEventTask();
        }
Beispiel #2
0
        public void DeferredRemoval(OutputDevice outputDevice, DS4 controller, bool immediate = false)
        {
            if (outputDevice is null || controller is null)
            {
                return;
            }

            Action tempAction = new Action(() =>
            {
                if (revDevictDict.ContainsKey(outputDevice))
                {
                    int slot            = revDevictDict[outputDevice];
                    outputDevices[slot] = null;
                    devictDict.Remove(slot);
                    revDevictDict.Remove(outputDevice);
                    outputDevice.Disconnect();
                    controller.Output = null;
                    if (!immediate)
                    {
                        Task.Delay(DELAY_TIME).Wait();
                    }
                }
            });

            lock (actionLock)
            {
                actions.Enqueue(tempAction);
            }

            PrepareEventTask();
        }
Beispiel #3
0
    void Update()
    {
        if (!DS4Manager.HasWiimote())
        {
            return;
        }

        controller = DS4Manager.Controllers[0];

        DS4Data tentative = data;

        do
        {
            data      = tentative;
            tentative = controller.ReadDS4Data();
        } while (tentative != null);

        if (Visual != null)
        {
            Visual.rotation = data.Orientation.Orientation;
        }
    }
Beispiel #4
0
 void Update()
 {
     if (controller == null)
     {
         try
         {
             controller = DS4.getConroller();
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
         }
     }
     else
     {
         // Press circle button to reset rotation
         if (controller.buttonEast.isPressed)
         {
             m_transform.rotation = Quaternion.identity;
         }
         m_transform.rotation *= DS4.getRotation(4000 * Time.deltaTime);
     }
 }
Beispiel #5
0
 void Start()
 {
     this.controller = DS4.getConroller();
     m_transform     = this.transform;
 }
Beispiel #6
0
    void OnGUI()
    {
        GUI.Box(new Rect(0, 0, 300, Screen.height), "");

        GUILayout.BeginVertical(GUILayout.Width(300));
        GUILayout.Label("DS4 Found: " + DS4Manager.HasWiimote());
        if (GUILayout.Button("Find DS4"))
        {
            DS4Manager.FindDS4s();
        }

        if (GUILayout.Button("Cleanup"))
        {
            DS4Manager.Cleanup(controller);
            controller = null;
        }

        if (data == null)
        {
            return;
        }

        GUILayout.Label("X: " + data.Cross);
        GUILayout.Label("\u25cb: " + data.Circle);
        GUILayout.Label("\u25a1: " + data.Square);
        GUILayout.Label("\u25b3: " + data.Triangle);

        GUILayout.Label("PS: " + data.PS);
        GUILayout.Label("Share: " + data.Share);
        GUILayout.Label("Options: " + data.Options);

        GUILayout.Label("D-Pad Up: " + data.DpadUp);
        GUILayout.Label("D-Pad Down: " + data.DpadDown);
        GUILayout.Label("D-Pad Left: " + data.DpadLeft);
        GUILayout.Label("D-Pad Right: " + data.DpadRight);

        GUILayout.Label("Left Stick: (" + data.lstick[0] + "," + data.lstick[1] + ")");
        GUILayout.Label("Right Stick: (" + data.rstick[0] + "," + data.rstick[1] + ")");

        GUILayout.Label("L1: " + data.L1);
        GUILayout.Label("R1: " + data.R1);
        GUILayout.Label("L2: " + data.L2 + " (" + data.L2_analog + ")");
        GUILayout.Label("R2: " + data.R2 + " (" + data.R2_analog + ")");
        GUILayout.Label("L3: " + data.L3);
        GUILayout.Label("R3: " + data.R3);

        GUILayout.Label("Trackpad Button: " + data.TouchButton);
        GUILayout.Label("Trackpad Finger 1: (" + data.Touches[0, 0] + ", " + data.Touches[0, 1] + ")");
        GUILayout.Label("Trackpad Finger 2: (" + data.Touches[1, 0] + ", " + data.Touches[1, 1] + ")");

        GUILayout.Label("Gyro: " + data.Orientation.Gyro_Raw);
        GUILayout.Label("Rotation: " + data.Orientation.Orientation.eulerAngles);
        GUILayout.Label("Accel: " + data.Orientation.Accel_Raw);
        GUILayout.Label("Accel Standard Deviation: " + data.Orientation.Accel_Deviation);
        GUILayout.Label("Accel Magnitude: " + data.Orientation.Accel_Raw.magnitude);

        GUILayout.EndVertical();

        if (controller != null)
        {
            windowRect = GUI.Window(0, windowRect, DataWindow, "Data");
        }
    }
Beispiel #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);
                }
                //TODO: check VID/PID or HID Usage
                if (ds4Mode)
                {
                    currentDS4 = DS4.parse(newArray);
                }
                else
                {
                    currentPSVR = PSVR.parse(newArray);
                }
                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;
            }
        }