Skip to content

Commit fa7704c

Browse files
committed
Merge branch 'dev' of https://github.com/antonpup/Aurora into feature/variable-modul
# Conflicts: # Project-Aurora/Project-Aurora/Project-Aurora.csproj
2 parents 032ec2f + f21e2d8 commit fa7704c

31 files changed

+3883
-17
lines changed

Project-Aurora/Project-Aurora/Devices/DeviceManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ public DeviceManager()
114114
devices.Add(new DeviceContainer(new Devices.Asus.AsusDevice())); // Asus Device
115115
devices.Add(new DeviceContainer(new Devices.NZXT.NZXTDevice())); //NZXT Device
116116
devices.Add(new DeviceContainer(new Devices.Vulcan.VulcanDevice()));
117+
devices.Add(new DeviceContainer(new Devices.Uniwill.UniwillDevice()));
117118
devices.Add(new DeviceContainer(new Devices.Ducky.DuckyDevice())); //Ducky Device
118119

120+
119121
string devices_scripts_path = System.IO.Path.Combine(Global.ExecutingDirectory, "Scripts", "Devices");
120122

121123
if (Directory.Exists(devices_scripts_path))
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Diagnostics;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
using Aurora.Devices.RGBNet;
11+
using Aurora.Settings;
12+
using Microsoft.Win32;
13+
using UniwillSDKDLL;
14+
15+
namespace Aurora.Devices.Uniwill
16+
{
17+
enum GAMECENTERTYPE
18+
{
19+
NONE = 0,
20+
GAMINGTCENTER = 1,
21+
CONTROLCENTER = 2
22+
}
23+
24+
public class UniwillDevice : Device
25+
{
26+
// Generic Variables
27+
private string devicename = "Uniwill";
28+
private bool isInitialized = false;
29+
30+
private Stopwatch watch = new Stopwatch();
31+
private long lastUpdateTime = 0;
32+
33+
System.Timers.Timer regTimer;
34+
const string Root = "HKEY_LOCAL_MACHINE";
35+
const string subkey = @"SOFTWARE\OEM\Aurora";
36+
const string keyName = Root + "\\" + subkey;
37+
int SwitchOn = 0;
38+
39+
private AuroraInterface keyboard = null;
40+
41+
GAMECENTERTYPE GamingCenterType = 0;
42+
43+
float brightness = 1f;
44+
45+
public UniwillDevice()
46+
{
47+
devicename = KeyboardFactory.GetOEMName();
48+
ChoiceGamingCenter();
49+
}
50+
51+
private void ChoiceGamingCenter()
52+
{
53+
GamingCenterType = CheckGC();
54+
55+
if (GamingCenterType == GAMECENTERTYPE.GAMINGTCENTER)
56+
{
57+
regTimer = new System.Timers.Timer();
58+
regTimer.Interval = 300;
59+
regTimer.Elapsed += OnRegChanged;
60+
regTimer.Stop();
61+
regTimer.Start();
62+
63+
}
64+
}
65+
66+
private GAMECENTERTYPE CheckGC()
67+
{
68+
try
69+
{
70+
int Control = (int)Registry.GetValue(keyName, "AuroraSwitch", null);
71+
GamingCenterType = GAMECENTERTYPE.GAMINGTCENTER;
72+
SwitchOn = Control;
73+
}
74+
catch
75+
{
76+
GamingCenterType = GAMECENTERTYPE.NONE;
77+
SwitchOn = 0;
78+
}
79+
return GamingCenterType;
80+
}
81+
82+
public bool CheckGCPower()
83+
{
84+
if (GamingCenterType == GAMECENTERTYPE.GAMINGTCENTER)
85+
{
86+
int Control = (int)Registry.GetValue(keyName, "AuroraSwitch", 0);
87+
return Control != 0;
88+
}
89+
else
90+
{
91+
return true;
92+
}
93+
}
94+
95+
private void OnRegChanged(object sender, EventArgs e)
96+
{
97+
int newSwtich = (int)Registry.GetValue(keyName, "AuroraSwitch", 0);
98+
if (SwitchOn != newSwtich)
99+
{
100+
SwitchOn = newSwtich;
101+
if (CheckGCPower())
102+
{
103+
Initialize();
104+
}
105+
else
106+
{
107+
bRefreshOnce = true;
108+
isInitialized = false;
109+
Shutdown();
110+
}
111+
}
112+
}
113+
114+
public string GetDeviceName()
115+
{
116+
return devicename;
117+
}
118+
119+
public string GetDeviceDetails()
120+
{
121+
if (isInitialized)
122+
{
123+
return devicename + ": Initialized";
124+
}
125+
else
126+
{
127+
return devicename + ": Not initialized";
128+
}
129+
}
130+
131+
public bool Initialize()
132+
{
133+
if (!isInitialized && CheckGCPower())
134+
{
135+
try
136+
{
137+
keyboard = KeyboardFactory.CreateHIDDevice("hidkeyboard");
138+
if (keyboard != null)
139+
{
140+
bRefreshOnce = true;
141+
isInitialized = true;
142+
//SetBrightness();
143+
return true;
144+
}
145+
146+
isInitialized = false;
147+
return false;
148+
}
149+
catch
150+
{
151+
Debug.WriteLine("Uniwill device error!");
152+
}
153+
// Mark Initialized = FALSE
154+
isInitialized = false;
155+
return false;
156+
}
157+
158+
return isInitialized;
159+
}
160+
161+
public void Shutdown()
162+
{
163+
if (this.IsInitialized())
164+
{
165+
if (CheckGCPower())
166+
{
167+
keyboard?.release();
168+
}
169+
170+
bRefreshOnce = true;
171+
isInitialized = false;
172+
173+
}
174+
}
175+
176+
public void Reset()
177+
{
178+
if (this.IsInitialized())
179+
{
180+
if (CheckGCPower())
181+
{
182+
keyboard?.release();
183+
}
184+
185+
bRefreshOnce = true;
186+
isInitialized = false;
187+
}
188+
}
189+
190+
public bool Reconnect()
191+
{
192+
throw new NotImplementedException();
193+
}
194+
195+
public bool IsInitialized()
196+
{
197+
return isInitialized;
198+
}
199+
200+
public bool IsConnected()
201+
{
202+
return isInitialized;
203+
}
204+
205+
bool bRefreshOnce = true; // This is used to refresh effect between Row-Type and Fw-Type change or layout light level change
206+
207+
public bool UpdateDevice(Dictionary<DeviceKeys, Color> keyColors, DoWorkEventArgs e, bool forced = false)
208+
{
209+
if (e.Cancel) return false;
210+
211+
//Alpha necessary for Global Brightness modifier
212+
var adjustedColors = keyColors.Select(kc => AdjustBrightness(kc));
213+
214+
bool ret = keyboard?.SetEffect(0x32, 0x00, bRefreshOnce, adjustedColors, e) ?? false;
215+
216+
bRefreshOnce = false;
217+
218+
return ret;
219+
}
220+
221+
public bool UpdateDevice(DeviceColorComposition colorComposition, DoWorkEventArgs e, bool forced = false)
222+
{
223+
watch.Restart();
224+
225+
bool update_result = UpdateDevice(colorComposition.keyColors, e, forced);
226+
227+
watch.Stop();
228+
lastUpdateTime = watch.ElapsedMilliseconds;
229+
230+
return update_result;
231+
}
232+
233+
private KeyValuePair<DeviceKeys, Color> AdjustBrightness(KeyValuePair<DeviceKeys, Color> kc)
234+
{
235+
var newEntry = new KeyValuePair<DeviceKeys, Color>(kc.Key, Color.FromArgb(255, Utils.ColorUtils.MultiplyColorByScalar(kc.Value, (kc.Value.A / 255.0D) * brightness)));
236+
kc = newEntry;
237+
return kc;
238+
}
239+
240+
// Device Status Methods
241+
public bool IsKeyboardConnected()
242+
{
243+
return isInitialized;
244+
}
245+
246+
public bool IsPeripheralConnected()
247+
{
248+
return isInitialized;
249+
}
250+
251+
public string GetDeviceUpdatePerformance()
252+
{
253+
return (isInitialized ? lastUpdateTime + " ms" : "");
254+
}
255+
256+
public VariableRegistry GetRegisteredVariables()
257+
{
258+
return new VariableRegistry();
259+
}
260+
}
261+
}

