cemu-DS4Windows/DS4Library/DS4Devices.cs
jays2kings 7d7d5d7391 Version 1.4.23
Extended range needed for touchpad swipes actions to register
UI adjustments in profile settings, such as a color box for flashing
color, alignment adjustments, and the Sixaxis reading dot staying in
bounds of the box
Recording a macro for special actions now open up in a new window,
allowing for ctrl+tab to be used
When controller's latency passes 10ms, the log will show and the
controller will flash red until the latency is under 10ms
Hovering over the mac address shows the latency of said controller, if
it's connected via bluetooth
Option to choose when at low battery for the light to flash or pulse
Much cleaner/neater hotkeys/about window
Option to download language packs if your PC is not set to an english
language
Finished Italian Translations (Thanks again Giulio)
Finished German Translations (Thanks Ammonjak)
Updated Italian & Russian Translations
Reorganized the the code so all cs files are under the same project
2015-02-08 16:51:52 -05:00

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);
}
}
}
}