Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CorsairDeviceGroup.cs
Go to the documentation of this file.
1using System;
5
7
9{
17
18 private readonly List<RgbDevice> _devices = new List<RgbDevice>();
19
20 private State _state;
21
23
25
30
31 protected override void Initialize()
32 {
33 if (_state == State.AnyDevicesAdded || _initializationFailed)
34 {
35 return;
36 }
37 if (!NativeLibrary.TryLoad("CUESDK.x64_2019.dll", Assembly.GetEntryAssembly(), DllImportSearchPath.SafeDirectories, out var _))
38 {
40 return;
41 }
42 try
43 {
44 if (_state < State.HandshakeCompleted)
45 {
48 if (corsairError != 0)
49 {
50 throw new DeviceInitializationException("Corsair initialization failed with: " + corsairError);
51 }
52 _state = State.HandshakeCompleted;
53 }
54 if (_state < State.DeviceControlGranted)
55 {
56 NativeMethods.CorsairRequestControl(CorsairAccessMode.CAM_ExclusiveLightingControl);
57 _state = State.DeviceControlGranted;
58 }
60 for (int i = 0; i < num; i++)
61 {
64 }
65 Console.WriteLine("Corsair RGB intialized.");
66 if (_state != State.AnyDevicesAdded)
67 {
68 Console.WriteLine("No usable Corsair RGB devices found. Shutting down Corsair SDK.");
70 }
71 }
73 {
74 Console.WriteLine("Corsair RGB not supported. (Can be disabled via Config.json)");
76 }
77 catch (Exception ex2)
78 {
79 Console.WriteLine("Corsair RGB not supported: " + ex2);
81 }
82 }
83
84 protected override void Uninitialize()
85 {
86 if (_state == State.Unitialized)
87 {
88 return;
89 }
90 try
91 {
93 if (_state >= State.DeviceControlGranted)
94 {
95 NativeMethods.CorsairReleaseControl(CorsairAccessMode.CAM_ExclusiveLightingControl);
96 }
97 Console.WriteLine("Corsair RGB unitialized.");
98 }
100 {
101 }
102 catch (Exception ex2)
103 {
104 Console.WriteLine("Corsair RGB failed to uninitialize: " + ex2);
105 }
106 if (_state >= State.HandshakeCompleted)
107 {
108 _state = State.HandshakeCompleted;
109 }
110 }
111
113 {
114 if (deviceInfo.CapsMask.HasFlag(CorsairDeviceCaps.CDC_Lighting))
115 {
116 RgbDevice rgbDevice = null;
117 switch (deviceInfo.Type)
118 {
119 case CorsairDeviceType.CDT_Headset:
121 break;
122 case CorsairDeviceType.CDT_Mouse:
124 break;
125 case CorsairDeviceType.CDT_Keyboard:
127 break;
128 case CorsairDeviceType.CDT_MouseMat:
130 break;
131 }
132 if (rgbDevice != null && rgbDevice.LedCount > 0)
133 {
135 _state = State.AnyDevicesAdded;
136 }
137 }
138 }
139
141 {
142 return _devices.GetEnumerator();
143 }
144}
CorsairDeviceGroup(VendorColorProfile colorProfiles)
override IEnumerator< RgbDevice > GetEnumerator()
void AddDeviceIfSupported(int deviceIndex, CorsairDeviceInfo deviceInfo)
static CorsairHeadset Create(int deviceIndex, DeviceColorProfile colorProfile)
static CorsairKeyboard Create(int deviceIndex, DeviceColorProfile colorProfile)
static CorsairMouse Create(int deviceIndex, CorsairDeviceInfo deviceInfo, DeviceColorProfile colorProfile)
static CorsairMousepad Create(int deviceIndex, DeviceColorProfile colorProfile)
static CorsairProtocolDetails CorsairPerformProtocolHandshake()
static bool CorsairRequestControl(CorsairAccessMode accessMode)
static bool CorsairReleaseControl(CorsairAccessMode accessMode)
static IntPtr CorsairGetDeviceInfo(int deviceIndex)
void Add(TKey key, TValue value)
static void WriteLine()
Definition Console.cs:733
static ? Assembly GetEntryAssembly()
Definition Assembly.cs:486
static ? object PtrToStructure(IntPtr ptr, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type structureType)
Definition Marshal.cs:1164
static bool TryLoad(string libraryPath, out IntPtr handle)