From 83fed695e483dbc2ec730703af7c5df5a8b58a51 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sat, 13 Jan 2024 23:38:12 +0100 Subject: [PATCH] Ally controller tweaks --- app/Ally/AllyControl.cs | 11 +++++++++-- app/Input/KeyboardListener.cs | 18 ++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/Ally/AllyControl.cs b/app/Ally/AllyControl.cs index 207a2602..5ffeb670 100644 --- a/app/Ally/AllyControl.cs +++ b/app/Ally/AllyControl.cs @@ -20,7 +20,7 @@ namespace GHelper.Ally SettingsForm settings; static ControllerMode mode = ControllerMode.Auto; - static ControllerMode _autoMode = ControllerMode.Gamepad; + static ControllerMode _autoMode = ControllerMode.Auto; static int _autoCount = 0; static int fpsLimit = -1; @@ -60,14 +60,15 @@ namespace GHelper.Ally if (AppConfig.IsAlly()) settings.VisualiseAlly(true); else return; + Deadzones(); SetMode((ControllerMode)AppConfig.Get("controller_mode", (int)ControllerMode.Auto)); + settings.VisualiseBacklight(InputDispatcher.GetBacklight()); fpsLimit = amdControl.GetFPSLimit(); Logger.WriteLine($"FPS Limit: {fpsLimit}"); settings.VisualiseFPSLimit(fpsLimit); - } public void ToggleFPSLimit() @@ -102,10 +103,16 @@ namespace GHelper.Ally settings.VisualiseBacklight(InputDispatcher.GetBacklight()); } + private void Deadzones() + { + AsusHid.WriteInput(new byte[] { AsusHid.INPUT_ID, 0xd1, 4, 4, 0, 100, 0, 100 }, "ControllerDeadzone"); + } + private void SetMode(ControllerMode mode) { if (mode == ControllerMode.Auto) { + _autoMode = ControllerMode.Auto; amdControl.StartFPS(); timer.Start(); } diff --git a/app/Input/KeyboardListener.cs b/app/Input/KeyboardListener.cs index 72ae6441..b7b1468a 100644 --- a/app/Input/KeyboardListener.cs +++ b/app/Input/KeyboardListener.cs @@ -7,17 +7,27 @@ namespace GHelper.Input { CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); + Action _handler; public KeyboardListener(Action KeyHandler) { + _handler = KeyHandler; + Listen(); + } + + private void Listen () { + HidStream? input = AsusHid.FindHidStream(AsusHid.INPUT_ID); - + // Fallback - if (input == null) + + int count = 0; + + while (input == null && count++ < 60) { Aura.Init(); Thread.Sleep(1000); - input = input = AsusHid.FindHidStream(AsusHid.INPUT_ID); + input = AsusHid.FindHidStream(AsusHid.INPUT_ID); } if (input == null) @@ -48,7 +58,7 @@ namespace GHelper.Input if (data.Length > 1 && data[0] == AsusHid.INPUT_ID && data[1] > 0 && data[1] != 236) { Logger.WriteLine($"Key: {data[1]}"); - KeyHandler(data[1]); + _handler(data[1]); } }