-
Notifications
You must be signed in to change notification settings - Fork 1
/
DeviceManager.cs
77 lines (68 loc) · 3.14 KB
/
DeviceManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) Den Delimarsky
// Den Delimarsky licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using DeckSurf.SDK.Models;
using DeckSurf.SDK.Models.Devices;
using HidSharp;
using System;
using System.Collections.Generic;
using System.Linq;
namespace DeckSurf.SDK.Core
{
/// <summary>
/// Class used to manage connected Stream Deck devices.
/// </summary>
public class DeviceManager
{
public static readonly int SupportedVid = 4057;
/// <summary>
/// Return a list of connected Stream Deck devices supported by DeckSurf.
/// </summary>
/// <returns>Enumerable containing a list of supported devices.</returns>
public static IEnumerable<ConnectedDevice> GetDeviceList()
{
var connectedDevices = new List<ConnectedDevice>();
var deviceList = DeviceList.Local.GetHidDevices();
foreach (var device in deviceList.Where(x => x.VendorID == SupportedVid))
{
bool supported = IsSupported(device.VendorID, device.ProductID);
Console.WriteLine("Vendor ID: " + device.VendorID);
Console.WriteLine("Product ID: " + device.ProductID);
Console.WriteLine("Serial Number: " + device.GetSerialNumber());
if (supported)
{
switch ((DeviceModel)device.ProductID)
{
case DeviceModel.XL:
connectedDevices.Add(new StreamDeckXL(device.VendorID, device.ProductID, device.DevicePath, device.GetFriendlyName(), (DeviceModel)device.ProductID, device.GetSerialNumber()));
break;
case DeviceModel.MINI:
connectedDevices.Add(new StreamDeckMini(device.VendorID, device.ProductID, device.DevicePath, device.GetFriendlyName(), (DeviceModel)device.ProductID, device.GetSerialNumber()));
break;
case DeviceModel.ORIGINAL:
case DeviceModel.ORIGINAL_V2:
connectedDevices.Add(new StreamDeckOriginal(device.VendorID, device.ProductID, device.DevicePath, device.GetFriendlyName(), (DeviceModel)device.ProductID, device.GetSerialNumber()));
break;
default:
break;
}
}
}
return connectedDevices;
}
/// <summary>
/// Determines whether a given vendor ID (VID) and product ID (PID) are supported by the SDK. VID and PID should be representing a Stream Deck device.
/// </summary>
/// <param name="vid">Device VID.</param>
/// <param name="pid">Device PID.</param>
/// <returns>True if device is supported, false if not.</returns>
public static bool IsSupported(int vid, int pid)
{
if (vid == SupportedVid && Enum.IsDefined(typeof(DeviceModel), (byte)pid))
{
return true;
}
return false;
}
}
}