Skip to content

Commit

Permalink
Added basic aura control, animation modes and colors
Browse files Browse the repository at this point in the history
  • Loading branch information
seerge committed Feb 19, 2023
1 parent dba6dae commit 66a2a1d
Show file tree
Hide file tree
Showing 8 changed files with 354 additions and 145 deletions.
1 change: 1 addition & 0 deletions GHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="hidlibrary" Version="3.3.40" />
<PackageReference Include="System.Management" Version="7.0.0" />
<PackageReference Include="TaskScheduler" Version="2.10.1" />
</ItemGroup>
Expand Down
118 changes: 68 additions & 50 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Diagnostics;
using System.Management;
using System.Runtime.InteropServices;

using HidLibrary;
using System.Text.Json;

public class ASUSWmi
Expand Down Expand Up @@ -214,55 +214,6 @@ public void setConfig(string name, int value)
}


public class PowerPlan
{
static void RunCommands(List<string> cmds, string workingDirectory = "")
{
var process = new Process();
var psi = new ProcessStartInfo();
psi.FileName = "powershell";
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.UseShellExecute = false;

psi.CreateNoWindow = true;

psi.WorkingDirectory = workingDirectory;
process.StartInfo = psi;
process.Start();
process.OutputDataReceived += (sender, e) => { Debug.WriteLine(e.Data); };
process.ErrorDataReceived += (sender, e) => { Debug.WriteLine(e.Data); };
process.BeginOutputReadLine();
process.BeginErrorReadLine();
using (StreamWriter sw = process.StandardInput)
{
foreach (var cmd in cmds)
{
sw.WriteLine(cmd);
}
}
process.WaitForExit();
}


public static int getBoostStatus()
{
List<string> cmds = new List<string>
{
"$asGuid = [regex]::Match((powercfg /getactivescheme),'(\\{){0,1}[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}(\\}){0,1}').Value",
"$statusFull = (powercfg /QUERY $asGuid 54533251-82be-4824-96c1-47b60b740d00 be337238-0d82-4146-a960-4f3749d470c7) -match 'Current AC Power Setting Index'",
"[regex]::Match($statusFull,'(0x.{8})').Value"
};

RunCommands(cmds);

return 0;
}

}


public class NativeMethods
{

Expand Down Expand Up @@ -468,8 +419,74 @@ public static void SetCPUBoost(int boost = 0)

PowerSetActiveScheme(IntPtr.Zero, activeSchemeGuid);
}
}


public class Aura
{

static byte[] MESSAGE_SET = { 0x5d, 0xb5 };
static byte[] MESSAGE_APPLY = { 0x5d, 0xb4 };

public const int Static = 0;
public const int Breathe = 0;
public const int Strobe = 0;
public const int Rainbow = 0;


public const int SpeedSlow = 0;
public const int SpeedMedium = 1;
public const int SpeedHigh = 2;

public static int Mode = Static;
public static Color Color1 = Color.White;
public static Color Color2 = Color.Black;
public static int Speed = SpeedSlow;

public static byte[] AuraMessage(int mode, Color color, Color color2, int speed)
{
byte[] msg = new byte[17];
msg[0] = 0x5d;
msg[1] = 0xb3;
msg[2] = 0x00; // Zone
msg[3] = (byte)mode; // Aura Mode
msg[4] = (byte)(color.R); // R
msg[5] = (byte)(color.G); // G
msg[6] = (byte)(color.B); // B
msg[7] = (byte)speed; // aura.speed as u8;
msg[8] = 0; // aura.direction as u8;
msg[10] = (byte)(color2.R); // R
msg[11] = (byte)(color2.G); // G
msg[12] = (byte)(color2.B); // B
return msg;
}

public static void ApplyAura()
{

HidDevice[] HidDeviceList;
int[] deviceIds = { 0x1854, 0x1869, 0x1866, 0x19b6 };

HidDeviceList = HidDevices.Enumerate(0x0b05, deviceIds).ToArray();

foreach (HidDevice device in HidDeviceList)
{
if (device.IsConnected)
{
if (device.Description.IndexOf("HID") >= 0)
{
device.OpenDevice();
byte[] msg = AuraMessage(Mode, Color1, Color2, Speed);
device.Write(msg);
device.Write(MESSAGE_SET);
device.Write(MESSAGE_APPLY);
device.CloseDevice();
}

}
}

}
}


Expand Down Expand Up @@ -508,6 +525,7 @@ public static void Main()

settingsForm.InitGPUMode();
settingsForm.InitBoost();
settingsForm.InitAura();

settingsForm.SetPerformanceMode(config.getConfig("performance_mode"));
settingsForm.SetBatteryChargeLimit(config.getConfig("charge_limit"));
Expand Down
10 changes: 10 additions & 0 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
<data name="eco" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\eco.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icons8-keyboard-48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icons8-keyboard-48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ultimate" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ultimate.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand Down
Binary file added Resources/icons8-keyboard-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 66a2a1d

Please sign in to comment.