This commit is contained in:
Serge
2023-11-12 19:12:58 +01:00
parent f6602fff3c
commit 3249072ee5
12 changed files with 250 additions and 300 deletions

View File

@@ -4,6 +4,7 @@ using GHelper.Helpers;
using GHelper.Input; using GHelper.Input;
using GHelper.Mode; using GHelper.Mode;
using GHelper.UI; using GHelper.UI;
using GHelper.USB;
using System.Diagnostics; using System.Diagnostics;
namespace GHelper namespace GHelper
@@ -218,10 +219,10 @@ namespace GHelper
Shown += Keyboard_Shown; Shown += Keyboard_Shown;
comboKeyboardSpeed.DropDownStyle = ComboBoxStyle.DropDownList; comboKeyboardSpeed.DropDownStyle = ComboBoxStyle.DropDownList;
comboKeyboardSpeed.DataSource = new BindingSource(AsusUSB.GetSpeeds(), null); comboKeyboardSpeed.DataSource = new BindingSource(Aura.GetSpeeds(), null);
comboKeyboardSpeed.DisplayMember = "Value"; comboKeyboardSpeed.DisplayMember = "Value";
comboKeyboardSpeed.ValueMember = "Key"; comboKeyboardSpeed.ValueMember = "Key";
comboKeyboardSpeed.SelectedValue = AsusUSB.Speed; comboKeyboardSpeed.SelectedValue = Aura.Speed;
comboKeyboardSpeed.SelectedValueChanged += ComboKeyboardSpeed_SelectedValueChanged; comboKeyboardSpeed.SelectedValueChanged += ComboKeyboardSpeed_SelectedValueChanged;
// Keyboard // Keyboard
@@ -400,7 +401,7 @@ namespace GHelper
else else
AppConfig.Set("keyboard_brightness", sliderBrightness.Value); AppConfig.Set("keyboard_brightness", sliderBrightness.Value);
AsusUSB.ApplyBrightness(sliderBrightness.Value, "Slider"); Aura.ApplyBrightness(sliderBrightness.Value, "Slider");
} }
private void InitServices() private void InitServices()
@@ -515,7 +516,7 @@ namespace GHelper
private void CheckXMG_CheckedChanged(object? sender, EventArgs e) private void CheckXMG_CheckedChanged(object? sender, EventArgs e)
{ {
AppConfig.Set("xmg_light", (checkXMG.Checked ? 1 : 0)); AppConfig.Set("xmg_light", (checkXMG.Checked ? 1 : 0));
AsusUSB.ApplyXGMLight(checkXMG.Checked); XGM.Light(checkXMG.Checked);
} }
private void CheckUSBC_CheckedChanged(object? sender, EventArgs e) private void CheckUSBC_CheckedChanged(object? sender, EventArgs e)
@@ -563,14 +564,14 @@ namespace GHelper
AppConfig.Set("keyboard_sleep_logo", (checkSleepLogo.Checked ? 1 : 0)); AppConfig.Set("keyboard_sleep_logo", (checkSleepLogo.Checked ? 1 : 0));
AppConfig.Set("keyboard_shutdown_logo", (checkShutdownLogo.Checked ? 1 : 0)); AppConfig.Set("keyboard_shutdown_logo", (checkShutdownLogo.Checked ? 1 : 0));
AsusUSB.ApplyAuraPower(); Aura.ApplyAuraPower();
} }
private void ComboKeyboardSpeed_SelectedValueChanged(object? sender, EventArgs e) private void ComboKeyboardSpeed_SelectedValueChanged(object? sender, EventArgs e)
{ {
AppConfig.Set("aura_speed", (int)comboKeyboardSpeed.SelectedValue); AppConfig.Set("aura_speed", (int)comboKeyboardSpeed.SelectedValue);
AsusUSB.ApplyAura(); Aura.ApplyAura();
} }

View File

@@ -2,6 +2,7 @@
using GHelper.Gpu.NVidia; using GHelper.Gpu.NVidia;
using GHelper.Mode; using GHelper.Mode;
using GHelper.UI; using GHelper.UI;
using GHelper.USB;
using Ryzen; using Ryzen;
using System.Diagnostics; using System.Diagnostics;
using System.Windows.Forms.DataVisualization.Charting; using System.Windows.Forms.DataVisualization.Charting;
@@ -1004,7 +1005,7 @@ namespace GHelper
InitPowerPlan(); InitPowerPlan();
if (Program.acpi.IsXGConnected()) AsusUSB.ResetXGM(); if (Program.acpi.IsXGConnected()) XGM.Reset();
if (gpuVisible) if (gpuVisible)

View File

@@ -15,7 +15,7 @@
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly> <ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.130</AssemblyVersion> <AssemblyVersion>0.131</AssemblyVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -59,7 +59,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="FftSharp" Version="2.0.0" /> <PackageReference Include="FftSharp" Version="2.0.0" />
<PackageReference Include="hidlibrary" Version="3.3.40" />
<PackageReference Include="HidSharpCore" Version="1.2.1.1" /> <PackageReference Include="HidSharpCore" Version="1.2.1.1" />
<PackageReference Include="NAudio" Version="2.1.0" /> <PackageReference Include="NAudio" Version="2.1.0" />
<PackageReference Include="NvAPIWrapper.Net" Version="0.8.1.101" /> <PackageReference Include="NvAPIWrapper.Net" Version="0.8.1.101" />

