diff --git a/app/Program.cs b/app/Program.cs index 9af94d86..761005f1 100644 --- a/app/Program.cs +++ b/app/Program.cs @@ -97,7 +97,7 @@ namespace GHelper gpuControl.InitXGM(); - SetAutoModes(init : true); + SetAutoModes(init: true); // Subscribing for system power change events SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; diff --git a/app/USB/Aura.cs b/app/USB/Aura.cs index 74da514e..1836034e 100644 --- a/app/USB/Aura.cs +++ b/app/USB/Aura.cs @@ -1,8 +1,6 @@ using GHelper.Gpu; using GHelper.Helpers; using GHelper.Input; -using Microsoft.VisualBasic.Devices; -using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Runtime.InteropServices; @@ -214,7 +212,7 @@ namespace GHelper.USB return; if (Mode == AuraMode.HEATMAP) - { + { CustomRGB.ApplyHeatmap(); } else if (Mode == AuraMode.AMBIENT) @@ -267,7 +265,7 @@ namespace GHelper.USB if (isACPI) Program.acpi.TUFKeyboardBrightness(brightness); AsusHid.Write(new byte[] { AsusHid.AURA_ID, 0xba, 0xc5, 0xc4, (byte)brightness }, AsusHid.AURA_ID, log); - if (AppConfig.ContainsModel("GA503")) + if (AppConfig.ContainsModel("GA503")) AsusHid.Write(new byte[] { AsusHid.INPUT_ID, 0xba, 0xc5, 0xc4, (byte)brightness }, AsusHid.INPUT_ID, log); }); @@ -361,7 +359,8 @@ namespace GHelper.USB } - public static void ApplyColor(Color color, bool init = false) { + public static void ApplyColor(Color color, bool init = false) + { Color[] color_list = Enumerable.Repeat(color, 0x12).ToArray(); ApplyColor(color_list, init); } @@ -470,7 +469,8 @@ namespace GHelper.USB } - public static class CustomRGB { + public static class CustomRGB + { public static void ApplyGPUColor() { @@ -538,7 +538,7 @@ namespace GHelper.USB else { screeb_pxl = AmbientData.ResizeImage(screen_low, 1, 1); - var average = ColorUtils.HSV.UpSaturation(screeb_pxl.GetPixel(0, 0), (float)0.7); + var average = ColorUtils.HSV.UpSaturation(screeb_pxl.GetPixel(0, 0), (float)0.3); for (int i = 0; i < 4; i++) //just color transfer from the bottom screen on keyboard AmbientData.Colors[i].RGB = average; } diff --git a/app/USB/XGM.cs b/app/USB/XGM.cs index 8aac792f..c5895507 100644 --- a/app/USB/XGM.cs +++ b/app/USB/XGM.cs @@ -1,7 +1,6 @@ // Reference : thanks to https://github.com/RomanYazvinsky/ for initial discovery of XGM payloads using HidSharp; -using System.Diagnostics; using System.Text; namespace GHelper.USB @@ -9,30 +8,37 @@ namespace GHelper.USB public static class XGM { const int XGM_ID = 0x1970; - public const int ASUS_ID = 0x0b05; + const int ASUS_ID = 0x0b05; + public static void Write(byte[] data) { HidDeviceLoader loader = new HidDeviceLoader(); - HidDevice device = loader.GetDevices(ASUS_ID, XGM_ID).Where(device => device.GetMaxFeatureReportLength() >= 300).FirstOrDefault(); - if (device is null) return; - try { + HidDevice device = loader.GetDevices(ASUS_ID, XGM_ID).Where(device => device.CanOpen && device.GetMaxFeatureReportLength() >= 300).FirstOrDefault(); + + if (device is null) + { + Logger.WriteLine("XGM SUB device not found"); + return; + } + using (HidStream hidStream = device.Open()) { var payload = new byte[300]; Array.Copy(data, payload, data.Length); - hidStream.Write(payload); - Logger.WriteLine("XGM " + device.ProductID + "|" + device.GetMaxFeatureReportLength() + ":" + BitConverter.ToString(data)); + hidStream.SetFeature(payload); + Logger.WriteLine("XGM-" + device.ProductID + "|" + device.GetMaxFeatureReportLength() + ":" + BitConverter.ToString(data)); hidStream.Close(); } } catch (Exception ex) { - Debug.WriteLine($"Error accessing HID device: {ex.Message}"); + Logger.WriteLine($"Error accessing XGM device: {ex}"); } + } public static void Init()