Skip to content

Commit

Permalink
Implement support for Rog Ally X (#362)
Browse files Browse the repository at this point in the history
* Initial commit

* add oem118 failsafe

* todo: check PnPDevice PID/VID to deploy the appropriate inf

* use vendorID and productID to pull the appropriate XInput driver

- Generic XInput: xusb22.inf
- Custom XInput (Rog Ally X): oem118.inf

* Fixed an issue causing a crash on empty profile.TDPOverrideValues

* Revert "Fixed an issue causing a crash on empty profile.TDPOverrideValues"

This reverts commit 5fa36ec0c594c5f817ba80e35329ff72217b6c29.

* improve controller drivers store logic

* remove SuspendedControllers

* improve DeviceManager fail-safe drivers restoration

* add rog_ally_x illustration, thanks to @romracer

* oups

* improve memory management

* improve virtual controller disposal on suspend

* Fixed an issue affecting Alt Gr key locking LControl

* Fixed an issue causing a crash when failing to retrieve deviceInfo for OneXPlayerX1

* Fix an issue preventing HC to load properly on X1Mini, which doesn't seams to have a serial chip

* update libraries

* remove splashscreen loading text

* on popular demand, improve UI navigation when desktop layout is enabled

inputs sent to UI are now post layout management

* improve gamepad navigation on combobox. Handle disabled ComboBoxItem

* prevent disabled comboBoxItem from being selected

* clear hidDevices array on device Close()

* build 0.21.6.1

* update ROGAllyX default power profiles

* code cleanup

* make PerformanceGuids public
  • Loading branch information
Valkirie authored Oct 9, 2024
1 parent fcedca0 commit 5f11fe4
Show file tree
Hide file tree
Showing 29 changed files with 269 additions and 243 deletions.
2 changes: 1 addition & 1 deletion HandheldCompanion.iss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define InstallerVersion '0.2'
#define MyAppSetupName 'Handheld Companion'
#define MyBuildId 'HandheldCompanion'
#define MyAppVersion '0.21.6.0'
#define MyAppVersion '0.21.6.1'
#define MyAppPublisher 'BenjaminLSR'
#define MyAppCopyright 'Copyright @ BenjaminLSR'
#define MyAppURL 'https://github.com/Valkirie/HandheldCompanion'
Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Controllers/IController.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public partial class IController : UserControl
private Thread workingThread;
private bool workingThreadRunning;

protected object hidlock = new();
protected object hidLock = new();

public virtual bool IsReady => true;
public virtual bool IsWireless => false;
Expand Down
4 changes: 2 additions & 2 deletions HandheldCompanion/Controllers/NeptuneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private void Close()

public override void Hide(bool powerCycle = true)
{
lock (hidlock)
lock (hidLock)
{
Close();
base.Hide(powerCycle);
Expand All @@ -305,7 +305,7 @@ public override void Unhide(bool powerCycle = true)
if (IsExclusiveMode)
return;

lock (hidlock)
lock (hidLock)
{
Close();
base.Unhide(powerCycle);
Expand Down
8 changes: 1 addition & 7 deletions HandheldCompanion/Controllers/RumbleConverter.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HandheldCompanion.Controllers
namespace HandheldCompanion.Controllers
{
// Function to map the Xbox rumble value to Nintendo Switch HD Rumble
public class RumbleConverter
Expand Down
1 change: 1 addition & 0 deletions HandheldCompanion/Controls/ProcessEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ public void Dispose()
Process?.Dispose();
MainThread?.Dispose();
ChildrenProcessIds.Dispose();
ProcessWindows.Clear();

GC.SuppressFinalize(this); //now, the finalizer won't be called
}
Expand Down
9 changes: 5 additions & 4 deletions HandheldCompanion/Devices/ASUS/ROGAlly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public ROGAlly()
OEMPowerMode = (int)AsusMode.Silent,
OSPowerMode = OSPowerMode.BetterBattery,
CPUBoostLevel = CPUBoostLevel.Disabled,
Guid = new("961cc777-2547-4f9d-8174-7d86181b8a7a"),
Guid = BetterBatteryGuid,
TDPOverrideEnabled = true,
TDPOverrideValues = new[] { 10.0d, 10.0d, 10.0d }
});
Expand All @@ -140,7 +140,7 @@ public ROGAlly()
DeviceDefault = true,
OEMPowerMode = (int)AsusMode.Performance,
OSPowerMode = OSPowerMode.BetterPerformance,
Guid = new("3af9B8d9-7c97-431d-ad78-34a8bfea439f"),
Guid = BetterPerformanceGuid,
TDPOverrideEnabled = true,
TDPOverrideValues = new[] { 15.0d, 15.0d, 15.0d }
});
Expand All @@ -151,7 +151,7 @@ public ROGAlly()
DeviceDefault = true,
OEMPowerMode = (int)AsusMode.Turbo,
OSPowerMode = OSPowerMode.BestPerformance,
Guid = new("ded574b5-45a0-4f42-8737-46345c09c238"),
Guid = BestPerformanceGuid,
TDPOverrideEnabled = true,
TDPOverrideValues = new[] { 25.0d, 25.0d, 25.0d }
});
Expand Down Expand Up @@ -367,6 +367,8 @@ public override void Close()
}
}

