protected override void OnDeviceArrival()

in ScpControl/RootHub.cs [500:558]


        protected override void OnDeviceArrival(object sender, ArrivalEventArgs e)
        {
            var bFound = false;
            var arrived = e.Device;

            lock (Pads)
            {
                for (var index = 0; index < Pads.Count && !bFound; index++)
                {
                    if (arrived.DeviceAddress.Equals(_reservedPads[index]))
                    {
                        if (Pads[index].State == DsState.Connected)
                        {
                            if (Pads[index].Connection == DsConnection.Bluetooth)
                            {
                                Pads[index].Disconnect();
                            }

                            if (Pads[index].Connection == DsConnection.Usb)
                            {
                                arrived.Disconnect();

                                e.Handled = false;
                                return;
                            }
                        }

                        bFound = true;

                        arrived.PadId = (DsPadId)index;
                        Pads[index] = arrived;
                    }
                }

                for (var index = 0; index < Pads.Count && !bFound; index++)
                {
                    if (Pads[index].State == DsState.Disconnected)
                    {
                        bFound = true;
                        _reservedPads[index] = arrived.DeviceAddress;

                        arrived.PadId = (DsPadId)index;
                        Pads[index] = arrived;
                    }
                }
            }

            if (bFound)
            {
                _scpBus.Plugin((int)arrived.PadId + 1);

                if (!GlobalConfiguration.Instance.IsVBusDisabled)
                {
                    Log.InfoFormat("Plugged in Port #{0} for {1} on Virtual Bus", (int)arrived.PadId + 1,
                        arrived.DeviceAddress.AsFriendlyName());
                }
            }
            e.Handled = bFound;
        }