Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve gyro support on Rog Ally, AYANEO Air Plus (#649) #1

Merged
merged 1 commit into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions ControllerCommon/Devices/ASUS/ROGAlly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ROGAlly : IDevice
};

private bool previousWasEmpty;
private List<HidStream> _hidStreams = new();

public ROGAlly()
{
Expand Down Expand Up @@ -81,8 +82,8 @@ public override bool Open()

// prepare configuration
var deviceConfiguration = new OpenConfiguration();
deviceConfiguration.SetOption(OpenOption.Exclusive, true);
deviceConfiguration.SetOption(OpenOption.Transient, true);
deviceConfiguration.SetOption(OpenOption.Exclusive, false);
deviceConfiguration.SetOption(OpenOption.Transient, false);

foreach (var _hidDevice in DeviceList.Local.GetHidDevices()
.Where(d => d.ProductID == _pid && d.VendorID == _vid))
Expand All @@ -91,13 +92,20 @@ public override bool Open()
var deviceDescriptor = _hidDevice.GetReportDescriptor();

if (!_hidDevice.TryOpen(deviceConfiguration, out var inputStream)) continue;

// add stream to array
_hidStreams.Add(inputStream);

foreach (var inputReport in deviceDescriptor.InputReports)
{
var hiddeviceInputParser = inputReport.DeviceItem.CreateDeviceItemInputParser();
var hidDeviceInputReceiver = deviceDescriptor.CreateHidDeviceInputReceiver();

DeviceItemInputParser hiddeviceInputParser = inputReport.DeviceItem.CreateDeviceItemInputParser();
HidDeviceInputReceiver hidDeviceInputReceiver = deviceDescriptor.CreateHidDeviceInputReceiver();

// listen for event(s)
hidDeviceInputReceiver.Received += (sender, e) =>
InputReportReciever_Received(_hidDevice, hiddeviceInputParser, hidDeviceInputReceiver);
InputReportReceiver_Received(_hidDevice, hiddeviceInputParser, hidDeviceInputReceiver);

// start receiver
hidDeviceInputReceiver.Start(inputStream);
}
}
Expand All @@ -107,10 +115,17 @@ public override bool Open()

public override void Close()
{
// close stream(s)
foreach (HidStream stream in _hidStreams)
stream.Close();

// clear array
_hidStreams.Clear();

base.Close();
}

private void InputReportReciever_Received(HidDevice hidDevice, DeviceItemInputParser hiddeviceInputParser,
private void InputReportReceiver_Received(HidDevice hidDevice, DeviceItemInputParser hiddeviceInputParser,
HidDeviceInputReceiver hidDeviceInputReceiver)
{
var inputReportBuffer = new byte[hidDevice.GetMaxInputReportLength()];
Expand Down
5 changes: 4 additions & 1 deletion ControllerCommon/Devices/IDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ public void PullSensors()

public bool RestartSensor()
{
var deviceId = sensor.DeviceId.Replace("\\1", string.Empty);
if (sensor is null)
return false;

string deviceId = sensor.DeviceId.Replace("\\1", string.Empty);
return LegacyDevcon.Restart(deviceId);
}

Expand Down
42 changes: 25 additions & 17 deletions ControllerCommon/LegacyDevcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace ControllerCommon
public static class LegacyDevcon
{
private static readonly string path;
private static readonly ProcessStartInfo startInfo;
private static bool _IsInstalled;

static LegacyDevcon()
{
Expand All @@ -25,31 +25,39 @@ static LegacyDevcon()
return;
}

startInfo = new ProcessStartInfo(path)
{
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
};
_IsInstalled = true;
}

public static bool Restart(string InstanceId)
{
// register command
startInfo.Arguments = $"restart \"{InstanceId}\"";
using (var ProcessOutput = Process.Start(startInfo))
if (!_IsInstalled)
return false;

string output = string.Empty;
using (Process process = new Process())
{
string output = ProcessOutput.StandardOutput.ReadToEnd();
process.StartInfo.FileName = path;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;

// register command
process.StartInfo.Arguments = $"restart \"{InstanceId}\"";

ProcessOutput.WaitForExit();
process.Start();

if (output.Contains("No matching devices found."))
return false;
else if (output.Contains("Restarted"))
return true;
StreamReader reader = process.StandardOutput;
output = reader.ReadToEnd();

process.WaitForExit();
}

if (output.Contains("No matching devices found."))
return false;
else if (output.Contains("Restarted"))
return true;

return false;
}
}
Expand Down
7 changes: 7 additions & 0 deletions ControllerService/ControllerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,15 @@ public ControllerService(IHostApplicationLifetime lifetime)
case "AYANEOAIRPlus":
case "ROGAlly":
{
LogManager.LogInformation("Restarting: {0}", CurrentDevice.InternalSensorName);

if (CurrentDevice.RestartSensor())
{
// give the device some breathing space once restarted
Thread.Sleep(500);

LogManager.LogInformation("Successfully restarted: {0}", CurrentDevice.InternalSensorName);
}
else
LogManager.LogError("Failed to restart: {0}", CurrentDevice.InternalSensorName);
}
Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion HandheldCompanion/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
<value>Decrease system or currently applied profile TDP by one watt</value>
</data>
<data name="InputsHotkey_fallbackInput" xml:space="preserve">
<value>Press to define hotkey input</value>
<value>Press to define trigger</value>
</data>
<data name="InputsHotkey_fallbackOutput" xml:space="preserve">
<value>Press to define keyboard output</value>
Expand Down