-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathHidReader.cs
44 lines (34 loc) · 1.61 KB
/
HidReader.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
using System.Linq;
using Linearstar.Windows.RawInput.Native;
namespace Linearstar.Windows.RawInput;
public class HidReader
{
readonly HidPCaps capabilities;
public byte[]? PreparsedData { get; }
public HidPreparsedData PreparsedDataPtr { get; }
public int ValueCount => capabilities.NumberInputValueCaps;
public HidButtonSet[] ButtonSets { get; }
public HidValueSet[] ValueSets { get; }
public HidReader(HidPreparsedData preparsedData)
{
PreparsedDataPtr = preparsedData;
capabilities = HidP.GetCaps(preparsedData);
var buttonCaps = HidP.GetButtonCaps(preparsedData, HidPReportType.Input);
ButtonSets = buttonCaps.Select(i => new HidButtonSet(this, i)).ToArray();
var valueCaps = HidP.GetValueCaps(preparsedData, HidPReportType.Input);
ValueSets = valueCaps.Select(i => new HidValueSet(this, i)).ToArray();
}
public HidReader(byte[] preparsedData)
{
using var preparsedDataPtr = new HidPreparsedDataPtr(PreparsedData = preparsedData);
capabilities = HidP.GetCaps(preparsedDataPtr);
var buttonCaps = HidP.GetButtonCaps(preparsedDataPtr, HidPReportType.Input);
ButtonSets = buttonCaps.Select(i => new HidButtonSet(this, i)).ToArray();
var valueCaps = HidP.GetValueCaps(preparsedDataPtr, HidPReportType.Input);
ValueSets = valueCaps.Select(i => new HidValueSet(this, i)).ToArray();
}
internal HidPreparsedDataPtr GetPreparsedData() =>
PreparsedData == null
? new HidPreparsedDataPtr(PreparsedDataPtr)
: new HidPreparsedDataPtr(PreparsedData);
}