hidDevices.Clear();

base.Close();
}

Expand Down Expand Up @@ -709,7 +711,6 @@ public void SendHidControlWrite(byte[] data)
if (device.IsConnected)
device.WriteFeatureData(data);
}

}

public void SetBatteryChargeLimit(int chargeLimit)
Expand Down
33 changes: 33 additions & 0 deletions HandheldCompanion/Devices/ASUS/ROGAllyX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using HandheldCompanion.Misc;
using System.Linq;
using System.Numerics;

namespace HandheldCompanion.Devices;

public class ROGAllyX : ROGAlly
{
public ROGAllyX()
{
// device specific settings
ProductIllustration = "device_rog_ally_x";

// used to monitor OEM specific inputs
_pid = 0x1B4C;

// overwrite ROGAlly default gyrometer axis settings
GyrometerAxis = new Vector3(1.0f, 1.0f, -1.0f);

// overwrite ROGAlly default power profiles
PowerProfile powerProfile = DevicePowerProfiles.FirstOrDefault(profile => profile.Guid == BetterBatteryGuid);
if (powerProfile != null)
powerProfile.TDPOverrideValues = new[] { 13.0d, 13.0d, 13.0d };

powerProfile = DevicePowerProfiles.FirstOrDefault(profile => profile.Guid == BetterPerformanceGuid);
if (powerProfile != null)
powerProfile.TDPOverrideValues = new[] { 17.0d, 17.0d, 17.0d };

powerProfile = DevicePowerProfiles.FirstOrDefault(profile => profile.Guid == BestPerformanceGuid);
if (powerProfile != null)
powerProfile.TDPOverrideValues = new[] { 25.0d, 25.0d, 25.0d };
}
}
50 changes: 7 additions & 43 deletions HandheldCompanion/Devices/IDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Sentry;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
using System.Windows.Media;
Expand Down Expand Up @@ -66,6 +65,10 @@ public abstract class IDevice
public delegate void KeyReleasedEventHandler(ButtonFlags button);
public delegate void PowerStatusChangedEventHandler(IDevice device);

public static readonly Guid BetterBatteryGuid = new Guid("961cc777-2547-4f9d-8174-7d86181b8a7a");
public static readonly Guid BetterPerformanceGuid = new Guid("3af9B8d9-7c97-431d-ad78-34a8bfea439f");
public static readonly Guid BestPerformanceGuid = new Guid("ded574b5-45a0-4f42-8737-46345c09c238");

protected static OpenLibSys openLibSys;
protected object updateLock = new();

Expand Down Expand Up @@ -479,6 +482,9 @@ public static IDevice GetCurrent()
case "RC71L":
device = new ROGAlly();
break;
case "RC72LA":
device = new ROGAllyX();
break;
}
}
break;
Expand Down Expand Up @@ -865,48 +871,6 @@ public bool HasKey()
return false;
}

protected void ResumeDevices()
{
List<string> successes = [];

StringCollection deviceInstanceIds = SettingsManager.GetStringCollection("SuspendedDevices");

if (deviceInstanceIds is null)
deviceInstanceIds = [];

foreach (string InstanceId in deviceInstanceIds)
{
if (PnPUtil.EnableDevice(InstanceId))
successes.Add(InstanceId);
}

foreach (string InstanceId in successes)
deviceInstanceIds.Remove(InstanceId);

SettingsManager.SetProperty("SuspendedDevices", deviceInstanceIds);
}

protected bool SuspendDevice(string InterfaceId)
{
PnPDevice pnPDevice = PnPDevice.GetDeviceByInterfaceId(InterfaceId);
if (pnPDevice is not null)
{
StringCollection deviceInstanceIds = SettingsManager.GetStringCollection("SuspendedDevices");

if (deviceInstanceIds is null)
deviceInstanceIds = [];

if (!deviceInstanceIds.Contains(pnPDevice.InstanceId))
deviceInstanceIds.Add(pnPDevice.InstanceId);

SettingsManager.SetProperty("SuspendedDevices", deviceInstanceIds);

return PnPUtil.DisableDevice(pnPDevice.InstanceId);
}

return false;
}

