示例#1
0
        private void RespondIdentifyWiiMotionPlus(byte[] data)
        {
            if (data.Length != ID_InactiveMotionPlus.Length)
            {
                _wmp_attached = false;
                return;
            }

            if (data[0] == 0x01)                 // This is a weird inconsistency with some Wii Remote Pluses.  They don't have the -TR suffix
            {
                _Type = WiimoteType.WIIMOTEPLUS; // or a different PID as an identifier.  Instead they have a different WMP extension identifier.
            }
            // It occurs on some of the oldest Wii Remote Pluses available (pre-2012).

            for (int x = 0; x < data.Length; x++)
            {
                // [x != 4] is necessary because byte 5 of the identifier changes based on the state of the remote
                // It is 0x00 on startup, 0x04 when deactivated, 0x05 when deactivated nunchuck passthrough,
                // and 0x07 when deactivated classic passthrough
                //
                // [x != 0] is necessary due to the inconsistency noted above.
                if (x != 4 && x != 0 && data[x] != ID_InactiveMotionPlus[x])
                {
                    _wmp_attached = false;
                    return;
                }
            }
            _wmp_attached = true;
        }
示例#2
0
 public CS_WiiMote(IntPtr hidapi_handle, string hidapi_path, WiimoteType Type)
 {
     _hidapi_handle = hidapi_handle;
     _hidapi_path   = hidapi_path;
     _Type          = Type;
     _Status        = new CS_StatusData(this);
     _Extension     = null;
 }
