mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Backlight fix
This commit is contained in:
@@ -53,16 +53,19 @@ namespace GHelper
|
|||||||
public static class AsusUSB
|
public static class AsusUSB
|
||||||
{
|
{
|
||||||
|
|
||||||
public const byte HID_ID = 0x5a;
|
public const int ASUS_ID = 0x0b05;
|
||||||
|
|
||||||
public static readonly byte[] LED_INIT1 = new byte[] { 0x5d, 0xb9 };
|
public const byte INPUT_HID_ID = 0x5a;
|
||||||
|
public const byte AURA_HID_ID = 0x5d;
|
||||||
|
|
||||||
|
public static readonly byte[] LED_INIT1 = new byte[] { AURA_HID_ID, 0xb9 };
|
||||||
public static readonly byte[] LED_INIT2 = Encoding.ASCII.GetBytes("]ASUS Tech.Inc.");
|
public static readonly byte[] LED_INIT2 = Encoding.ASCII.GetBytes("]ASUS Tech.Inc.");
|
||||||
public static readonly byte[] LED_INIT3 = new byte[] { 0x5d, 0x05, 0x20, 0x31, 0, 0x08 };
|
public static readonly byte[] LED_INIT3 = new byte[] { AURA_HID_ID, 0x05, 0x20, 0x31, 0, 0x08 };
|
||||||
public static readonly byte[] LED_INIT4 = Encoding.ASCII.GetBytes("^ASUS Tech.Inc.");
|
public static readonly byte[] LED_INIT4 = Encoding.ASCII.GetBytes("^ASUS Tech.Inc.");
|
||||||
public static readonly byte[] LED_INIT5 = new byte[] { 0x5e, 0x05, 0x20, 0x31, 0, 0x08 };
|
public static readonly byte[] LED_INIT5 = new byte[] { 0x5e, 0x05, 0x20, 0x31, 0, 0x08 };
|
||||||
|
|
||||||
static byte[] MESSAGE_SET = { 0x5d, 0xb5, 0, 0, 0 };
|
static byte[] MESSAGE_SET = { AURA_HID_ID, 0xb5, 0, 0, 0 };
|
||||||
static byte[] MESSAGE_APPLY = { 0x5d, 0xb4 };
|
static byte[] MESSAGE_APPLY = { AURA_HID_ID, 0xb4 };
|
||||||
|
|
||||||
static int[] deviceIds = { 0x1a30, 0x1854, 0x1869, 0x1866, 0x19b6, 0x1822, 0x1837, 0x1854, 0x184a, 0x183d, 0x8502, 0x1807, 0x17e0, 0x18c6 };
|
static int[] deviceIds = { 0x1a30, 0x1854, 0x1869, 0x1866, 0x19b6, 0x1822, 0x1837, 0x1854, 0x184a, 0x183d, 0x8502, 0x1807, 0x17e0, 0x18c6 };
|
||||||
|
|
||||||
@@ -174,72 +177,42 @@ namespace GHelper
|
|||||||
|
|
||||||
private static IEnumerable<HidDevice> GetHidDevices(int[] deviceIds, int minInput = 18)
|
private static IEnumerable<HidDevice> GetHidDevices(int[] deviceIds, int minInput = 18)
|
||||||
{
|
{
|
||||||
HidDevice[] HidDeviceList = HidDevices.Enumerate(0x0b05, deviceIds).ToArray();
|
HidDevice[] HidDeviceList = HidDevices.Enumerate(ASUS_ID, deviceIds).ToArray();
|
||||||
foreach (HidDevice device in HidDeviceList)
|
foreach (HidDevice device in HidDeviceList)
|
||||||
if (device.IsConnected
|
if (device.IsConnected
|
||||||
&& device.Capabilities.FeatureReportByteLength > 0
|
&& device.Capabilities.FeatureReportByteLength > 0
|
||||||
&& device.Capabilities.InputReportByteLength >= minInput) //
|
&& device.Capabilities.InputReportByteLength >= minInput)
|
||||||
yield return device;
|
yield return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HidDevice? GetInputDevice()
|
public static HidDevice? GetDevice(byte reportID = INPUT_HID_ID)
|
||||||
{
|
{
|
||||||
HidDevice[] HidDeviceList = HidDevices.Enumerate(0x0b05, deviceIds).ToArray();
|
HidDevice[] HidDeviceList = HidDevices.Enumerate(ASUS_ID, deviceIds).ToArray();
|
||||||
HidDevice input = null;
|
HidDevice input = null;
|
||||||
|
|
||||||
foreach (HidDevice device in HidDeviceList)
|
foreach (HidDevice device in HidDeviceList)
|
||||||
if (device.ReadFeatureData(out byte[] data, HID_ID))
|
if (device.ReadFeatureData(out byte[] data, reportID))
|
||||||
{
|
{
|
||||||
input = device;
|
input = device;
|
||||||
Logger.WriteLine("Input Events" + device.Capabilities.FeatureReportByteLength + "|" + device.Capabilities.InputReportByteLength + device.Description + device.DevicePath);
|
//Logger.WriteLine("HID Device("+ reportID + ")" + + device.Capabilities.FeatureReportByteLength + "|" + device.Capabilities.InputReportByteLength + device.DevicePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input is null) Logger.WriteLine("Input device not found");
|
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool TouchpadToggle()
|
public static bool TouchpadToggle()
|
||||||
{
|
{
|
||||||
HidDevice? input = GetInputDevice();
|
HidDevice? input = GetDevice();
|
||||||
if (input != null) return input.WriteFeatureData(new byte[] { HID_ID, 0xf4, 0x6b });
|
if (input != null) return input.WriteFeatureData(new byte[] { INPUT_HID_ID, 0xf4, 0x6b });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RunListener(Action<int> KeyHandler)
|
|
||||||
{
|
|
||||||
HidDevice? input = GetInputDevice();
|
|
||||||
if (input == null) return;
|
|
||||||
|
|
||||||
//Logger.WriteLine("Input Events " + input.DevicePath);
|
|
||||||
|
|
||||||
var task = Task.Run(() =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
var data = input.Read().Data;
|
|
||||||
if (data.Length > 1 && data[0] == HID_ID && data[1] > 0)
|
|
||||||
{
|
|
||||||
Logger.WriteLine("Key:" + data[1]);
|
|
||||||
KeyHandler(data[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Logger.WriteLine(ex.ToString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] AuraMessage(int mode, Color color, Color color2, int speed)
|
public static byte[] AuraMessage(int mode, Color color, Color color2, int speed)
|
||||||
{
|
{
|
||||||
|
|
||||||
byte[] msg = new byte[17];
|
byte[] msg = new byte[17];
|
||||||
msg[0] = 0x5d;
|
msg[0] = AURA_HID_ID;
|
||||||
msg[1] = 0xb3;
|
msg[1] = 0xb3;
|
||||||
msg[2] = 0x00; // Zone
|
msg[2] = 0x00; // Zone
|
||||||
msg[3] = (byte)mode; // Aura Mode
|
msg[3] = (byte)mode; // Aura Mode
|
||||||
@@ -277,14 +250,15 @@ namespace GHelper
|
|||||||
{
|
{
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
byte[] msg = { 0x5d, 0xba, 0xc5, 0xc4, (byte)brightness };
|
|
||||||
|
|
||||||
var devices = GetHidDevices(deviceIds);
|
byte[] msg = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };
|
||||||
|
Logger.WriteLine("KB Backlight:" + BitConverter.ToString(msg));
|
||||||
|
|
||||||
|
var devices = GetHidDevices(deviceIds, 0);
|
||||||
foreach (HidDevice device in devices)
|
foreach (HidDevice device in devices)
|
||||||
{
|
{
|
||||||
device.OpenDevice();
|
device.OpenDevice();
|
||||||
device.WriteFeatureData(msg);
|
device.WriteFeatureData(msg);
|
||||||
Logger.WriteLine("USB-KB " + device.Capabilities.FeatureReportByteLength + ":" + BitConverter.ToString(msg));
|
|
||||||
device.CloseDevice();
|
device.CloseDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Win32;
|
using HidLibrary;
|
||||||
|
using Microsoft.Win32;
|
||||||
using NAudio.CoreAudioApi;
|
using NAudio.CoreAudioApi;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Management;
|
using System.Management;
|
||||||
@@ -6,6 +7,58 @@ using Tools;
|
|||||||
|
|
||||||
namespace GHelper
|
namespace GHelper
|
||||||
{
|
{
|
||||||
|
public class KeyboardListener
|
||||||
|
{
|
||||||
|
|
||||||
|
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
|
||||||
|
|
||||||
|
public KeyboardListener(Action<int> KeyHandler)
|
||||||
|
{
|
||||||
|
HidDevice? input = AsusUSB.GetDevice();
|
||||||
|
|
||||||
|
if (input == null)
|
||||||
|
{
|
||||||
|
Logger.WriteLine("Input device not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger.WriteLine("Listener input " + input.DevicePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var task = Task.Run(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while (!cancellationTokenSource.Token.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
var data = input.Read().Data;
|
||||||
|
if (data.Length > 1 && data[0] == AsusUSB.INPUT_HID_ID && data[1] > 0)
|
||||||
|
{
|
||||||
|
Logger.WriteLine("Key:" + data[1]);
|
||||||
|
KeyHandler(data[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Logger.WriteLine("Listener stopped");
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.WriteLine(ex.ToString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
cancellationTokenSource?.Cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class InputDispatcher
|
public class InputDispatcher
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -14,6 +67,8 @@ namespace GHelper
|
|||||||
|
|
||||||
public static Keys keyProfile = Keys.F5;
|
public static Keys keyProfile = Keys.F5;
|
||||||
|
|
||||||
|
KeyboardListener listener;
|
||||||
|
|
||||||
KeyHandler m1, m2, togggle;
|
KeyHandler m1, m2, togggle;
|
||||||
|
|
||||||
public InputDispatcher(nint handle)
|
public InputDispatcher(nint handle)
|
||||||
@@ -23,8 +78,6 @@ namespace GHelper
|
|||||||
|
|
||||||
Program.acpi.SubscribeToEvents(WatcherEventArrived);
|
Program.acpi.SubscribeToEvents(WatcherEventArrived);
|
||||||
|
|
||||||
if (!isOptimizationRunning) AsusUSB.RunListener(HandleEvent);
|
|
||||||
|
|
||||||
// CTRL + SHIFT + F5 to cycle profiles
|
// CTRL + SHIFT + F5 to cycle profiles
|
||||||
if (AppConfig.getConfig("keybind_profile") != -1) keyProfile = (Keys)AppConfig.getConfig("keybind_profile");
|
if (AppConfig.getConfig("keybind_profile") != -1) keyProfile = (Keys)AppConfig.getConfig("keybind_profile");
|
||||||
|
|
||||||
@@ -33,8 +86,19 @@ namespace GHelper
|
|||||||
m2 = new KeyHandler(KeyHandler.NOMOD, Keys.VolumeUp, windowHandle);
|
m2 = new KeyHandler(KeyHandler.NOMOD, Keys.VolumeUp, windowHandle);
|
||||||
|
|
||||||
RegisterKeys();
|
RegisterKeys();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void InitListener()
|
||||||
|
{
|
||||||
|
if (listener is not null) listener.Dispose();
|
||||||
|
|
||||||
|
if (!OptimizationService.IsRunning())
|
||||||
|
listener = new KeyboardListener(HandleEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void RegisterKeys()
|
public void RegisterKeys()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using NAudio.CoreAudioApi;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Management;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
using Tools;
|
|
||||||
using static NativeMethods;
|
using static NativeMethods;
|
||||||
|
|
||||||
namespace GHelper
|
namespace GHelper
|
||||||
@@ -43,11 +40,11 @@ namespace GHelper
|
|||||||
|
|
||||||
string language = AppConfig.getConfigString("language");
|
string language = AppConfig.getConfigString("language");
|
||||||
|
|
||||||
if (language != null && language.Length > 0)
|
if (language != null && language.Length > 0)
|
||||||
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(language);
|
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(language);
|
||||||
else
|
else
|
||||||
Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentUICulture;
|
Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentUICulture;
|
||||||
|
|
||||||
Debug.WriteLine(CultureInfo.CurrentUICulture);
|
Debug.WriteLine(CultureInfo.CurrentUICulture);
|
||||||
//Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr");
|
//Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("fr");
|
||||||
|
|
||||||
@@ -86,7 +83,7 @@ namespace GHelper
|
|||||||
settingsForm.InitMatrix();
|
settingsForm.InitMatrix();
|
||||||
settingsForm.SetStartupCheck(Startup.IsScheduled());
|
settingsForm.SetStartupCheck(Startup.IsScheduled());
|
||||||
|
|
||||||
|
|
||||||
SetAutoModes();
|
SetAutoModes();
|
||||||
|
|
||||||
// Subscribing for system power change events
|
// Subscribing for system power change events
|
||||||
@@ -103,7 +100,7 @@ namespace GHelper
|
|||||||
SettingsToggle(action);
|
SettingsToggle(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Application.Run();
|
Application.Run();
|
||||||
|
|
||||||
@@ -147,6 +144,8 @@ namespace GHelper
|
|||||||
isPlugged = SystemInformation.PowerStatus.PowerLineStatus;
|
isPlugged = SystemInformation.PowerStatus.PowerLineStatus;
|
||||||
Logger.WriteLine("AutoSetting for " + isPlugged.ToString());
|
Logger.WriteLine("AutoSetting for " + isPlugged.ToString());
|
||||||
|
|
||||||
|
inputDispatcher.InitListener();
|
||||||
|
|
||||||
settingsForm.SetBatteryChargeLimit(AppConfig.getConfig("charge_limit"));
|
settingsForm.SetBatteryChargeLimit(AppConfig.getConfig("charge_limit"));
|
||||||
settingsForm.AutoPerformance();
|
settingsForm.AutoPerformance();
|
||||||
|
|
||||||
|
|||||||
@@ -187,7 +187,7 @@
|
|||||||
<value>Limite à 60 Hz pour éco. batterie, valeur normale sur secteur</value>
|
<value>Limite à 60 Hz pour éco. batterie, valeur normale sur secteur</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Awake" xml:space="preserve">
|
<data name="Awake" xml:space="preserve">
|
||||||
<value>Éveillé</value>
|
<value>Allumé</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="BacklightTimeout" xml:space="preserve">
|
<data name="BacklightTimeout" xml:space="preserve">
|
||||||
<value>Délai (secondes) avant extinction rétroéclairage</value>
|
<value>Délai (secondes) avant extinction rétroéclairage</value>
|
||||||
@@ -199,7 +199,7 @@
|
|||||||
<value>Limite de charge </value>
|
<value>Limite de charge </value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Boot" xml:space="preserve">
|
<data name="Boot" xml:space="preserve">
|
||||||
<value>Lors du démarrage</value>
|
<value>Au démarrage</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Brightness" xml:space="preserve">
|
<data name="Brightness" xml:space="preserve">
|
||||||
<value>Luminosité</value>
|
<value>Luminosité</value>
|
||||||
@@ -361,7 +361,7 @@
|
|||||||
<value>Désactiver le micro</value>
|
<value>Désactiver le micro</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="OpenGHelper" xml:space="preserve">
|
<data name="OpenGHelper" xml:space="preserve">
|
||||||
<value>Ouvrir la fenêtre G-Helper</value>
|
<value>Ouvrir G-Helper</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Optimized" xml:space="preserve">
|
<data name="Optimized" xml:space="preserve">
|
||||||
<value>Optimisé</value>
|
<value>Optimisé</value>
|
||||||
|
|||||||
@@ -93,8 +93,6 @@ namespace GHelper
|
|||||||
comboMatrix.DropDownClosed += ComboMatrix_SelectedValueChanged;
|
comboMatrix.DropDownClosed += ComboMatrix_SelectedValueChanged;
|
||||||
comboMatrixRunning.DropDownClosed += ComboMatrixRunning_SelectedValueChanged;
|
comboMatrixRunning.DropDownClosed += ComboMatrixRunning_SelectedValueChanged;
|
||||||
|
|
||||||
checkMatrix.CheckedChanged += CheckMatrix_CheckedChanged; ;
|
|
||||||
|
|
||||||
buttonMatrix.Click += ButtonMatrix_Click;
|
buttonMatrix.Click += ButtonMatrix_Click;
|
||||||
|
|
||||||
checkStartup.CheckedChanged += CheckStartup_CheckedChanged;
|
checkStartup.CheckedChanged += CheckStartup_CheckedChanged;
|
||||||
@@ -735,7 +733,7 @@ namespace GHelper
|
|||||||
comboMatrixRunning.SelectedIndex = (running != -1) ? Math.Min(running, comboMatrixRunning.Items.Count - 1) : 0;
|
comboMatrixRunning.SelectedIndex = (running != -1) ? Math.Min(running, comboMatrixRunning.Items.Count - 1) : 0;
|
||||||
|
|
||||||
checkMatrix.Checked = (AppConfig.getConfig("matrix_auto") == 1);
|
checkMatrix.Checked = (AppConfig.getConfig("matrix_auto") == 1);
|
||||||
|
checkMatrix.CheckedChanged += CheckMatrix_CheckedChanged;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1267,13 +1265,12 @@ namespace GHelper
|
|||||||
{
|
{
|
||||||
AsusUSB.Init();
|
AsusUSB.Init();
|
||||||
|
|
||||||
if (AppConfig.getConfig("keyboard_auto") != 1) return;
|
int backlight = AppConfig.getConfig("keyboard_brightness");
|
||||||
|
|
||||||
if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online)
|
if (AppConfig.isConfig("keyboard_auto") && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online)
|
||||||
AsusUSB.ApplyBrightness(3);
|
|
||||||
else
|
|
||||||
AsusUSB.ApplyBrightness(0);
|
AsusUSB.ApplyBrightness(0);
|
||||||
|
else if (backlight >= 0)
|
||||||
|
AsusUSB.ApplyBrightness(backlight);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user