コード例 #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));
        }
コード例 #3
0
        public void Update()
        {
            if (IsDiscovering)
            {
                throw new InvalidOperationException("This provider is already discovering.");
            }
            _IsDiscovering = true;
            List <string> devicePaths = new List <string>(MsHidDeviceProviderHelper.GetWiiDevicePaths());

            foreach (string devicePath in devicePaths)
            {
                if (!_FoundDevices.ContainsKey(devicePath))
                {
                    MsHidDeviceInfo deviceInfo = new MsHidDeviceInfo(devicePath);
                    _FoundDevices.Add(devicePath, deviceInfo);
                    OnDeviceFound(new DeviceInfoEventArgs(deviceInfo));
                }
            }
            if (devicePaths.Count < _FoundDevices.Count)
            {
                List <string> devicesToBeRemoved = new List <string>();
                foreach (KeyValuePair <string, IDeviceInfo> pair in _FoundDevices)
                {
                    if (!devicePaths.Contains(pair.Key))
                    {
                        devicesToBeRemoved.Add(pair.Key);
                    }
                }
                foreach (string devicePathToBeRemoved in devicesToBeRemoved)
                {
                    OnDeviceLost(new DeviceInfoEventArgs(_FoundDevices[devicePathToBeRemoved]));
                    _FoundDevices.Remove(devicePathToBeRemoved);
                }
            }
            _IsDiscovering = false;
        }