示例#3
0
    private static bool _FindWiimotes(WiimoteType a_MoteType)
    {
        ushort uVendor = 0;
        ushort uProduct = 0;

        if(a_MoteType == WiimoteType.WIIMOTE) {
            uVendor = c_uVendorIDWiiMote;
            uProduct = c_uProductIDWiiMote;
        }

        IntPtr ptr = CS_HIDapi.hid_enumerate(uVendor, uProduct);
        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 bHasFound = false;

        while(cur_ptr != IntPtr.Zero)
        {
            CS_WiiMote Remote = null;
            bool bEnd = false;
            foreach (CS_WiiMote r in Wiimotes)
            {
                if (bEnd)
                    continue;

                if (r.hidapi_path.Equals(enumerate.path))
                {
                    Remote = r;
                    bEnd = true;
                }
            }
            if (Remote == null)
            {
                IntPtr handle = CS_HIDapi.hid_open_path(enumerate.path);

                Remote = new CS_WiiMote(handle, enumerate.path, a_MoteType);

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

                Wiimotes.Add(Remote);
                Remote.SendStatusInfoRequest();
            }

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

        CS_HIDapi.hid_free_enumeration(ptr);

        return bHasFound;
    }
示例#4
0
 internal WiimoteDeviceInfo(BluetoothDeviceInfo bt)
 {
     Bluetooth = bt;
     HID       = HIDDeviceInfo.GetDevice(bt.Address);
     if (HID == null)
     {
         throw new IOException("Error opening HID device!");
     }
     Type = GetTypeFromName(bt.Name);
 }
示例#5
0
        public Wiimote(IntPtr hidapi_handle, string hidapi_path, WiimoteType Type)
        {
            _hidapi_handle = hidapi_handle;
            _hidapi_path   = hidapi_path;
            _Type          = Type;

            _Accel     = new AccelData(this);
            _Button    = new ButtonData(this);
            _Ir        = new IRData(this);
            _Status    = new StatusData(this);
            _Extension = null;

            //RequestIdentifyWiiMotionPlus(); // why not?
        }
示例#6
0
文件: Wiimote.cs 项目: dsesclei/DS501
        public Wiimote(IntPtr hidapi_handle, string hidapi_path, WiimoteType Type)
        {
            _hidapi_handle  = hidapi_handle;
            _hidapi_path    = hidapi_path;
            _Type    = Type;

            _Accel  = new AccelData(this);
            _Button = new ButtonData(this);
            _Ir     = new IRData(this);
            _Status = new StatusData(this);
            _Extension = null;

            //RequestIdentifyWiiMotionPlus(); // why not?
        }
示例#7
0
 internal WiimoteDeviceInfo(HIDDeviceInfo hid, bool dolphinBarMode)
 {
     HID = hid;
     if (dolphinBarMode)
     {
         Bluetooth = new BluetoothDeviceInfo();
         Type      = GetTypeFromPID(hid.ProductID);
     }
     else
     {
         Bluetooth = BluetoothDeviceInfo.GetDevice(hid.DevicePath);
         if (Bluetooth == null)
         {
             throw new IOException("Error locating Bluetooth device!");
         }
         Type = GetTypeFromName(Bluetooth.Name);
     }
 }
示例#8
0
 internal WiimoteDeviceInfo(string hidPath, bool dolphinBarMode)
 {
     HID = HIDDeviceInfo.GetDevice(hidPath);
     if (HID == null)
     {
         throw new IOException("Error opening HID device!");
     }
     if (dolphinBarMode)
     {
         Bluetooth = new BluetoothDeviceInfo();
         Type      = GetTypeFromPID(HID.ProductID);
     }
     else
     {
         Bluetooth = WiimoteRegistry.GetBluetoothDevice(hidPath);
         if (Bluetooth == null)
         {
             throw new IOException("Error locating Bluetooth device!");
         }
         Type = GetTypeFromName(Bluetooth.Name);
     }
 }
示例#9
0
        private void RespondIdentifyExtension(byte[] data)
        {
            if (data.Length != 6)
            {
                return;
            }

            byte[] resized = new byte[8];
            for (int x = 0; x < 6; x++)
            {
                resized[x] = data[5 - x];
            }
            long val = BitConverter.ToInt64(resized, 0);

            // Disregard bytes 0 and 5 - see RespondIdentifyWiiMotionPlus()
            if ((val | 0xff000000ff00) == (ID_ActiveMotionPlus | 0xff000000ff00))
            {
                _current_ext = ExtensionController.MOTIONPLUS;
                if (_Extension == null || _Extension.GetType() != typeof(MotionPlusData))
                {
                    _Extension = new MotionPlusData(this);
                }
            }
            else if (val == ID_ActiveMotionPlus_Nunchuck)
            {
                _current_ext = ExtensionController.MOTIONPLUS_NUNCHUCK;
                _Extension   = null;
            }
            else if (val == ID_ActiveMotionPlus_Classic)
            {
                _current_ext = ExtensionController.MOTIONPLUS_CLASSIC;
                _Extension   = null;
            }
            else if (val == ID_ClassicPro)
            {
                _current_ext = ExtensionController.CLASSIC_PRO;
                _Extension   = null;
            }
            else if (val == ID_Nunchuck)
            {
                _current_ext = ExtensionController.NUNCHUCK;
                if (_Extension == null || _Extension.GetType() != typeof(NunchuckData))
                {
                    _Extension = new NunchuckData(this);
                }
            }
            else if (val == ID_Classic)
            {
                _current_ext = ExtensionController.CLASSIC;
                if (_Extension == null || _Extension.GetType() != typeof(ClassicControllerData))
                {
                    _Extension = new ClassicControllerData(this);
                }
            }
            else if (val == ID_WiiUPro)
            {
                _current_ext = ExtensionController.WIIU_PRO;
                _Type        = WiimoteType.PROCONTROLLER;
                if (_Extension == null || _Extension.GetType() != typeof(WiiUProData))
                {
                    _Extension = new WiiUProData(this);
                }
            }
            else
            {
                _current_ext = ExtensionController.NONE;
                _Extension   = null;
            }
        }
示例#10
0
        private static bool _FindWiimotes(WiimoteType type)
        {
            //if (hidapi_wiimote != IntPtr.Zero)
            //    HIDapi.hid_close(hidapi_wiimote);

            ushort vendor = 0;
            ushort product = 0;

            if (type == WiimoteType.WIIMOTE)
            {
                vendor = vendor_id_wiimote;
                product = product_id_wiimote;
            }
            else if (type == WiimoteType.WIIMOTEPLUS || type == WiimoteType.PROCONTROLLER)
            {
                vendor = vendor_id_wiimote;
                product = product_id_wiimoteplus;
            }

            IntPtr ptr = HIDapi.hid_enumerate(vendor, product);
            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)
            {
                Wiimote remote = null;
                bool fin = false;
                foreach (Wiimote r in Wiimotes)
                {
                    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);

                    WiimoteType trueType = type;

                    // Wii U Pro Controllers have the same identifiers as the newer Wii Remote Plus except for product
                    // string (WHY nintendo...)
                    if (enumerate.product_string.EndsWith("UC"))
                        trueType = WiimoteType.PROCONTROLLER;

                    remote = new Wiimote(handle, enumerate.path, trueType);

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

                    Wiimotes.Add(remote);

                    remote.SendDataReportMode(InputDataType.REPORT_BUTTONS);
                    remote.SendStatusInfoRequest();
                }

                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;
        }
