Example #1
0
        public static bool FindWiimotes()
        {
            IntPtr ptr = HIDapi.hid_enumerate(vid, pid);

            if (ptr == IntPtr.Zero)
            {
                ptr = HIDapi.hid_enumerate(vid, pid2);
                if (ptr == IntPtr.Zero)
                {
                    return(false);
                }
            }
            IntPtr cur_ptr = ptr;

            hid_device_info enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info));

            bool found = false;

            while (cur_ptr != IntPtr.Zero)
            {
                DS4  remote = null;
                bool fin    = false;
                foreach (DS4 r in Controllers)
                {
                    if (fin)
                    {
                        continue;
                    }

                    if (r.hidapi_path.Equals(enumerate.path))
                    {
                        remote = r;
                        fin    = true;
                    }
                }
                if (remote == null)
                {
                    IntPtr handle = HIDapi.hid_open_path(enumerate.path);

                    remote = new DS4(handle, enumerate.path);

                    Debug.Log("Found New Remote: " + remote.hidapi_path);

                    Controllers.Add(remote);

                    // TODO: Initialization (?)
                }

                cur_ptr = enumerate.next;
                if (cur_ptr != IntPtr.Zero)
                {
                    enumerate = (hid_device_info)Marshal.PtrToStructure(cur_ptr, typeof(hid_device_info));
                }
            }

            HIDapi.hid_free_enumeration(ptr);

            return(found);
        }
Example #2
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.FindWiimotes();

        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");
    }
Example #3
0
        public static void Cleanup(DS4 remote)
        {
            if (remote != null)
            {
                if (remote.hidapi_handle != IntPtr.Zero)
                    HIDapi.hid_close(remote.hidapi_handle);

                Controllers.Remove(remote);
            }
        }
Example #4
0
        public static void Cleanup(DS4 remote)
        {
            if (remote != null)
            {
                if (remote.hidapi_handle != IntPtr.Zero)
                {
                    HIDapi.hid_close(remote.hidapi_handle);
                }

                Controllers.Remove(remote);
            }
        }
Example #5
0
        public static bool FindWiimotes()
        {
            IntPtr ptr = HIDapi.hid_enumerate(vid, pid);
            IntPtr cur_ptr = ptr;

            if (ptr == IntPtr.Zero)
                return false;

            hid_device_info enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info));

            bool found = false;

            while (cur_ptr != IntPtr.Zero)
            {
                DS4 remote = null;
                bool fin = false;
                foreach (DS4 r in Controllers)
                {
                    if (fin)
                        continue;

                    if (r.hidapi_path.Equals(enumerate.path))
                    {
                        remote = r;
                        fin = true;
                    }
                }
                if (remote == null)
                {
                    IntPtr handle = HIDapi.hid_open_path(enumerate.path);

                    remote = new DS4(handle, enumerate.path);

                    Debug.Log("Found New Remote: " + remote.hidapi_path);

                    Controllers.Add(remote);

                    // TODO: Initialization (?)
                }

                cur_ptr = enumerate.next;
                if (cur_ptr != IntPtr.Zero)
                    enumerate = (hid_device_info)Marshal.PtrToStructure(cur_ptr, typeof(hid_device_info));
            }

            HIDapi.hid_free_enumeration(ptr);

            return found;
        }
Example #6
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;
    }