in ScpControl/Usb/UsbHub.cs [210:299]
public override DsPadId Notify(ScpDevice.Notified notification, string Class, string path)
{
Log.DebugFormat("++ Notify [{0}] [{1}] [{2}]", notification, Class, path);
var classGuid = Guid.Parse(Class);
switch (notification)
{
case ScpDevice.Notified.Arrival:
{
var arrived = new UsbDevice();
if (classGuid == UsbDs3.DeviceClassGuid)
{
arrived = new UsbDs3();
Log.Info("DualShock 3 plugged in via Usb");
}
if (classGuid == UsbDs4.DeviceClassGuid)
{
arrived = new UsbDs4();
Log.Info("DualShock 4 plugged in via Usb");
}
if (classGuid == UsbGenericGamepad.DeviceClassGuid)
{
arrived = UsbGenericGamepad.DeviceFactory(path);
// unknown or unsupported device
if (arrived == null)
break;
Log.Debug("Generic Gamepad plugged in via Usb");
}
Log.DebugFormat("Arrival event for GUID {0} received", classGuid);
if (arrived.Open(path))
{
Log.DebugFormat("Device MAC address: {0}", arrived.DeviceAddress.AsFriendlyName());
if (!Apply3RdPartyWorkaroundsForDs3(ref arrived, path: path)) break;
if (LogArrival(arrived))
{
if (_devices[(byte) arrived.PadId].IsShutdown)
{
_devices[(byte) arrived.PadId].IsShutdown = false;
_devices[(byte) arrived.PadId].Close();
_devices[(byte) arrived.PadId] = arrived;
return arrived.PadId;
}
arrived.HidReportReceived += OnHidReportReceived;
_devices[(byte) arrived.PadId].Close();
_devices[(byte) arrived.PadId] = arrived;
if (m_Started) arrived.Start();
return arrived.PadId;
}
}
else
{
Log.FatalFormat("Couldn't open device {0}", path);
}
arrived.Close();
}
break;
case ScpDevice.Notified.Removal:
{
foreach (var t in _devices.Where(t => t.State == DsState.Connected && path == t.Path))
{
Log.InfoFormat("Device with MAC address {0} unplugged from Usb", t.DeviceAddress.AsFriendlyName());
// play disconnect sound
if (GlobalConfiguration.Instance.IsUsbDisconnectSoundEnabled)
AudioPlayer.Instance.PlayCustomFile(GlobalConfiguration.Instance.UsbDisconnectSoundFile);
t.Stop();
}
}
break;
}
return DsPadId.None;
}