예제 #1
0
        public IDevice Connect(IDeviceInfo deviceInfo)
        {
            MsHidDeviceInfo hidDeviceInfo = deviceInfo as MsHidDeviceInfo;

            if (hidDeviceInfo == null)
            {
                throw new ArgumentException("The specified DeviceInfo does not belong to this DeviceProvider.", "deviceInfo");
            }


            ReportWiimote wiimote;

            if (!TryConnect(hidDeviceInfo, out wiimote))
            {
                UseSetOutputReport = !UseSetOutputReport;
                if (!TryConnect(hidDeviceInfo, out wiimote))
                {
                    throw new DeviceConnectException("Both methods of connecting timed out.");
                }
            }

            wiimote.Disconnected += device_Disconnected;
            ConnectedDevices.Add(wiimote);
            MsHidDeviceProviderHelper.SetDevicePathConnected(hidDeviceInfo.DevicePath, true);

            OnDeviceConnected(new DeviceEventArgs(wiimote));
            return(wiimote);
        }
예제 #2
0
        void device_Disconnected(object sender, EventArgs e)
        {
            ReportWiimote   wiimote    = (ReportWiimote)sender;
            MsHidDeviceInfo deviceInfo = (MsHidDeviceInfo)wiimote.DeviceInfo;

            wiimote.Disconnected -= device_Disconnected;
            ConnectedDevices.Remove(wiimote);
            MsHidDeviceProviderHelper.SetDevicePathConnected(deviceInfo.DevicePath, false);
            OnDeviceDisconnected(new DeviceEventArgs(wiimote));
        }