-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathHidValueState.cs
53 lines (43 loc) · 1.4 KB
/
HidValueState.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
using Linearstar.Windows.RawInput.Native;
namespace Linearstar.Windows.RawInput;
public class HidValueState
{
readonly byte[] report;
readonly int reportLength;
public HidValue Value { get; }
public int CurrentValue
{
get
{
using (var preparsedDataPtr = Value.reader.GetPreparsedData())
return HidP.GetUsageValue(preparsedDataPtr, HidPReportType.Input, Value.valueCaps, Value.UsageAndPage.Usage, report, reportLength);
}
}
public int? ScaledValue
{
get
{
using (var preparsedDataPtr = Value.reader.GetPreparsedData())
return HidP.TryGetScaledUsageValue(preparsedDataPtr, HidPReportType.Input, Value.valueCaps, Value.UsageAndPage.Usage, report, reportLength, out var value) == NtStatus.Success
? value
: null;
}
}
public bool HasValue
{
get
{
if (!Value.CanBeNull) return true;
var currentValue = CurrentValue;
return currentValue >= Value.MinValue && currentValue <= Value.MaxValue;
}
}
internal HidValueState(HidValue value, byte[] report, int reportLength)
{
Value = value;
this.report = report;
this.reportLength = reportLength;
}
public override string ToString() =>
$"Value: {{{Value}}}, CurrentValue: {CurrentValue}";
}