mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-11-23 09:49:16 +01:00
Change main device list to be dependent on device path rather than mac address
Should resolve issue #71.
This commit is contained in:
parent
5ac42d1fe1
commit
16f6f5be32
@ -9,7 +9,9 @@ namespace DS4Windows
|
|||||||
{
|
{
|
||||||
public class DS4Devices
|
public class DS4Devices
|
||||||
{
|
{
|
||||||
|
// (HID device path, DS4Device)
|
||||||
private static Dictionary<string, DS4Device> Devices = new Dictionary<string, DS4Device>();
|
private static Dictionary<string, DS4Device> Devices = new Dictionary<string, DS4Device>();
|
||||||
|
private static HashSet<string> deviceSerials = new HashSet<string>();
|
||||||
private static HashSet<string> DevicePaths = new HashSet<string>();
|
private static HashSet<string> DevicePaths = new HashSet<string>();
|
||||||
// Keep instance of opened exclusive mode devices not in use (Charging while using BT connection)
|
// Keep instance of opened exclusive mode devices not in use (Charging while using BT connection)
|
||||||
private static List<HidDevice> DisabledDevices = new List<HidDevice>();
|
private static List<HidDevice> DisabledDevices = new List<HidDevice>();
|
||||||
@ -101,7 +103,7 @@ namespace DS4Windows
|
|||||||
{
|
{
|
||||||
string serial = hDevice.readSerial();
|
string serial = hDevice.readSerial();
|
||||||
bool validSerial = !serial.Equals(DS4Device.blankSerial);
|
bool validSerial = !serial.Equals(DS4Device.blankSerial);
|
||||||
if (Devices.ContainsKey(serial))
|
if (validSerial && deviceSerials.Contains(serial))
|
||||||
{
|
{
|
||||||
// happens when the BT endpoint already is open and the USB is plugged into the same host
|
// happens when the BT endpoint already is open and the USB is plugged into the same host
|
||||||
if (isExclusiveMode && hDevice.IsExclusive &&
|
if (isExclusiveMode && hDevice.IsExclusive &&
|
||||||
@ -119,7 +121,7 @@ namespace DS4Windows
|
|||||||
{
|
{
|
||||||
DS4Device ds4Device = new DS4Device(hDevice);
|
DS4Device ds4Device = new DS4Device(hDevice);
|
||||||
//ds4Device.Removal += On_Removal;
|
//ds4Device.Removal += On_Removal;
|
||||||
Devices.Add(ds4Device.MacAddress, ds4Device);
|
Devices.Add(hDevice.DevicePath, ds4Device);
|
||||||
DevicePaths.Add(hDevice.DevicePath);
|
DevicePaths.Add(hDevice.DevicePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,22 +129,6 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//allows to get DS4Device by specifying unique MAC address
|
|
||||||
//format for MAC address is XX:XX:XX:XX:XX:XX
|
|
||||||
public static DS4Device getDS4Controller(string mac)
|
|
||||||
{
|
|
||||||
lock (Devices)
|
|
||||||
{
|
|
||||||
DS4Device device = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Devices.TryGetValue(mac, out device);
|
|
||||||
}
|
|
||||||
catch (ArgumentNullException) { }
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns DS4 controllers that were found and are running
|
// Returns DS4 controllers that were found and are running
|
||||||
public static IEnumerable<DS4Device> getDS4Controllers()
|
public static IEnumerable<DS4Device> getDS4Controllers()
|
||||||
{
|
{
|
||||||
@ -170,6 +156,7 @@ namespace DS4Windows
|
|||||||
|
|
||||||
Devices.Clear();
|
Devices.Clear();
|
||||||
DevicePaths.Clear();
|
DevicePaths.Clear();
|
||||||
|
deviceSerials.Clear();
|
||||||
DisabledDevices.Clear();
|
DisabledDevices.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,8 +170,9 @@ namespace DS4Windows
|
|||||||
if (device != null)
|
if (device != null)
|
||||||
{
|
{
|
||||||
device.HidDevice.CloseDevice();
|
device.HidDevice.CloseDevice();
|
||||||
Devices.Remove(device.MacAddress);
|
Devices.Remove(device.HidDevice.DevicePath);
|
||||||
DevicePaths.Remove(device.HidDevice.DevicePath);
|
DevicePaths.Remove(device.HidDevice.DevicePath);
|
||||||
|
deviceSerials.Remove(device.MacAddress);
|
||||||
//purgeHiddenExclusiveDevices();
|
//purgeHiddenExclusiveDevices();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -197,13 +185,17 @@ namespace DS4Windows
|
|||||||
DS4Device device = (DS4Device)sender;
|
DS4Device device = (DS4Device)sender;
|
||||||
if (device != null)
|
if (device != null)
|
||||||
{
|
{
|
||||||
|
string devPath = device.HidDevice.DevicePath;
|
||||||
string serial = device.getMacAddress();
|
string serial = device.getMacAddress();
|
||||||
if (Devices.ContainsKey(serial))
|
if (Devices.ContainsKey(devPath))
|
||||||
{
|
{
|
||||||
Devices.Remove(serial);
|
deviceSerials.Remove(serial);
|
||||||
device.updateSerial();
|
device.updateSerial();
|
||||||
serial = device.getMacAddress();
|
serial = device.getMacAddress();
|
||||||
Devices.Add(serial, device);
|
if (DS4Device.isValidSerial(serial))
|
||||||
|
{
|
||||||
|
deviceSerials.Add(serial);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user