mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-12-29 01:41:49 +01:00
86079b029e
Flash Lightbar when at high latency now has the option to choose what you decide is high latency Show Notifications now has the option to only show warnings, such as when a controller cannot be grabbed exclusively Speaking of bad news for Windows 10 users: Hide DS4 has now been disabled, until i can figure out why this is, it will be disabled, this means some games that rely on this may not work properly or at all, sorry about that As for good news for Windows 10, did you know you can press Windows + G to open a game bar which can record games. For Windows 10 users, there's a new special action: Xbox Game DVR. Pick a trigger (only one button) and tapping/holding/or double tapping does various things, such as start/stop recording, save an ongoing recording, take a screenshot (via the xbox app's option or your own hotkey ie form steam), or just open the gamebar Much of the code has been updated with c# 6.0 Added manifest so DS4Windows can notice Windows 10 and high DPIs, also reorganized files
108 lines
3.9 KiB
C#
108 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace DS4Windows
|
|
{
|
|
public class DS4Devices
|
|
{
|
|
private static Dictionary<string, DS4Device> Devices = new Dictionary<string, DS4Device>();
|
|
private static HashSet<String> DevicePaths = new HashSet<String>();
|
|
public static bool isExclusiveMode = false;
|
|
|
|
//enumerates ds4 controllers in the system
|
|
public static void findControllers()
|
|
{
|
|
lock (Devices)
|
|
{
|
|
int[] pid = { 0x5C4 };
|
|
IEnumerable<HidDevice> hDevices = HidDevices.Enumerate(0x054C, pid);
|
|
// Sort Bluetooth first in case USB is also connected on the same controller.
|
|
hDevices = hDevices.OrderBy<HidDevice, ConnectionType>((HidDevice d) => { return DS4Device.HidConnectionType(d); });
|
|
|
|
foreach (HidDevice hDevice in hDevices)
|
|
{
|
|
if (DevicePaths.Contains(hDevice.DevicePath))
|
|
continue; // BT/USB endpoint already open once
|
|
if (!hDevice.IsOpen)
|
|
{
|
|
hDevice.OpenDevice(isExclusiveMode);
|
|
// TODO in exclusive mode, try to hold both open when both are connected
|
|
if (isExclusiveMode && !hDevice.IsOpen)
|
|
hDevice.OpenDevice(false);
|
|
}
|
|
if (hDevice.IsOpen)
|
|
{
|
|
if (Devices.ContainsKey(hDevice.readSerial()))
|
|
continue; // happens when the BT endpoint already is open and the USB is plugged into the same host
|
|
else
|
|
{
|
|
DS4Device ds4Device = new DS4Device(hDevice);
|
|
ds4Device.Removal += On_Removal;
|
|
Devices.Add(ds4Device.MacAddress, ds4Device);
|
|
DevicePaths.Add(hDevice.DevicePath);
|
|
ds4Device.StartUpdate();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//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
|
|
public static IEnumerable<DS4Device> getDS4Controllers()
|
|
{
|
|
lock (Devices)
|
|
{
|
|
DS4Device[] controllers = new DS4Device[Devices.Count];
|
|
Devices.Values.CopyTo(controllers, 0);
|
|
return controllers;
|
|
}
|
|
}
|
|
|
|
public static void stopControllers()
|
|
{
|
|
lock (Devices)
|
|
{
|
|
IEnumerable<DS4Device> devices = getDS4Controllers();
|
|
foreach (DS4Device device in devices)
|
|
{
|
|
device.StopUpdate();
|
|
device.HidDevice.CloseDevice();
|
|
}
|
|
Devices.Clear();
|
|
DevicePaths.Clear();
|
|
}
|
|
}
|
|
|
|
//called when devices is diconnected, timed out or has input reading failure
|
|
public static void On_Removal(object sender, EventArgs e)
|
|
{
|
|
lock (Devices)
|
|
{
|
|
DS4Device device = (DS4Device)sender;
|
|
device.HidDevice.CloseDevice();
|
|
Devices.Remove(device.MacAddress);
|
|
DevicePaths.Remove(device.HidDevice.DevicePath);
|
|
}
|
|
}
|
|
}
|
|
}
|