Ally Mappings

This commit is contained in:
Serge
2024-01-17 12:18:59 +01:00
parent adcbe33fbb
commit c2aa4da1db
3 changed files with 31 additions and 32 deletions

View File

@@ -1,7 +1,6 @@
using GHelper.Gpu.AMD; using GHelper.Gpu.AMD;
using GHelper.Input; using GHelper.Input;
using GHelper.USB; using GHelper.USB;
using System.Text;
namespace GHelper.Ally namespace GHelper.Ally
{ {
@@ -35,7 +34,7 @@ namespace GHelper.Ally
SettingsForm settings; SettingsForm settings;
static ControllerMode mode = ControllerMode.Auto; static ControllerMode mode = ControllerMode.Auto;
static ControllerMode _autoMode = ControllerMode.Auto; static ControllerMode _applyMode = ControllerMode.Auto;
static int _autoCount = 0; static int _autoCount = 0;
static int fpsLimit = -1; static int fpsLimit = -1;
@@ -232,16 +231,16 @@ namespace GHelper.Ally
{ {
float fps = amdControl.GetFPS(); 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; else _autoCount = 0;
if (_autoCount > 2) if (_autoCount > 2)
{ {
_autoMode = _newMode; _applyMode = newMode;
_autoCount = 0; _autoCount = 0;
ApplyMode(_autoMode, "ControllerAuto"); ApplyMode(_applyMode);
Logger.WriteLine(fps.ToString()); Logger.WriteLine(fps.ToString());
} }
@@ -374,7 +373,7 @@ namespace GHelper.Ally
byte[] init = new byte[] { AsusHid.INPUT_ID, 0xd1, 0x02, (byte)zone, 0x2c }; byte[] init = new byte[] { AsusHid.INPUT_ID, 0xd1, 0x02, (byte)zone, 0x2c };
init.CopyTo(bindings, 0); init.CopyTo(bindings, 0);
DecodeBinding(Key1).CopyTo(bindings, 5); DecodeBinding(Key1).CopyTo(bindings, 5);
DecodeBinding(Key1).CopyTo(bindings, 16); 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() 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); AsusHid.WriteInput(MappingSave);
SetMapping();
} }
private void SetMode(ControllerMode mode) private void SetMode(ControllerMode mode)
{ {
if (mode == ControllerMode.Auto) if (mode == ControllerMode.Auto)
{ {
_autoMode = ControllerMode.Auto; _applyMode = ControllerMode.Auto;
amdControl.StartFPS(); amdControl.StartFPS();
timer.Start(); timer.Start();
} }

View File

@@ -110,7 +110,7 @@ namespace GHelper
if (value >= 0) AppConfig.Set(combo.Name, value); if (value >= 0) AppConfig.Set(combo.Name, value);
else AppConfig.Remove(combo.Name); else AppConfig.Remove(combo.Name);
AllyControl.SetMapping(); AllyControl.ApplyMode();
} }
private void Controller_Complete(object? sender, EventArgs e) private void Controller_Complete(object? sender, EventArgs e)

View File

@@ -57,7 +57,7 @@ public static class AsusHid
return null; 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)) foreach (var device in FindDevices(INPUT_ID))
{ {
@@ -68,7 +68,7 @@ public static class AsusHid
var payload = new byte[device.GetMaxFeatureReportLength()]; var payload = new byte[device.GetMaxFeatureReportLength()];
Array.Copy(data, payload, data.Length); Array.Copy(data, payload, data.Length);
stream.SetFeature(payload); 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) catch (Exception ex)