From 3fbd833e21e9d9ec10f08a73eb21e4d510ce4cdc Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sun, 21 Jan 2024 15:35:56 +0100 Subject: [PATCH] XGM binding for Ally https://github.com/seerge/g-helper/issues/1964 --- app/Ally/AllyControl.cs | 3 +++ app/Input/InputDispatcher.cs | 4 ++++ app/Input/KeyboardListener.cs | 15 ++++++++------- app/Settings.cs | 6 +++--- app/USB/Aura.cs | 19 +++++++++++-------- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/app/Ally/AllyControl.cs b/app/Ally/AllyControl.cs index d22d64ba..8c4581c6 100644 --- a/app/Ally/AllyControl.cs +++ b/app/Ally/AllyControl.cs @@ -88,6 +88,7 @@ namespace GHelper.Ally public const string BindBrightnessDown = "04-04-8C-88-8A-05"; public const string BindBrightnessUp = "04-04-8C-88-8A-06"; + public const string BindXGM = "04-04-8C-88-8A-04"; public const string BindOverlay = "04-03-8C-88-44"; @@ -152,6 +153,8 @@ namespace GHelper.Ally { BindCloseWindow, "Close Window" }, { BindShiftTab, "Shift-Tab" }, { BindAltTab, "Alt-Tab" }, + { BindXGM, "XGM Toggle" }, + { BindEsc, "Esc" }, { BindBack, "Backspace" }, diff --git a/app/Input/InputDispatcher.cs b/app/Input/InputDispatcher.cs index 9c69a977..d85df4e9 100644 --- a/app/Input/InputDispatcher.cs +++ b/app/Input/InputDispatcher.cs @@ -145,6 +145,7 @@ namespace GHelper.Input { hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, Keys.F1); hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, Keys.F2); + hook.RegisterHotKey(ModifierKeys.Shift | ModifierKeys.Control | ModifierKeys.Alt, Keys.F3); } // FN-Lock group @@ -370,6 +371,9 @@ namespace GHelper.Input case Keys.F2: SetBrightness(10); break; + case Keys.F3: + Program.settingsForm.gpuControl.ToggleXGM(); + break; case Keys.F14: Program.settingsForm.gpuControl.SetGPUMode(AsusACPI.GPUModeEco); break; diff --git a/app/Input/KeyboardListener.cs b/app/Input/KeyboardListener.cs index 776ac43e..0b6ce49e 100644 --- a/app/Input/KeyboardListener.cs +++ b/app/Input/KeyboardListener.cs @@ -1,6 +1,6 @@ -using HidSharp; -using GHelper.USB; -using GHelper.Ally; +using GHelper.USB; +using HidSharp; +using System.Text; namespace GHelper.Input { @@ -16,17 +16,17 @@ namespace GHelper.Input var task = Task.Run(Listen); } - private void Listen () { + private void Listen() + { HidStream? input = AsusHid.FindHidStream(AsusHid.INPUT_ID); // Fallback int count = 0; - while (input == null && count++ < 5) + while (input == null && count++ < 10) { - Aura.Init(); - Thread.Sleep(2000); + Thread.Sleep(1000); input = AsusHid.FindHidStream(AsusHid.INPUT_ID); } @@ -36,6 +36,7 @@ namespace GHelper.Input return; } + AsusHid.WriteInput(Encoding.ASCII.GetBytes("ZASUS Tech.Inc.")); Logger.WriteLine($"Input: {input.Device.DevicePath}"); try diff --git a/app/Settings.cs b/app/Settings.cs index bd9c6ff3..1f02ad2d 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -1324,10 +1324,11 @@ namespace GHelper public void VisualiseGPUMode(int GPUMode = -1) { - if (AppConfig.IsAlly() && !Program.acpi.IsXGConnected()) + if (AppConfig.IsAlly()) { tableGPU.Visible = false; - GPUMode = AsusACPI.GPUModeEco; + if (Program.acpi.IsXGConnected()) tableAMD.Controls.Add(buttonXGM, 1, 0); + return; } ButtonEnabled(buttonOptimized, true); @@ -1370,7 +1371,6 @@ namespace GHelper VisualizeXGM(GPUMode); - if (isGpuSection) { menuEco.Checked = buttonEco.Activated; diff --git a/app/USB/Aura.cs b/app/USB/Aura.cs index dc7c6af8..a448596b 100644 --- a/app/USB/Aura.cs +++ b/app/USB/Aura.cs @@ -264,12 +264,13 @@ namespace GHelper.USB new byte[] { AsusHid.AURA_ID, 0xB9 }, Encoding.ASCII.GetBytes("]ASUS Tech.Inc."), new byte[] { AsusHid.AURA_ID, 0x05, 0x20, 0x31, 0, 0x1A }, + new byte[] { AsusHid.AURA_ID, 0x05, 0x20, 0x31, 0, 0x10 }, // Random data AC sends to keyboard on start + /* new byte[] { AsusHid.AURA_ID, 0x9F, 0x01 }, new byte[] { AsusHid.AURA_ID, 0xBF }, - new byte[] { AsusHid.AURA_ID, 0x05, 0x20, 0x31, 0, 0x10 }, new byte[] { AsusHid.AURA_ID, 0x05, 0x20, 0x31, 0, 0x20 }, new byte[] { AsusHid.AURA_ID, 0xC0, 0x03, 0x01}, @@ -277,10 +278,11 @@ namespace GHelper.USB Encoding.ASCII.GetBytes("]ASUS Tech.Inc."), new byte[] { AsusHid.AURA_ID, 0x05, 0x20, 0x31, 0, 0x1A }, - new byte[] { AsusHid.AURA_ID, 0xC0, 0x00, 0x01}, - }, "Init"); + */ - AsusHid.WriteInput(Encoding.ASCII.GetBytes("ZASUS Tech.Inc.")); + new byte[] { AsusHid.AURA_ID, 0xC0, 0x00, 0x01}, + + }, "Init"); } @@ -483,7 +485,7 @@ namespace GHelper.USB byte[] keyBuf = new byte[mapSize]; buffer[0] = AsusHid.AURA_ID; - buffer[1] = 0xbc; + buffer[1] = 0xBC; buffer[2] = 0; buffer[3] = 1; buffer[4] = 1; @@ -494,7 +496,7 @@ namespace GHelper.USB if (init) { Init(); - AsusHid.WriteAura(new byte[] { AsusHid.AURA_ID, 0xbc }); + AsusHid.WriteAura(new byte[] { AsusHid.AURA_ID, 0xBC }); } Array.Clear(keyBuf, 0, keyBuf.Length); @@ -531,7 +533,8 @@ namespace GHelper.USB buffer[6] = 0x00; buffer[7] = 0x00; - if (isStrix4Zone) { // per zone + if (isStrix4Zone) + { // per zone var leds_4_zone = packet4Zone.Count(); for (int ledIndex = 0; ledIndex < leds_4_zone; ledIndex++) { @@ -705,7 +708,7 @@ namespace GHelper.USB bound.Y += bound.Height / 3; bound.Height -= (int)Math.Round(bound.Height * (0.33f + 0.022f)); // cut 1/3 of the top screen + windows panel - Bitmap screen_low = AmbientData.CamptureScreen(bound, 512, 288); //quality decreases greatly if it is less 512 ; + Bitmap screen_low = AmbientData.CamptureScreen(bound, 512, 288); //quality decreases greatly if it is less 512 ; Bitmap screeb_pxl = AmbientData.ResizeImage(screen_low, 4, 2); // 4x2 zone. top for keyboard and bot for lightbar; int zones = AURA_ZONES;