public static IEnumerable<HidDevice> GetHidDevices(int vendorId, int deviceId, int minFeatures = 1)
{
HidDevice[] HidDeviceList = HidDevices.Enumerate(vendorId, new int[] { deviceId }).ToArray();
Expand Down
8 changes: 5 additions & 3 deletions HandheldCompanion/Devices/Lenovo/LegionGo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public LegionGo()
OSPowerMode = OSPowerMode.BetterBattery,
CPUBoostLevel = CPUBoostLevel.Disabled,
OEMPowerMode = (int)LegionMode.Quiet,
Guid = new("961cc777-2547-4f9d-8174-7d86181b8a7a"),
Guid = BetterBatteryGuid,
TDPOverrideEnabled = true,
TDPOverrideValues = new[] { 8.0d, 8.0d, 8.0d }
});
Expand All @@ -257,7 +257,7 @@ public LegionGo()
DeviceDefault = true,
OSPowerMode = OSPowerMode.BetterPerformance,
OEMPowerMode = (int)LegionMode.Balanced,
Guid = new("3af9B8d9-7c97-431d-ad78-34a8bfea439f"),
Guid = BetterPerformanceGuid,
TDPOverrideEnabled = true,
TDPOverrideValues = new[] { 15.0d, 15.0d, 15.0d }
});
Expand All @@ -269,7 +269,7 @@ public LegionGo()
DeviceDefault = true,
OSPowerMode = OSPowerMode.BestPerformance,
OEMPowerMode = (int)LegionMode.Performance,
Guid = new("ded574b5-45a0-4f42-8737-46345c09c238"),
Guid = BestPerformanceGuid,
TDPOverrideEnabled = true,
TDPOverrideValues = new[] { 20.0d, 20.0d, 20.0d }
});
Expand Down Expand Up @@ -381,6 +381,8 @@ public override void Close()
device.CloseDevice();
}

hidDevices.Clear();

// Reset the fan speed to default before device shutdown/restart
SetFanFullSpeedAsync(false);

Expand Down
6 changes: 3 additions & 3 deletions HandheldCompanion/Devices/MSI/ClawA1M.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public ClawA1M()
DeviceDefault = true,
OSPowerMode = OSPowerMode.BetterBattery,
CPUBoostLevel = CPUBoostLevel.Disabled,
Guid = new("961cc777-2547-4f9d-8174-7d86181b8a7a"),
Guid = BetterBatteryGuid,
TDPOverrideEnabled = true,
TDPOverrideValues = new[] { 20.0d, 20.0d, 20.0d }
});
Expand All @@ -125,7 +125,7 @@ public ClawA1M()
Default = true,
DeviceDefault = true,
OSPowerMode = OSPowerMode.BetterPerformance,
Guid = new("3af9B8d9-7c97-431d-ad78-34a8bfea439f"),
Guid = BetterPerformanceGuid,
TDPOverrideEnabled = true,
TDPOverrideValues = new[] { 30.0d, 30.0d, 30.0d }
});
Expand All @@ -135,7 +135,7 @@ public ClawA1M()
Default = true,
DeviceDefault = true,
OSPowerMode = OSPowerMode.BestPerformance,
Guid = new("ded574b5-45a0-4f42-8737-46345c09c238"),
Guid = BestPerformanceGuid,
TDPOverrideEnabled = true,
TDPOverrideValues = new[] { 35.0d, 35.0d, 35.0d }
});
Expand Down
7 changes: 3 additions & 4 deletions HandheldCompanion/Devices/Minisforum/MinisforumV3.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using HandheldCompanion.Managers;
using HandheldCompanion.Misc;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -63,7 +62,7 @@ public MinisforumV3()
OSPowerMode = OSPowerMode.BetterBattery,
OEMPowerMode = (int)MinisForumMode.Quiet,
CPUBoostLevel = CPUBoostLevel.Disabled,
Guid = new("961cc777-2547-4f9d-8174-7d86181b8a7a"),
Guid = BetterBatteryGuid,
TDPOverrideEnabled = true,
TDPOverrideValues = new[] { 15.0d, 15.0d, 15.0d }
});
Expand All @@ -74,7 +73,7 @@ public MinisforumV3()
DeviceDefault = true,
OSPowerMode = OSPowerMode.BetterPerformance,
OEMPowerMode = (int)MinisForumMode.Balanced,
Guid = new("3af9B8d9-7c97-431d-ad78-34a8bfea439f"),
Guid = BetterPerformanceGuid,
TDPOverrideEnabled = true,
TDPOverrideValues = new[] { 22.0d, 22.0d, 22.0d }
});
Expand All @@ -85,7 +84,7 @@ public MinisforumV3()
DeviceDefault = true,
OSPowerMode = OSPowerMode.BestPerformance,
OEMPowerMode = (int)MinisForumMode.Performance,
Guid = new("ded574b5-45a0-4f42-8737-46345c09c238"),
Guid = BestPerformanceGuid,
TDPOverrideEnabled = true,
TDPOverrideValues = new[] { 28.0d, 28.0d, 28.0d }
});
Expand Down
32 changes: 18 additions & 14 deletions HandheldCompanion/Devices/OneXPlayer/OneXPlayerX1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,27 @@ public override bool Open()

