diff --git a/app/AsusACPI.cs b/app/AsusACPI.cs index ac981ea3..0baa2bf4 100644 --- a/app/AsusACPI.cs +++ b/app/AsusACPI.cs @@ -32,6 +32,7 @@ public class AsusACPI const uint DSTS = 0x53545344; const uint DEVS = 0x53564544; + const uint INIT = 0x54494E49; public const uint UniversalControl = 0x00100021; public const int KB_Light_Up = 0xc4; @@ -161,7 +162,7 @@ public class AsusACPI public void RunListener() { - eventHandle = CreateEvent(IntPtr.Zero, false, false, "ATK Event"); + eventHandle = CreateEvent(IntPtr.Zero, false, false, "ATK4001"); byte[] outBuffer = new byte[16]; byte[] data = new byte[8]; @@ -178,7 +179,7 @@ public class AsusACPI WaitForSingleObject(eventHandle, Timeout.Infinite); Control(0x222408, new byte[0], outBuffer); int code = BitConverter.ToInt32(outBuffer); - Logger.WriteLine("Code: " + code); + Logger.WriteLine("ACPI Code: " + code); } } @@ -240,6 +241,13 @@ public class AsusACPI } + public byte[] DeviceInit() + { + byte[] args = new byte[8]; + return CallMethod(INIT, args); + + } + public int DeviceSet(uint DeviceID, int Status, string logName) { byte[] args = new byte[8]; diff --git a/app/AsusUSB.cs b/app/AsusUSB.cs index 5f1492f1..a7f95467 100644 --- a/app/AsusUSB.cs +++ b/app/AsusUSB.cs @@ -229,9 +229,9 @@ namespace GHelper public static void Init() { - Task.Run(() => + Task.Run(async () => { - var devices = GetHidDevices(deviceIds); + var devices = GetHidDevices(deviceIds, 0); foreach (HidDevice device in devices) { device.OpenDevice(); @@ -248,7 +248,7 @@ namespace GHelper public static void ApplyBrightness(int brightness) { - Task.Run(() => + Task.Run(async () => { byte[] msg = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness }; diff --git a/app/Gpu/NvidiaGpuControl.cs b/app/Gpu/NvidiaGpuControl.cs index 870fad9a..57114f62 100644 --- a/app/Gpu/NvidiaGpuControl.cs +++ b/app/Gpu/NvidiaGpuControl.cs @@ -182,7 +182,7 @@ public class NvidiaGpuControl : IGpuControl } catch (Exception ex) { - Logger.WriteLine(ex.Message); + Debug.WriteLine(ex.Message); return null; } } diff --git a/app/HardwareControl.cs b/app/HardwareControl.cs index 8ac3e237..017a9750 100644 --- a/app/HardwareControl.cs +++ b/app/HardwareControl.cs @@ -151,6 +151,7 @@ public static class HardwareControl GpuControl?.Dispose(); IGpuControl _gpuControl = new NvidiaGpuControl(); + if (_gpuControl.IsValid) { GpuControl = _gpuControl; diff --git a/app/InputDispatcher.cs b/app/InputDispatcher.cs index 30ee5325..92cd466c 100644 --- a/app/InputDispatcher.cs +++ b/app/InputDispatcher.cs @@ -1,6 +1,7 @@ using HidLibrary; using Microsoft.Win32; using NAudio.CoreAudioApi; +using System.Collections.Generic; using System.Diagnostics; using System.Management; using Tools; @@ -15,17 +16,9 @@ namespace GHelper public KeyboardListener(Action KeyHandler) { HidDevice? input = AsusUSB.GetDevice(); + if (input == null) return; - if (input == null) - { - Logger.WriteLine("Input device not found"); - return; - } - else - { - Logger.WriteLine("Listener input " + input.DevicePath); - } - + Logger.WriteLine($"Input: {input.DevicePath}"); var task = Task.Run(() => { @@ -36,7 +29,7 @@ namespace GHelper var data = input.Read().Data; if (data.Length > 1 && data[0] == AsusUSB.INPUT_HID_ID && data[1] > 0) { - Logger.WriteLine("Key:" + data[1]); + Logger.WriteLine($"Key: {data[1]}"); KeyHandler(data[1]); } } @@ -62,7 +55,6 @@ namespace GHelper public class InputDispatcher { - private static bool isOptimizationRunning = OptimizationService.IsRunning(); private static nint windowHandle; public static Keys keyProfile = Keys.F5; @@ -76,7 +68,12 @@ namespace GHelper windowHandle = handle; + byte[] result = Program.acpi.DeviceInit(); + Debug.WriteLine($"Init: {BitConverter.ToString(result)}"); + Program.acpi.SubscribeToEvents(WatcherEventArrived); + //Task.Run(Program.acpi.RunListener); + // CTRL + SHIFT + F5 to cycle profiles if (AppConfig.getConfig("keybind_profile") != -1) keyProfile = (Keys)AppConfig.getConfig("keybind_profile"); @@ -95,6 +92,7 @@ namespace GHelper if (!OptimizationService.IsRunning()) listener = new KeyboardListener(HandleEvent); + } @@ -160,7 +158,7 @@ namespace GHelper action = "aura"; if (name == "fnf5") action = "performance"; - if (name == "m3" && !isOptimizationRunning) + if (name == "m3" && !OptimizationService.IsRunning()) action = "micmute"; } @@ -251,16 +249,13 @@ namespace GHelper return; } - if (isOptimizationRunning) return; + if (OptimizationService.IsRunning()) return; // Asus Optimization service Events int backlight = AppConfig.getConfig("keyboard_brightness"); - string[] backlightNames = new string[] { "Off", "Low", "Mid", "Max" }; - int brightness; - switch (EventID) { case 197: // FN+F2 @@ -289,7 +284,7 @@ namespace GHelper break; case 107: // FN+F10 bool touchpadState = GetTouchpadState(); - if (!AsusUSB.TouchpadToggle()) Program.acpi.DeviceSet(AsusACPI.UniversalControl, 0x6B, "Touchpad"); + AsusUSB.TouchpadToggle(); Program.settingsForm.BeginInvoke(Program.settingsForm.RunToast, touchpadState ? "Off" : "On", ToastIcon.Touchpad); break; case 108: // FN+F11 diff --git a/app/OptimizationService.cs b/app/OptimizationService.cs index 6f5973ac..c54ab72f 100644 --- a/app/OptimizationService.cs +++ b/app/OptimizationService.cs @@ -39,6 +39,7 @@ namespace GHelper { return (Process.GetProcessesByName("AsusOptimization").Count() > 0); } + } } \ No newline at end of file diff --git a/app/Settings.cs b/app/Settings.cs index 380f839c..0e6c65e9 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -1436,6 +1436,8 @@ namespace GHelper GpuMode = AsusACPI.GPUModeStandard; UltimateUI(mux == 1); + + if (eco < 0) tableGPU.Visible = false; }