Project-Aurora/Project-Aurora/Project-Aurora.csproj

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@
119119
<Reference Include="Microsoft.CSharp" />
120120
<Reference Include="System.Data" />
121121
<Reference Include="System.Xml" />
122+
<Reference Include="UniwillSDKDLL, Version=1.0.0.0, Culture=neutral, processorArchitecture=AMD64">
123+
<SpecificVersion>False</SpecificVersion>
124+
<HintPath>.\UniwillSDKDLL.dll</HintPath>
125+
</Reference>
122126
<Reference Include="WindowsBase" />
123127
</ItemGroup>
124128
<ItemGroup>
@@ -155,6 +159,7 @@
155159
<Compile Include="Controls\Window_Prompt.xaml.cs">
156160
<DependentUpon>Window_Prompt.xaml</DependentUpon>
157161
</Compile>
162+
<Compile Include="Devices\Uniwill\UniwillDevice.cs" />
158163
<Compile Include="Profiles\EliteDangerous\EliteConfig.cs" />
159164
<Compile Include="Profiles\EliteDangerous\EliteDangerousSettings.cs" />
160165
<Compile Include="Profiles\EliteDangerous\GSI\Nodes\Journal\Events\DockFighter.cs" />
@@ -827,6 +832,69 @@
827832
<Content Include="Profiles\Overlays\SkypeOverlay\Event_SkypeOverlay.cs" />
828833
<Content Include="Profiles\Overlays\SkypeOverlay\SkypeOverlaySettings.cs" />
829834
<Content Include="Profiles\Overlays\SkypeOverlay\State_SkypeOverlay.cs" />
835+
<None Include="kb_layouts\Extra Features\keyboard101_numpad_right_features.json">
836+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
837+
</None>
838+
<None Include="kb_layouts\Extra Features\keyboard102_numpad_right_features.json">
839+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
840+
</None>
841+
<None Include="kb_layouts\Extra Features\keyboard21br_numpad_left_bottom_features.json">
842+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
843+
</None>
844+
<None Include="kb_layouts\Extra Features\keyboard21jp_numpad_left_bottom_features.json">
845+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
846+
</None>
847+
<None Include="kb_layouts\Extra Features\keyboard21us_numpad_right_features.json">
848+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
849+
</None>
850+
<None Include="kb_layouts\Extra Features\keyboard21_numpad_left_bottom_features.json">
851+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
852+
</None>
853+
<None Include="kb_layouts\Extra Features\keyboard22br_numpad_left_bottom_features.json">
854+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
855+
</None>
856+
<None Include="kb_layouts\Extra Features\keyboard22jp_numpad_left_bottom_features.json">
857+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
858+
</None>
859+
<None Include="kb_layouts\Extra Features\keyboard22usuk_numpad_left_bottom_features.json">
860+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
861+
</None>
862+
<None Include="kb_layouts\Extra Features\keyboard22us_numpad_right_features.json">
863+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
864+
</None>
865+
<None Include="kb_layouts\Extra Features\keyboard_numpad_left_bottom_features.json">
866+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
867+
</None>
868+
<None Include="kb_layouts\Uniwill2ND_35X_1.json">
869+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
870+
</None>
871+
<None Include="kb_layouts\Uniwill2ND_35X_2.json">
872+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
873+
</None>
874+
<None Include="kb_layouts\Uniwill2P1_550_BR.json">
875+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
876+
</None>
877+
<None Include="kb_layouts\Uniwill2P1_550_JP.json">
878+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
879+
</None>
880+
<None Include="kb_layouts\Uniwill2P1_550_UK.json">
881+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
882+
</None>
883+
<None Include="kb_layouts\Uniwill2P1_550_US.json">
884+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
885+
</None>
886+
<None Include="kb_layouts\Uniwill2P2_650_BR.json">
887+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
888+
</None>
889+
<None Include="kb_layouts\Uniwill2P2_650_JP.json">
890+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
891+
</None>
892+
<None Include="kb_layouts\Uniwill2P2_650_UK.json">
893+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
894+
</None>
895+
<None Include="kb_layouts\Uniwill2P2_650_US.json">
896+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
897+
</None>
830898
<None Include="kb_layouts\ducky_shine_7.json">
831899
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
832900
</None>
-1.17 KB
Loading

0 commit comments

Comments
 (0)