View File

@@ -1,6 +1,7 @@
using GHelper.Display; using GHelper.Display;
using GHelper.Gpu.NVidia; using GHelper.Gpu.NVidia;
using GHelper.Helpers; using GHelper.Helpers;
using GHelper.USB;
using System.Diagnostics; using System.Diagnostics;
namespace GHelper.Gpu namespace GHelper.Gpu
@@ -53,7 +54,7 @@ namespace GHelper.Gpu
AppConfig.Set("gpu_mode", gpuMode); AppConfig.Set("gpu_mode", gpuMode);
settings.VisualiseGPUMode(gpuMode); settings.VisualiseGPUMode(gpuMode);
AsusUSB.ApplyGPUColor(); Aura.ApplyGPUColor();
} }
@@ -284,7 +285,7 @@ namespace GHelper.Gpu
if (Program.acpi.IsXGConnected()) if (Program.acpi.IsXGConnected())
{ {
//Program.acpi.DeviceSet(AsusACPI.GPUXGInit, 1, "XG Init"); //Program.acpi.DeviceSet(AsusACPI.GPUXGInit, 1, "XG Init");
AsusUSB.InitXGM(); XGM.Init();
} }
} }
@@ -298,7 +299,7 @@ namespace GHelper.Gpu
if (Program.acpi.DeviceGet(AsusACPI.GPUXG) == 1) if (Program.acpi.DeviceGet(AsusACPI.GPUXG) == 1)
{ {
AsusUSB.ResetXGM(); XGM.Reset();
HardwareControl.KillGPUApps(); HardwareControl.KillGPUApps();
DialogResult dialogResult = MessageBox.Show("Did you close all applications running on XG Mobile?", "Disabling XG Mobile", MessageBoxButtons.YesNo); DialogResult dialogResult = MessageBox.Show("Did you close all applications running on XG Mobile?", "Disabling XG Mobile", MessageBoxButtons.YesNo);
@@ -318,12 +319,12 @@ namespace GHelper.Gpu
InitXGM(); InitXGM();
AsusUSB.ApplyXGMLight(AppConfig.Is("xmg_light")); XGM.Light(AppConfig.Is("xmg_light"));
await Task.Delay(TimeSpan.FromSeconds(15)); await Task.Delay(TimeSpan.FromSeconds(15));
if (AppConfig.IsMode("auto_apply")) if (AppConfig.IsMode("auto_apply"))
AsusUSB.SetXGMFan(AppConfig.GetFanConfig(AsusFan.XGM)); XGM.SetFan(AppConfig.GetFanConfig(AsusFan.XGM));
HardwareControl.RecreateGpuControl(); HardwareControl.RecreateGpuControl();

View File

@@ -1,6 +1,7 @@
using GHelper.Display; using GHelper.Display;
using GHelper.Helpers; using GHelper.Helpers;
using GHelper.Mode; using GHelper.Mode;
using GHelper.USB;
using Microsoft.Win32; using Microsoft.Win32;
using System.Diagnostics; using System.Diagnostics;
using System.Management; using System.Management;
@@ -59,7 +60,7 @@ namespace GHelper.Input
if (backlightActivity && iddle.TotalSeconds > kb_timeout) if (backlightActivity && iddle.TotalSeconds > kb_timeout)
{ {
backlightActivity = false; backlightActivity = false;
AsusUSB.ApplyBrightness(0, "Timeout"); Aura.ApplyBrightness(0, "Timeout");
} }
if (!backlightActivity && iddle.TotalSeconds < kb_timeout) if (!backlightActivity && iddle.TotalSeconds < kb_timeout)
@@ -478,7 +479,7 @@ namespace GHelper.Input
static void ToggleTouchpad() static void ToggleTouchpad()
{ {
KeyboardHook.KeyKeyKeyPress(Keys.LWin, Keys.LControlKey, Keys.F24); KeyboardHook.KeyKeyKeyPress(Keys.LWin, Keys.LControlKey, Keys.F24, 50);
} }
public static void ToggleArrowLock() public static void ToggleArrowLock()
@@ -654,8 +655,8 @@ namespace GHelper.Input
public static void SetBacklightAuto(bool init = false) public static void SetBacklightAuto(bool init = false)
{ {
if (init) AsusUSB.Init(); if (init) Aura.Init();
AsusUSB.ApplyBrightness(GetBacklight(), "Auto", init); Aura.ApplyBrightness(GetBacklight(), "Auto", init);
} }
public static void SetBacklight(int delta, bool force = false) public static void SetBacklight(int delta, bool force = false)
@@ -678,7 +679,7 @@ namespace GHelper.Input
if (force || !OptimizationService.IsRunning()) if (force || !OptimizationService.IsRunning())
{ {
AsusUSB.ApplyBrightness(backlight, "HotKey"); Aura.ApplyBrightness(backlight, "HotKey");
} }
if (!OptimizationService.IsOSDRunning()) if (!OptimizationService.IsOSDRunning())

View File

@@ -34,15 +34,17 @@ public sealed class KeyboardHook : IDisposable
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero); keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero);
} }
public static void KeyKeyKeyPress(Keys key, Keys key2, Keys key3) public static void KeyKeyKeyPress(Keys key, Keys key2, Keys key3, int sleep = 0)
{ {
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero); keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
keybd_event((byte)key2, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero); keybd_event((byte)key2, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
keybd_event((byte)key3, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero); keybd_event((byte)key3, 0, KEYEVENTF_EXTENDEDKEY, IntPtr.Zero);
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero);
keybd_event((byte)key2, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero);
keybd_event((byte)key3, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero); keybd_event((byte)key3, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero);
if (sleep > 0) Thread.Sleep(sleep);
keybd_event((byte)key2, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero);
if (sleep > 0) Thread.Sleep(sleep);
keybd_event((byte)key, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, IntPtr.Zero);
} }
/// <summary> /// <summary>

