mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Aura HID fixes https://github.com/seerge/g-helper/issues/1616
This commit is contained in:
@@ -14,21 +14,18 @@ public static class AsusHid
|
||||
|
||||
static HidStream? auraStream;
|
||||
|
||||
public static IEnumerable<HidDevice>? FindDevices(byte reportId, int minFeatureLength = 1)
|
||||
public static IEnumerable<HidDevice>? FindDevices(byte reportId)
|
||||
{
|
||||
HidDeviceLoader loader = new HidDeviceLoader();
|
||||
IEnumerable<HidDevice> deviceList;
|
||||
|
||||
try
|
||||
{
|
||||
deviceList = loader.GetDevices(ASUS_ID).Where(
|
||||
device => deviceIds.Contains(device.ProductID) &&
|
||||
device.CanOpen &&
|
||||
device.GetMaxFeatureReportLength() >= minFeatureLength);
|
||||
deviceList = loader.GetDevices(ASUS_ID).Where(device => deviceIds.Contains(device.ProductID) && device.CanOpen && device.GetMaxFeatureReportLength() > 0);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"Error enumerating HID devices: {ex.Message}");
|
||||
Logger.WriteLine($"Error enumerating HID devices: {ex.Message}");
|
||||
yield break;
|
||||
}
|
||||
|
||||
@@ -37,28 +34,50 @@ public static class AsusHid
|
||||
yield return device;
|
||||
}
|
||||
|
||||
public static HidStream? FindHidStream(byte reportId, int minFeatureLength = 1)
|
||||
public static HidStream? FindHidStream(byte reportId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return FindDevices(reportId, minFeatureLength)?.FirstOrDefault()?.Open();
|
||||
return FindDevices(reportId)?.FirstOrDefault()?.Open();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"Error accessing HID device: {ex.Message}");
|
||||
Logger.WriteLine($"Error accessing HID device: {ex.Message}");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void Write(byte[] data, byte reportId = AURA_ID, string log = "USB")
|
||||
public static void WriteInput(byte[] data, string log = "USB")
|
||||
{
|
||||
Write(new List<byte[]> { data }, reportId, log);
|
||||
foreach (var device in FindDevices(INPUT_ID))
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var stream = device.Open())
|
||||
{
|
||||
var payload = new byte[device.GetMaxFeatureReportLength()];
|
||||
Array.Copy(data, payload, data.Length);
|
||||
stream.SetFeature(payload);
|
||||
Logger.WriteLine($"{log} Feature {device.ProductID.ToString("X")}|{device.GetMaxFeatureReportLength()}: {BitConverter.ToString(data)}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.WriteLine($"Error setting feature {device.GetMaxFeatureReportLength()} {device.DevicePath}: {BitConverter.ToString(data)} {ex.Message}");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Write(List<byte[]> dataList, byte reportId = AURA_ID, string log = "USB")
|
||||
public static void Write(byte[] data, string log = "USB")
|
||||
{
|
||||
var devices = FindDevices(reportId);
|
||||
Write(new List<byte[]> { data }, log);
|
||||
}
|
||||
|
||||
public static void Write(List<byte[]> dataList, string log = "USB")
|
||||
{
|
||||
var devices = FindDevices(AURA_ID);
|
||||
if (devices is null) return;
|
||||
|
||||
try
|
||||
@@ -68,12 +87,12 @@ public static class AsusHid
|
||||
foreach (var data in dataList)
|
||||
{
|
||||
stream.Write(data);
|
||||
Logger.WriteLine($"{log} " + device.ProductID.ToString("X") + ": " + BitConverter.ToString(data));
|
||||
Logger.WriteLine($"{log} {device.ProductID.ToString("X")}: {BitConverter.ToString(data)}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"Error writing {log} to HID device: {ex.Message}");
|
||||
Logger.WriteLine($"Error writing {log}: {ex.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -263,9 +263,9 @@ namespace GHelper.USB
|
||||
if (delay) await Task.Delay(TimeSpan.FromSeconds(1));
|
||||
if (isACPI) Program.acpi.TUFKeyboardBrightness(brightness);
|
||||
|
||||
AsusHid.Write(new byte[] { AsusHid.AURA_ID, 0xba, 0xc5, 0xc4, (byte)brightness }, AsusHid.AURA_ID, log);
|
||||
AsusHid.Write(new byte[] { AsusHid.AURA_ID, 0xba, 0xc5, 0xc4, (byte)brightness }, log);
|
||||
if (AppConfig.ContainsModel("GA503"))
|
||||
AsusHid.Write(new byte[] { AsusHid.INPUT_ID, 0xba, 0xc5, 0xc4, (byte)brightness }, AsusHid.INPUT_ID, log);
|
||||
AsusHid.WriteInput(new byte[] { AsusHid.INPUT_ID, 0xba, 0xc5, 0xc4, (byte)brightness }, log);
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user