if (EnableSerialPort)
{
var devices = GetSerialDevices();
List<USBDeviceInfo> devices = GetSerialDevices();

USBDeviceInfo deviceInfo = devices.FirstOrDefault(a => a.Name.Contains(SerialPortDeviceName));

var SerialPortName = Regex.Match(deviceInfo.Name, "COM\\d+").Value;

// Add the serial port name to be excluded for other instances
SerialUSBIMU.SerialPortNamesInUse.Add(SerialPortName);

// Initialize and open the serial port if it has not been initialized yet
if (_serialPort is null)
if (deviceInfo is null)
{
_serialPort = new SerialPort(SerialPortName, SerialPortBaudRate, SerialPortParity, SerialPortDataBits,
SerialPortStopBits);
_serialPort.Open();

LogManager.LogInformation("Enabled Serial Port Control: {0}", _serialPort.PortName);
LogManager.LogInformation("Failed to retrieve serial device with name: {0}", SerialPortDeviceName);
}
else
{
// Add the serial port name to be excluded for other instances
string SerialPortName = Regex.Match(deviceInfo.Name, "COM\\d+").Value;
SerialUSBIMU.SerialPortNamesInUse.Add(SerialPortName);

// Initialize and open the serial port if it has not been initialized yet
if (_serialPort is null)
{
_serialPort = new SerialPort(SerialPortName, SerialPortBaudRate, SerialPortParity, SerialPortDataBits, SerialPortStopBits);
_serialPort.Open();

LogManager.LogInformation("Enabled Serial Port Control: {0}", _serialPort.PortName);
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions HandheldCompanion/Devices/OneXPlayer/OneXPlayerX1Intel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public OneXPlayerX1Intel()
DeviceDefault = true,
OSPowerMode = OSPowerMode.BetterBattery,
CPUBoostLevel = CPUBoostLevel.Disabled,
Guid = new("961cc777-2547-4f9d-8174-7d86181b8a7a"),
Guid = BetterBatteryGuid,
TDPOverrideEnabled = true,
TDPOverrideValues = new[] { 15.0d, 15.0d, 15.0d }
});
Expand All @@ -32,7 +32,7 @@ public OneXPlayerX1Intel()
DeviceDefault = true,
OSPowerMode = OSPowerMode.BetterPerformance,
CPUBoostLevel = CPUBoostLevel.Enabled,
Guid = new("3af9B8d9-7c97-431d-ad78-34a8bfea439f"),
Guid = BetterPerformanceGuid,
TDPOverrideEnabled = true,
TDPOverrideValues = new[] { 30.0d, 30.0d, 30.0d }
});
Expand All @@ -44,7 +44,7 @@ public OneXPlayerX1Intel()
DeviceDefault = true,
OSPowerMode = OSPowerMode.BestPerformance,
CPUBoostLevel = CPUBoostLevel.Enabled,
Guid = new("ded574b5-45a0-4f42-8737-46345c09c238"),
Guid = BestPerformanceGuid,
TDPOverrideEnabled = true,
TDPOverrideValues = new[] { 35.0d, 35.0d, 64.0d },
EPPOverrideEnabled = true,
Expand Down
2 changes: 2 additions & 0 deletions HandheldCompanion/Devices/OneXPlayer/OneXPlayerX1Mini.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ public OneXPlayerX1Mini()
cTDP = new double[] { 15, 30 };
GfxClock = new double[] { 100, 2700 };
CpuClock = 5100;

EnableSerialPort = false;
}
}
Loading

0 comments on commit 5f11fe4

Please sign in to comment.