View File

@@ -1,4 +1,5 @@
using HidLibrary; using HidSharp;
using GHelper.USB;
namespace GHelper.Input namespace GHelper.Input
{ {
@@ -9,14 +10,14 @@ namespace GHelper.Input
public KeyboardListener(Action<int> KeyHandler) public KeyboardListener(Action<int> KeyHandler)
{ {
HidDevice? input = AsusUSB.GetDevice(); HidStream? input = AsusHid.FindHidStream(AsusHid.INPUT_ID);
// Fallback // Fallback
if (input == null) if (input == null)
{ {
AsusUSB.Init(); Aura.Init();
Thread.Sleep(1000); Thread.Sleep(1000);
input = AsusUSB.GetDevice(); input = input = AsusHid.FindHidStream(AsusHid.INPUT_ID);
} }
if (input == null) if (input == null)
@@ -25,7 +26,9 @@ namespace GHelper.Input
return; return;
} }
Logger.WriteLine($"Input: {input.DevicePath}"); input.ReadTimeout = int.MaxValue;
Logger.WriteLine($"Input: {input.Device.DevicePath}");
var task = Task.Run(() => var task = Task.Run(() =>
{ {
@@ -35,14 +38,15 @@ namespace GHelper.Input
{ {
// Emergency break // Emergency break
if (input == null || !input.IsConnected) if (input == null || !input.CanRead)
{ {
Logger.WriteLine("Listener terminated"); Logger.WriteLine("Listener terminated");
break; break;
} }
var data = input.Read().Data;
if (data.Length > 1 && data[0] == AsusUSB.INPUT_HID_ID && data[1] > 0 && data[1] != 236) var data = input.Read();
if (data.Length > 1 && data[0] == AsusHid.INPUT_ID && data[1] > 0 && data[1] != 236)
{ {
Logger.WriteLine($"Key: {data[1]}"); Logger.WriteLine($"Key: {data[1]}");
KeyHandler(data[1]); KeyHandler(data[1]);

View File

@@ -1,5 +1,6 @@
using GHelper.Gpu.NVidia; using GHelper.Gpu.NVidia;
using GHelper.Helpers; using GHelper.Helpers;
using GHelper.USB;
using Ryzen; using Ryzen;
namespace GHelper.Mode namespace GHelper.Mode
@@ -80,7 +81,7 @@ namespace GHelper.Mode
Program.acpi.DeviceSet(AsusACPI.VivoBookMode, vivoMode, "VivoMode"); Program.acpi.DeviceSet(AsusACPI.VivoBookMode, vivoMode, "VivoMode");
} }
if (AppConfig.Is("xgm_fan") && Program.acpi.IsXGConnected()) AsusUSB.ResetXGM(); if (AppConfig.Is("xgm_fan") && Program.acpi.IsXGConnected()) XGM.Reset();
if (notify) if (notify)
Program.toast.RunToast(Modes.GetCurrentName(), SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online ? ToastIcon.Charger : ToastIcon.Battery); Program.toast.RunToast(Modes.GetCurrentName(), SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online ? ToastIcon.Charger : ToastIcon.Battery);
@@ -133,8 +134,7 @@ namespace GHelper.Mode
bool xgmFan = false; bool xgmFan = false;
if (AppConfig.Is("xgm_fan") && Program.acpi.IsXGConnected()) if (AppConfig.Is("xgm_fan") && Program.acpi.IsXGConnected())
{ {
//AsusUSB.InitXGM(); XGM.SetFan(AppConfig.GetFanConfig(AsusFan.XGM));
AsusUSB.SetXGMFan(AppConfig.GetFanConfig(AsusFan.XGM));
xgmFan = true; xgmFan = true;
} }

View File

@@ -10,6 +10,7 @@ using GHelper.Mode;
using GHelper.Peripherals; using GHelper.Peripherals;
using GHelper.Peripherals.Mouse; using GHelper.Peripherals.Mouse;
using GHelper.UI; using GHelper.UI;
using GHelper.USB;
using System.Diagnostics; using System.Diagnostics;
using System.Timers; using System.Timers;
@@ -324,7 +325,7 @@ namespace GHelper
{ {
case 0: case 0:
Logger.WriteLine("Monitor Power Off"); Logger.WriteLine("Monitor Power Off");
AsusUSB.ApplyBrightness(0); Aura.ApplyBrightness(0);
break; break;
case 1: case 1:
Logger.WriteLine("Monitor Power On"); Logger.WriteLine("Monitor Power On");
@@ -698,16 +699,16 @@ namespace GHelper
public void InitAura() public void InitAura()
{ {
AsusUSB.Mode = AppConfig.Get("aura_mode"); Aura.Mode = AppConfig.Get("aura_mode");
AsusUSB.Speed = AppConfig.Get("aura_speed"); Aura.Speed = AppConfig.Get("aura_speed");
AsusUSB.SetColor(AppConfig.Get("aura_color")); Aura.SetColor(AppConfig.Get("aura_color"));
AsusUSB.SetColor2(AppConfig.Get("aura_color2")); Aura.SetColor2(AppConfig.Get("aura_color2"));
comboKeyboard.DropDownStyle = ComboBoxStyle.DropDownList; comboKeyboard.DropDownStyle = ComboBoxStyle.DropDownList;
comboKeyboard.DataSource = new BindingSource(AsusUSB.GetModes(), null); comboKeyboard.DataSource = new BindingSource(Aura.GetModes(), null);
comboKeyboard.DisplayMember = "Value"; comboKeyboard.DisplayMember = "Value";
comboKeyboard.ValueMember = "Key"; comboKeyboard.ValueMember = "Key";
comboKeyboard.SelectedValue = AsusUSB.Mode; comboKeyboard.SelectedValue = Aura.Mode;
comboKeyboard.SelectedValueChanged += ComboKeyboard_SelectedValueChanged; comboKeyboard.SelectedValueChanged += ComboKeyboard_SelectedValueChanged;
@@ -729,7 +730,7 @@ namespace GHelper
{ {
Task.Run(() => Task.Run(() =>
{ {
AsusUSB.ApplyAura(); Aura.ApplyAura();
VisualiseAura(); VisualiseAura();
}); });
} }
@@ -738,9 +739,9 @@ namespace GHelper
{ {
Invoke(delegate Invoke(delegate
{ {
pictureColor.BackColor = AsusUSB.Color1; pictureColor.BackColor = Aura.Color1;
pictureColor2.BackColor = AsusUSB.Color2; pictureColor2.BackColor = Aura.Color2;
pictureColor2.Visible = AsusUSB.HasSecondColor(); pictureColor2.Visible = Aura.HasSecondColor();
}); });
} }
@@ -1044,14 +1045,14 @@ namespace GHelper
if (!AppConfig.Is("skip_aura")) if (!AppConfig.Is("skip_aura"))
{ {
AsusUSB.ApplyAuraPower(); Aura.ApplyAuraPower();
AsusUSB.ApplyAura(); Aura.ApplyAura();
} }
InputDispatcher.SetBacklightAuto(true); InputDispatcher.SetBacklightAuto(true);
if (Program.acpi.IsXGConnected()) if (Program.acpi.IsXGConnected())
AsusUSB.ApplyXGMLight(AppConfig.Is("xmg_light")); XGM.Light(AppConfig.Is("xmg_light"));
if (AppConfig.HasTabletMode()) InputDispatcher.TabletMode(); if (AppConfig.HasTabletMode()) InputDispatcher.TabletMode();

96
app/USB/AsusHid.cs Normal file
View File

@@ -0,0 +1,96 @@
using HidSharp;
using HidSharp.Reports;
using System.Diagnostics;
namespace GHelper.USB;
public static class AsusHid
{
public const int ASUS_ID = 0x0b05;
public const byte INPUT_ID = 0x5a;
public const byte AURA_ID = 0x5d;
static int[] deviceIds = { 0x1a30, 0x1854, 0x1869, 0x1866, 0x19b6, 0x1822, 0x1837, 0x1854, 0x184a, 0x183d, 0x8502, 0x1807, 0x17e0, 0x18c6, 0x1abe };
static HidStream _stream;
public static HidStream FindHidStream(byte reportId, int minFeatureLength = 1)
{
HidDeviceLoader loader = new HidDeviceLoader();
var deviceList = loader.GetDevices(ASUS_ID).Where(device => deviceIds.Contains(device.ProductID));
foreach (var device in deviceList) if (device.CanOpen)
{
try
{
var config = new OpenConfiguration();
config.SetOption(OpenOption.Interruptible, false);
config.SetOption(OpenOption.Exclusive, false);
config.SetOption(OpenOption.Priority, 10);
HidStream hidStream = device.Open();
if (device.GetMaxFeatureReportLength() >= minFeatureLength)
{
var reportDescriptor = device.GetReportDescriptor();
if (reportDescriptor.TryGetReport(ReportType.Feature, reportId, out _))
{
return hidStream;
}
}
hidStream.Close();
hidStream.Dispose();
}
catch (Exception ex)
{
Debug.WriteLine($"Error accessing HID device: {ex.Message}");
}
}
return null;
}
static void WriteData(HidStream stream, byte[] data)
{
try
{
stream.Write(data);
Logger.WriteLine("USB " + stream.Device.ProductID + ": " + BitConverter.ToString(data));
}
catch (Exception ex)
{
Debug.WriteLine($"Error writing to HID device: {ex.Message} {BitConverter.ToString(data)}");
}
}
public static void Write(byte[] data, byte reportId = AURA_ID)
{
using (var stream = FindHidStream(reportId))
WriteData(stream, data);
}
public static void Write(List<byte[]> dataList, byte reportId = AURA_ID)
{
using (var stream = FindHidStream(reportId))
foreach (var data in dataList)
WriteData(stream, data);
}
public static void WriteAura(byte[] data, byte reportId = AURA_ID)
{
if (_stream == null) _stream = FindHidStream(reportId);
if (_stream == null) return;
try
{
_stream.Write(data);
}
catch (Exception ex)
{
_stream.Dispose();
Debug.WriteLine($"Error writing data to HID device: {ex.Message}");
}
}
}

View File

@@ -1,12 +1,9 @@
using GHelper.Gpu; using GHelper.Gpu;
using GHelper.Helpers; using GHelper.Helpers;
using System.Text; using System.Text;
using HidLibrary;
namespace GHelper namespace GHelper.USB
{ {
public class AuraPower public class AuraPower
{ {
public bool BootLogo; public bool BootLogo;
@@ -35,26 +32,19 @@ namespace GHelper
} }
public static class AsusUSB public static class Aura
{ {
public const int HEATMAP = 20; public const int HEATMAP = 20;
public const int GPUMODE = 21; public const int GPUMODE = 21;
public const int ASUS_ID = 0x0b05; public static readonly byte[] LED_INIT1 = new byte[] { AsusHid.AURA_ID, 0xb9 };
public const byte INPUT_HID_ID = 0x5a;
public const byte AURA_HID_ID = 0x5d;
public static readonly byte[] LED_INIT1 = new byte[] { AURA_HID_ID, 0xb9 };
public static readonly byte[] LED_INIT2 = Encoding.ASCII.GetBytes("]ASUS Tech.Inc."); public static readonly byte[] LED_INIT2 = Encoding.ASCII.GetBytes("]ASUS Tech.Inc.");
public static readonly byte[] LED_INIT3 = new byte[] { AURA_HID_ID, 0x05, 0x20, 0x31, 0, 0x1a }; public static readonly byte[] LED_INIT3 = new byte[] { AsusHid.AURA_ID, 0x05, 0x20, 0x31, 0, 0x1a };
public static readonly byte[] LED_INIT4 = Encoding.ASCII.GetBytes("^ASUS Tech.Inc."); public static readonly byte[] LED_INIT4 = Encoding.ASCII.GetBytes("^ASUS Tech.Inc.");
public static readonly byte[] LED_INIT5 = new byte[] { 0x5e, 0x05, 0x20, 0x31, 0, 0x1a }; public static readonly byte[] LED_INIT5 = new byte[] { 0x5e, 0x05, 0x20, 0x31, 0, 0x1a };
static byte[] MESSAGE_APPLY = { AURA_HID_ID, 0xb4 }; static byte[] MESSAGE_APPLY = { AsusHid.AURA_ID, 0xb4 };
static byte[] MESSAGE_SET = { AURA_HID_ID, 0xb5, 0, 0, 0 }; static byte[] MESSAGE_SET = { AsusHid.AURA_ID, 0xb5, 0, 0, 0 };
static int[] deviceIds = { 0x1a30, 0x1854, 0x1869, 0x1866, 0x19b6, 0x1822, 0x1837, 0x1854, 0x184a, 0x183d, 0x8502, 0x1807, 0x17e0, 0x18c6, 0x1abe };
private static int mode = 0; private static int mode = 0;
private static int speed = 1; private static int speed = 1;
@@ -68,10 +58,7 @@ namespace GHelper
static bool isOldHeatmap = AppConfig.Is("old_heatmap"); static bool isOldHeatmap = AppConfig.Is("old_heatmap");
static System.Timers.Timer timer = new System.Timers.Timer(80);
static System.Timers.Timer timer = new System.Timers.Timer(2000);
static HidDevice? auraDevice = null;
static byte[] AuraPowerMessage(AuraPower flags) static byte[] AuraPowerMessage(AuraPower flags)
{ {
@@ -114,14 +101,18 @@ namespace GHelper
return new byte[] { 0x5d, 0xbd, 0x01, keyb, bar, lid, rear, 0xFF }; return new byte[] { 0x5d, 0xbd, 0x01, keyb, bar, lid, rear, 0xFF };
} }
static AsusUSB() static Aura()
{ {
timer.Elapsed += Timer_Elapsed; timer.Elapsed += Timer_Elapsed;
isSingleColor = AppConfig.IsSingleColor(); // Mono Color isSingleColor = AppConfig.IsSingleColor(); // Mono Color
var device = GetDevice(AURA_HID_ID); using (var stream = AsusHid.FindHidStream(AsusHid.AURA_ID))
if (device is not null && (device.Attributes.Version == 22 || device.Attributes.Version == 23) && (AppConfig.ContainsModel("GA402X") || AppConfig.ContainsModel("GA402N"))) isSingleColor = true; {
if (stream is null) return;
if (stream.Device.ReleaseNumberBcd == 22 || stream.Device.ReleaseNumberBcd == 23 && (AppConfig.ContainsModel("GA402X") || AppConfig.ContainsModel("GA402N"))) isSingleColor = true;
stream.Close();
}
} }
private static void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e) private static void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
@@ -232,7 +223,7 @@ namespace GHelper
public static bool HasSecondColor() public static bool HasSecondColor()
{ {
return (mode == 1 && !isTuf); return mode == 1 && !isTuf;
} }
public static int Speed public static int Speed
@@ -259,37 +250,11 @@ namespace GHelper
} }
private static IEnumerable<HidDevice> GetHidDevices(int[] deviceIds, int minFeatures = 1)
{
HidDevice[] HidDeviceList = HidDevices.Enumerate(ASUS_ID, deviceIds).ToArray();
foreach (HidDevice device in HidDeviceList)
if (device.IsConnected && device.Capabilities.FeatureReportByteLength >= minFeatures)
yield return device;
}
public static HidDevice? GetDevice(byte reportID = INPUT_HID_ID)
{
HidDevice[] HidDeviceList = HidDevices.Enumerate(ASUS_ID, deviceIds).ToArray();
HidDevice input = null;
foreach (HidDevice device in HidDeviceList)
if (device.ReadFeatureData(out byte[] data, reportID))
{
input = device;
//Logger.WriteLine("HID Device("+ reportID + ")" + + device.Capabilities.FeatureReportByteLength + "|" + device.Capabilities.InputReportByteLength + device.DevicePath);
if (reportID == INPUT_HID_ID && device.Attributes.ProductId == 0x1a30) return input;
}
return input;
}
public static byte[] AuraMessage(int mode, Color color, Color color2, int speed, bool mono = false) public static byte[] AuraMessage(int mode, Color color, Color color2, int speed, bool mono = false)
{ {
byte[] msg = new byte[17]; byte[] msg = new byte[17];
msg[0] = AURA_HID_ID; msg[0] = AsusHid.AURA_ID;
msg[1] = 0xb3; msg[1] = 0xb3;
msg[2] = 0x00; // Zone msg[2] = 0x00; // Zone
msg[3] = (byte)mode; // Aura Mode msg[3] = (byte)mode; // Aura Mode
@@ -298,7 +263,7 @@ namespace GHelper
msg[6] = mono ? (byte)0 : color.B; // B msg[6] = mono ? (byte)0 : color.B; // B
msg[7] = (byte)speed; // aura.speed as u8; msg[7] = (byte)speed; // aura.speed as u8;
msg[8] = 0; // aura.direction as u8; msg[8] = 0; // aura.direction as u8;
msg[9] = (mode == 1) ? (byte)1 : (byte)0; msg[9] = mode == 1 ? (byte)1 : (byte)0;
msg[10] = color2.R; // R msg[10] = color2.R; // R
msg[11] = mono ? (byte)0 : color2.G; // G msg[11] = mono ? (byte)0 : color2.G; // G
msg[12] = mono ? (byte)0 : color2.B; // B msg[12] = mono ? (byte)0 : color2.B; // B
@@ -309,71 +274,20 @@ namespace GHelper
{ {
Task.Run(async () => Task.Run(async () =>
{ {
var devices = GetHidDevices(deviceIds); AsusHid.Write(new List<byte[]> { LED_INIT1, LED_INIT2, LED_INIT3, LED_INIT4, LED_INIT5 });
foreach (HidDevice device in devices)
{
device.OpenDevice();
device.WriteFeatureData(LED_INIT1);
device.WriteFeatureData(LED_INIT2);
device.WriteFeatureData(LED_INIT3);
device.WriteFeatureData(LED_INIT4);
device.WriteFeatureData(LED_INIT5);
device.CloseDevice();
}
}); });
} }
public static void ApplyBrightness(int brightness, string log = "Backlight", bool delay = false) public static void ApplyBrightness(int brightness, string log = "Backlight", bool delay = false)
{ {
Task.Run(async () => Task.Run(async () =>
{ {
if (delay) await Task.Delay(TimeSpan.FromSeconds(1)); if (delay) await Task.Delay(TimeSpan.FromSeconds(1));
if (isTuf) Program.acpi.TUFKeyboardBrightness(brightness); if (isTuf) Program.acpi.TUFKeyboardBrightness(brightness);
byte[] msg = { AURA_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness }; AsusHid.Write(new byte[] { AsusHid.AURA_ID, 0xba, 0xc5, 0xc4, (byte)brightness });
byte[] msgBackup = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness }; if (AppConfig.ContainsModel("GA503")) AsusHid.Write(new byte[] { AsusHid.INPUT_ID, 0xba, 0xc5, 0xc4, (byte)brightness }, AsusHid.INPUT_ID);
var devices = GetHidDevices(deviceIds);
foreach (HidDevice device in devices)
{
device.OpenDevice();
if (device.ReadFeatureData(out byte[] data, AURA_HID_ID))
{
device.WriteFeatureData(msg);
Logger.WriteLine(log + ":" + BitConverter.ToString(msg));
}
if (AppConfig.ContainsModel("GA503") && device.ReadFeatureData(out byte[] dataBackkup, INPUT_HID_ID))
{
device.WriteFeatureData(msgBackup);
Logger.WriteLine(log + ":" + BitConverter.ToString(msgBackup));
}
device.CloseDevice();
}
// Backup payload for old models
/*
if (AppConfig.ContainsModel("GA503RW"))
{
byte[] msgBackup = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };
var devicesBackup = GetHidDevices(deviceIds);
foreach (HidDevice device in devicesBackup)
{
device.OpenDevice();
device.WriteFeatureData(msgBackup);
device.CloseDevice();
}
}
*/
}); });
@@ -415,19 +329,7 @@ namespace GHelper
flags.SleepRear = AppConfig.IsNotFalse("keyboard_sleep_lid"); flags.SleepRear = AppConfig.IsNotFalse("keyboard_sleep_lid");
flags.ShutdownRear = AppConfig.IsNotFalse("keyboard_shutdown_lid"); flags.ShutdownRear = AppConfig.IsNotFalse("keyboard_shutdown_lid");
var devices = GetHidDevices(deviceIds); AsusHid.Write(AuraPowerMessage(flags));
byte[] msg = AuraPowerMessage(flags);
foreach (HidDevice device in devices)
{
device.OpenDevice();
if (device.ReadFeatureData(out byte[] data, AURA_HID_ID))
{
device.WriteFeatureData(msg);
Logger.WriteLine("USB-KB " + device.Attributes.ProductHexId + ":" + BitConverter.ToString(msg));
}
device.CloseDevice();
}
if (isTuf) if (isTuf)
Program.acpi.TUFKeyboardPower( Program.acpi.TUFKeyboardPower(
@@ -438,26 +340,6 @@ namespace GHelper
} }
static void GetAuraDevice()
{
var devices = GetHidDevices(deviceIds);
foreach (HidDevice device in devices)
{
device.OpenDevice();
if (device.ReadFeatureData(out byte[] data, AURA_HID_ID))
{
Logger.WriteLine("Aura Device:" + device.DevicePath);
auraDevice = device;
return;
}
else
{
device.CloseDevice();
}
}
}
public static void ApplyColor(Color color, bool init = false) public static void ApplyColor(Color color, bool init = false)
{ {
@@ -467,9 +349,6 @@ namespace GHelper
return; return;
} }
if (auraDevice is null || !auraDevice.IsConnected) GetAuraDevice();
if (auraDevice is null || !auraDevice.IsConnected) return;
if (isStrix && !isOldHeatmap) if (isStrix && !isOldHeatmap)
{ {
byte[] msg = new byte[0x40]; byte[] msg = new byte[0x40];
@@ -477,7 +356,7 @@ namespace GHelper
byte start = 9; byte start = 9;
byte maxLeds = 0x93; byte maxLeds = 0x93;
msg[0] = AURA_HID_ID; msg[0] = AsusHid.AURA_ID;
msg[1] = 0xbc; msg[1] = 0xbc;
msg[2] = 0; msg[2] = 0;
msg[3] = 1; msg[3] = 1;
@@ -493,38 +372,32 @@ namespace GHelper
msg[start + 2 + i * 3] = color.B; // B msg[start + 2 + i * 3] = color.B; // B
} }
if (init) if (init)
{ {
auraDevice.Write(LED_INIT1); Init();
auraDevice.Write(LED_INIT2); AsusHid.WriteAura(new byte[] { AsusHid.AURA_ID, 0xbc });
auraDevice.Write(LED_INIT3);
auraDevice.Write(LED_INIT4);
auraDevice.Write(LED_INIT5);
auraDevice.Write(new byte[] { AURA_HID_ID, 0xbc });
} }
for (byte b = 0; b < maxLeds; b += 0x10) for (byte b = 0; b < maxLeds; b += 0x10)
{ {
msg[6] = b; msg[6] = b;
auraDevice.Write(msg); AsusHid.WriteAura(msg);
} }
msg[6] = maxLeds; msg[6] = maxLeds;
auraDevice.Write(msg); AsusHid.WriteAura(msg);
msg[4] = 4; msg[4] = 4;
msg[5] = 0; msg[5] = 0;
msg[6] = 0; msg[6] = 0;
msg[7] = 0; msg[7] = 0;
auraDevice.Write(msg); AsusHid.WriteAura(msg);
} }
else else
{ {
//Debug.WriteLine(color.ToString()); AsusHid.WriteAura(AuraMessage(0, color, color, 0));
auraDevice.Write(AuraMessage(0, color, color, 0)); AsusHid.WriteAura(MESSAGE_SET);
auraDevice.Write(MESSAGE_SET);
} }
} }
@@ -534,8 +407,6 @@ namespace GHelper
{ {
if (AppConfig.Get("aura_mode") != GPUMODE) return; if (AppConfig.Get("aura_mode") != GPUMODE) return;
Logger.WriteLine(GPUModeControl.gpuMode.ToString());
switch (GPUModeControl.gpuMode) switch (GPUModeControl.gpuMode)
{ {
case AsusACPI.GPUModeUltimate: case AsusACPI.GPUModeUltimate:
@@ -574,36 +445,9 @@ namespace GHelper
return; return;
} }
int _speed; int _speed = (Speed == 1) ? 0xeb : (Speed == 2) ? 0xf5 : 0xe1;
switch (Speed)
{
case 1:
_speed = 0xeb;
break;
case 2:
_speed = 0xf5;
break;
default:
_speed = 0xe1;
break;
}
byte[] msg; AsusHid.Write(new List<byte[]> { AuraMessage(Mode, Color1, Color2, _speed, isSingleColor), MESSAGE_APPLY, MESSAGE_SET });
var devices = GetHidDevices(deviceIds);
foreach (HidDevice device in devices)
{
device.OpenDevice();
if (device.ReadFeatureData(out byte[] data, AURA_HID_ID))
{
msg = AuraMessage(Mode, Color1, Color2, _speed, isSingleColor);
device.WriteFeatureData(msg);
device.WriteFeatureData(MESSAGE_APPLY);
device.WriteFeatureData(MESSAGE_SET);
Logger.WriteLine("USB-KB " + device.Attributes.Version + device.Description + device.DevicePath + ":" + BitConverter.ToString(msg));
}
device.CloseDevice();
}
if (isTuf) if (isTuf)
Program.acpi.TUFKeyboardRGB(Mode, Color1, _speed); Program.acpi.TUFKeyboardRGB(Mode, Color1, _speed);
@@ -611,71 +455,6 @@ namespace GHelper
} }
// Reference : thanks to https://github.com/RomanYazvinsky/ for initial discovery of XGM payloads
public static int SetXGM(byte[] msg)
{
//Logger.WriteLine("XGM Payload :" + BitConverter.ToString(msg));
var payload = new byte[300];
Array.Copy(msg, payload, msg.Length);
foreach (HidDevice device in GetHidDevices(new int[] { 0x1970 }, 300))
{
device.OpenDevice();
Logger.WriteLine("XGM " + device.Attributes.ProductHexId + "|" + device.Capabilities.FeatureReportByteLength + ":" + BitConverter.ToString(msg));
device.WriteFeatureData(payload);
device.CloseDevice();
//return 1;
}
return 0;
}
public static void InitXGM()
{
byte[] ASUS_INIT = Encoding.ASCII.GetBytes("^ASUS Tech.Inc.");
SetXGM(ASUS_INIT);
/*
SetXGM(new byte[] { 0x5e, 0xd0, 0x02 });
SetXGM(new byte[] { 0x5e, 0xd0, 0x03 });
SetXGM(ASUS_INIT);
SetXGM(new byte[] { 0x5e, 0xd1, 0x02 }); // reset fan
SetXGM(ASUS_INIT);
SetXGM(new byte[] { 0x5e, 0xce, 0x03 });
SetXGM(new byte[] { 0x5e, 0xd0, 0x04 });
SetXGM(new byte[] { 0x5e, 0xd0, 0x01 });
*/
}
public static void ApplyXGMLight(bool status)
{
SetXGM(new byte[] { 0x5e, 0xc5, status ? (byte)0x50 : (byte)0 });
}
public static int ResetXGM()
{
return SetXGM(new byte[] { 0x5e, 0xd1, 0x02 });
}
public static int SetXGMFan(byte[] curve)
{
if (AsusACPI.IsInvalidCurve(curve)) return -1;
//InitXGM();
byte[] msg = new byte[19];
Array.Copy(new byte[] { 0x5e, 0xd1, 0x01 }, msg, 3);
Array.Copy(curve, 0, msg, 3, curve.Length);
return SetXGM(msg);
}
} }
} }

65
app/USB/XGM.cs Normal file
View File

@@ -0,0 +1,65 @@
// Reference : thanks to https://github.com/RomanYazvinsky/ for initial discovery of XGM payloads
using HidSharp;
using System.Diagnostics;
using System.Text;
namespace GHelper.USB
{
public static class XGM
{
const int XGM_ID = 0x1970;
public const int ASUS_ID = 0x0b05;
public static void Write(byte[] data)
{
HidDeviceLoader loader = new HidDeviceLoader();
HidDevice device = loader.GetDevices(ASUS_ID, XGM_ID).Where(device => device.GetMaxFeatureReportLength() >= 300).FirstOrDefault();
if (device is null) return;
try
{
using (HidStream hidStream = device.Open())
{
var payload = new byte[300];
Array.Copy(data, payload, data.Length);
hidStream.Write(payload);
Logger.WriteLine("XGM " + device.ProductID + "|" + device.GetMaxFeatureReportLength() + ":" + BitConverter.ToString(data));
hidStream.Close();
}
}
catch (Exception ex)
{
Debug.WriteLine($"Error accessing HID device: {ex.Message}");
}
}
public static void Init()
{
Write(Encoding.ASCII.GetBytes("^ASUS Tech.Inc."));
}
public static void Light(bool status)
{
Write(new byte[] { 0x5e, 0xc5, status ? (byte)0x50 : (byte)0 });
}
public static void Reset()
{
Write(new byte[] { 0x5e, 0xd1, 0x02 });
}
public static void SetFan(byte[] curve)
{
if (AsusACPI.IsInvalidCurve(curve)) return;
byte[] msg = new byte[19];
Array.Copy(new byte[] { 0x5e, 0xd1, 0x01 }, msg, 3);
Array.Copy(curve, 0, msg, 3, curve.Length);
Write(msg);
}
}
}