示例#11
0
    private void RespondIdentifyExtension(byte[] data)
    {
        if (data.Length != 6)
            return;

        byte[] resized = new byte[8];
        for (int x = 0; x < 6; x++) resized[x] = data[5-x];
        long val = BitConverter.ToInt64(resized, 0);

        // Disregard bytes 0 and 5 - see RespondIdentifyWiiMotionPlus()
        if ((val | 0xff000000ff00) == (ID_ActiveMotionPlus | 0xff000000ff00))
        {
            _current_ext = ExtensionController.MOTIONPLUS;
            if(_Extension == null || _Extension.GetType() != typeof(MotionPlusData))
                _Extension = new MotionPlusData(this);
        }
        else if (val == ID_ActiveMotionPlus_Nunchuck)
        {
            _current_ext = ExtensionController.MOTIONPLUS_NUNCHUCK;
            _Extension = null;
        }
        else if (val == ID_ActiveMotionPlus_Classic)
        {
            _current_ext = ExtensionController.MOTIONPLUS_CLASSIC;
            _Extension = null;
        }
        else if (val == ID_ClassicPro)
        {
            _current_ext = ExtensionController.CLASSIC_PRO;
            _Extension = null;
        }
        else if (val == ID_Nunchuck || val == ID_Nunchuck2)
        {
            _current_ext = ExtensionController.NUNCHUCK;
            if (_Extension == null || _Extension.GetType() != typeof(NunchuckData))
                _Extension = new NunchuckData(this);
        }
        else if (val == ID_Classic)
        {
            _current_ext = ExtensionController.CLASSIC;
            if (_Extension == null || _Extension.GetType() != typeof(ClassicControllerData))
                _Extension = new ClassicControllerData(this);
        }
        else if (val == ID_WiiUPro)
        {
            _current_ext = ExtensionController.WIIU_PRO;
            _Type = WiimoteType.PROCONTROLLER;
            if (_Extension == null || _Extension.GetType() != typeof(WiiUProData))
                _Extension = new WiiUProData(this);
        }
		else if (val == ID_Guitar)
		{
			_current_ext = ExtensionController.GUITAR;
			if (_Extension == null || _Extension.GetType() != typeof(GuitarData))
				_Extension = new GuitarData(this);
		}
        else
        {
            _current_ext = ExtensionController.NONE;
            _Extension = null;
        }
    }
示例#12
0
    private void RespondIdentifyWiiMotionPlus(byte[] data)
    {
        if (data.Length != ID_InactiveMotionPlus.Length)
        {
            _wmp_attached = false;
            return;
        }

        if (data[0] == 0x01)                    // This is a weird inconsistency with some Wii Remote Pluses.  They don't have the -TR suffix
            _Type = WiimoteType.WIIMOTEPLUS;    // or a different PID as an identifier.  Instead they have a different WMP extension identifier.
                                                // It occurs on some of the oldest Wii Remote Pluses available (pre-2012).

        for (int x = 0; x < data.Length; x++)
        {
            // [x != 4] is necessary because byte 5 of the identifier changes based on the state of the remote
            // It is 0x00 on startup, 0x04 when deactivated, 0x05 when deactivated nunchuck passthrough,
            // and 0x07 when deactivated classic passthrough
            //
            // [x != 0] is necessary due to the inconsistency noted above.
            if (x != 4 && x != 0 && data[x] != ID_InactiveMotionPlus[x])
            {
                _wmp_attached = false;
                return;
            }
        }
        _wmp_attached = true;
    }
    private static bool _FindWiimotes(WiimoteType type)
    {
        //if (hidapi_wiimote != IntPtr.Zero)
        //    HIDapi.hid_close(hidapi_wiimote);

        ushort vendor = 0;
        ushort product = 0;

        if(type == WiimoteType.WIIMOTE) {
            vendor = vendor_id_wiimote;
            product = product_id_wiimote;
        } else if(type == WiimoteType.WIIMOTEPLUS || type == WiimoteType.PROCONTROLLER) {
            vendor = vendor_id_wiimote;
            product = product_id_wiimoteplus;
        }

        IntPtr ptr = HIDapi.hid_enumerate(vendor, product);
        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)
        {
            Wiimote remote = null;
            bool fin = false;
            foreach (Wiimote r in Wiimotes)
            {
                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);

                WiimoteType trueType = type;

                // Wii U Pro Controllers have the same identifiers as the newer Wii Remote Plus except for product
                // string (WHY nintendo...)
                if(enumerate.product_string.EndsWith("UC"))
                    trueType = WiimoteType.PROCONTROLLER;

                remote = new Wiimote(handle, enumerate.path, trueType);

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

                Wiimotes.Add(remote);

                remote.SendDataReportMode(InputDataType.REPORT_BUTTONS);
                remote.SendStatusInfoRequest();
            }

            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;
    }
示例#14
0
 internal WiimoteDeviceInfo(BluetoothDeviceInfo bt, HIDDeviceInfo hid)
 {
     Bluetooth = bt;
     HID       = hid;
     Type      = GetTypeFromName(bt.Name);
 }