From c2aa4da1db2369cfd2f61337560e115eab8c4e0b Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Wed, 17 Jan 2024 12:18:59 +0100 Subject: [PATCH] Ally Mappings --- app/Ally/AllyControl.cs | 57 ++++++++++++++++++++--------------------- app/Handheld.cs | 2 +- app/USB/AsusHid.cs | 4 +-- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/app/Ally/AllyControl.cs b/app/Ally/AllyControl.cs index 92eb95a6..1cab2627 100644 --- a/app/Ally/AllyControl.cs +++ b/app/Ally/AllyControl.cs @@ -1,7 +1,6 @@ using GHelper.Gpu.AMD; using GHelper.Input; using GHelper.USB; -using System.Text; namespace GHelper.Ally { @@ -35,7 +34,7 @@ namespace GHelper.Ally SettingsForm settings; static ControllerMode mode = ControllerMode.Auto; - static ControllerMode _autoMode = ControllerMode.Auto; + static ControllerMode _applyMode = ControllerMode.Auto; static int _autoCount = 0; static int fpsLimit = -1; @@ -232,16 +231,16 @@ namespace GHelper.Ally { float fps = amdControl.GetFPS(); - ControllerMode _newMode = (fps > 0) ? ControllerMode.Gamepad : ControllerMode.Mouse; + ControllerMode newMode = (fps > 0) ? ControllerMode.Gamepad : ControllerMode.Mouse; - if (_autoMode != _newMode) _autoCount++; + if (_applyMode != newMode) _autoCount++; else _autoCount = 0; if (_autoCount > 2) { - _autoMode = _newMode; + _applyMode = newMode; _autoCount = 0; - ApplyMode(_autoMode, "ControllerAuto"); + ApplyMode(_applyMode); Logger.WriteLine(fps.ToString()); } @@ -374,7 +373,7 @@ namespace GHelper.Ally byte[] init = new byte[] { AsusHid.INPUT_ID, 0xd1, 0x02, (byte)zone, 0x2c }; init.CopyTo(bindings, 0); - + DecodeBinding(Key1).CopyTo(bindings, 5); DecodeBinding(Key1).CopyTo(bindings, 16); @@ -388,22 +387,6 @@ namespace GHelper.Ally - } - - static public void SetMapping() - { - MappingZone(BindingZone.DPadUpDown); - MappingZone(BindingZone.DPadLeftRight); - MappingZone(BindingZone.StickClick); - MappingZone(BindingZone.Bumper); - MappingZone(BindingZone.AB); - MappingZone(BindingZone.XY); - MappingZone(BindingZone.ViewMenu); - MappingZone(BindingZone.M1M2); - MappingZone(BindingZone.Trigger); - - AsusHid.WriteInput(MappingSave); - } static public void SetDeadzones() @@ -429,20 +412,36 @@ namespace GHelper.Ally } - private void ApplyMode(ControllerMode applyMode, string log = "ControllerMode") + public static void ApplyMode(ControllerMode? applyMode = null) { - //AsusHid.WriteInput(new byte[] { AsusHid.INPUT_ID, 0xd1, 0x0b, 0x01, (byte)applyMode }, log); - AsusHid.WriteInput(new byte[] { AsusHid.INPUT_ID, 0xd1, 0x01, 0x01, (byte)applyMode }, log); + + if (applyMode is not null) _applyMode = (ControllerMode)applyMode; + + AsusHid.WriteInput(new byte[] { AsusHid.INPUT_ID, 0xd1, 0x01, 0x01, (byte)_applyMode }, "Controller"); + AsusHid.WriteInput(MappingSave); + + if (_applyMode == ControllerMode.Gamepad) + { + MappingZone(BindingZone.DPadUpDown); + MappingZone(BindingZone.DPadLeftRight); + MappingZone(BindingZone.StickClick); + MappingZone(BindingZone.Bumper); + MappingZone(BindingZone.AB); + MappingZone(BindingZone.XY); + MappingZone(BindingZone.ViewMenu); + } + + MappingZone(BindingZone.M1M2); + MappingZone(BindingZone.Trigger); + AsusHid.WriteInput(MappingSave); - - SetMapping(); } private void SetMode(ControllerMode mode) { if (mode == ControllerMode.Auto) { - _autoMode = ControllerMode.Auto; + _applyMode = ControllerMode.Auto; amdControl.StartFPS(); timer.Start(); } diff --git a/app/Handheld.cs b/app/Handheld.cs index 148e67e1..2b34ef0f 100644 --- a/app/Handheld.cs +++ b/app/Handheld.cs @@ -110,7 +110,7 @@ namespace GHelper if (value >= 0) AppConfig.Set(combo.Name, value); else AppConfig.Remove(combo.Name); - AllyControl.SetMapping(); + AllyControl.ApplyMode(); } private void Controller_Complete(object? sender, EventArgs e) diff --git a/app/USB/AsusHid.cs b/app/USB/AsusHid.cs index 31c20ea5..7aac7f6c 100644 --- a/app/USB/AsusHid.cs +++ b/app/USB/AsusHid.cs @@ -57,7 +57,7 @@ public static class AsusHid return null; } - public static void WriteInput(byte[] data, string log = "USB") + public static void WriteInput(byte[] data, string? log = "USB") { foreach (var device in FindDevices(INPUT_ID)) { @@ -68,7 +68,7 @@ public static class AsusHid var payload = new byte[device.GetMaxFeatureReportLength()]; Array.Copy(data, payload, data.Length); stream.SetFeature(payload); - Logger.WriteLine($"{log} {device.ProductID.ToString("X")}|{device.GetMaxFeatureReportLength()}: {BitConverter.ToString(data)}"); + if (log is not null) Logger.WriteLine($"{log} {device.ProductID.ToString("X")}|{device.GetMaxFeatureReportLength()}: {BitConverter.ToString(data)}"); } } catch (Exception ex)