-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
77 lines (63 loc) · 2.04 KB
/
Copy pathProgram.cs
File metadata and controls
77 lines (63 loc) · 2.04 KB
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
using HeadsetControl.NET;
using HeadsetControl.NET.Exceptions;
var useTestDevice = args.Contains("--test", StringComparer.OrdinalIgnoreCase);
Console.WriteLine($"HeadsetControl native version: {HeadsetControlLibrary.Version}");
Console.WriteLine($"Supported device models: {HeadsetControlLibrary.SupportedDeviceCount}");
Console.WriteLine();
if (useTestDevice)
{
HeadsetControlLibrary.TestDeviceEnabled = true;
Console.WriteLine("Synthetic test device: ENABLED");
Console.WriteLine();
}
using var headsets = HeadsetControlLibrary.Discover();
if (headsets.Count == 0)
{
Console.WriteLine("No supported headset connected.");
return 0;
}
for (var i = 0; i < headsets.Count; i++)
{
var headset = headsets[i];
Console.WriteLine($"[{i}] {headset}");
Console.WriteLine($" Vendor : {headset.VendorName ?? "(unknown)"} (0x{headset.VendorId:X4})");
Console.WriteLine($" Product: {headset.ProductName ?? "(unknown)"} (0x{headset.ProductId:X4})");
Console.WriteLine($" Capabilities: {string.Join(", ", headset.SupportedCapabilities)}");
TryReadBattery(headset);
TryReadChatMix(headset);
Console.WriteLine();
}
return 0;
static void TryReadBattery(Headset headset)
{
if (!headset.Supports(HeadsetCapability.BatteryStatus))
{
return;
}
try
{
var battery = headset.GetBattery();
var level = battery.LevelPercent is int pct ? $"{pct}%" : "n/a";
Console.WriteLine($" Battery: {battery.Status} ({level})");
}
catch (HeadsetControlException ex)
{
Console.WriteLine($" Battery: <error: {ex.Message}>");
}
}
static void TryReadChatMix(Headset headset)
{
if (!headset.Supports(HeadsetCapability.ChatMixStatus))
{
return;
}
try
{
var mix = headset.GetChatMix();
Console.WriteLine($" ChatMix: level={mix.Level} game={mix.GameVolumePercent}% chat={mix.ChatVolumePercent}%");
}
catch (HeadsetControlException ex)
{
Console.WriteLine($" ChatMix: <error: {ex.Message}>");
}
}