Fix for turkish keyboard, tweak for default fan curves

This commit is contained in:
Serge
2023-05-13 22:13:00 +02:00
parent 82a39bcfa1
commit 608b8571d4
4 changed files with 73 additions and 21 deletions

View File

@@ -1,4 +1,5 @@
using GHelper;
using System.Globalization;
using System.IO.Pipes;
using System.Management;
using System.Runtime.InteropServices;
@@ -205,7 +206,7 @@ public class ASUSWmi
byte[] args = new byte[8];
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
byte[] status = CallMethod(DSTS, args);
return BitConverter.ToInt32(status, 0) - 65536;
}
@@ -215,7 +216,7 @@ public class ASUSWmi
byte[] args = new byte[8];
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
BitConverter.GetBytes((uint)Status).CopyTo(args, 4);
return CallMethod(DSTS, args);
}
@@ -242,8 +243,8 @@ public class ASUSWmi
int result;
//for (int i = 8; i < curve.Length; i++)
// curve[i] = Math.Max((byte)0, Math.Min((byte)99, curve[i])); // it seems to be a bug, when some old model's bios can go nuts if fan is set to 100%
for (int i = 8; i < curve.Length; i++)
curve[i] = Math.Max((byte)0, Math.Min((byte)99, curve[i])); // it seems to be a bug, when some old model's bios can go nuts if fan is set to 100%
switch (device)
{
@@ -285,6 +286,47 @@ public class ASUSWmi
}
public static bool IsEmptyCurve(byte[] curve) {
return curve.Length != 16 || curve.All(singleByte => singleByte == 0);
}
public static byte[] FixFanCurve(byte[] curve)
{
if (curve.Length != 16) throw new Exception("Incorrect curve");
var points = new Dictionary<byte, byte>();
for (int i = 0; i < 8; i++) points[curve[i]] = curve[i+8];
var pointsFixed = new Dictionary<byte, byte>();
bool fix = false;
int count = 0;
foreach (var pair in points.OrderBy(x => x.Key))
{
if (count == 0 && pair.Key >= 40)
{
fix = true;
pointsFixed.Add(20, 0);
}
if (count != 3 || !fix)
pointsFixed.Add(pair.Key, pair.Value);
count++;
}
count = 0;
foreach (var pair in pointsFixed.OrderBy(x => x.Key))
{
curve[count] =pair.Key;
curve[count+8] = pair.Value;
count++;
}
return curve;
}
public void TUFKeyboardBrightness(int brightness)
{
int param = 0x80 | (brightness & 0x7F);
@@ -334,7 +376,8 @@ public class ASUSWmi
watcher.Scope = new ManagementScope("root\\wmi");
watcher.Query = new WqlEventQuery("SELECT * FROM AsusAtkWmiEvent");
watcher.Start();
} catch
}
catch
{
Logger.WriteLine("Can't connect to ASUS WMI events");
}

View File

@@ -1,8 +1,6 @@
using HidLibrary;
using Microsoft.Win32;
using OSD;
using System.Diagnostics;
using System.Windows.Forms;
namespace GHelper
{
@@ -167,7 +165,9 @@ namespace GHelper
{
HidDevice[] HidDeviceList = HidDevices.Enumerate(0x0b05, deviceIds).ToArray();
foreach (HidDevice device in HidDeviceList)
if (device.IsConnected && device.Description.ToLower().Contains("hid") && device.Capabilities.FeatureReportByteLength >= 64)
if (device.IsConnected
&& device.Capabilities.FeatureReportByteLength >= 64
&& device.Capabilities.InputReportByteLength >= 12) //
yield return device;
}
@@ -196,12 +196,13 @@ namespace GHelper
byte[] msg = { 0x5d, 0xba, 0xc5, 0xc4, (byte)brightness };
var devices = GetHidDevices(deviceIds);
if (devices.Count() > 0) Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg));
//Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg));
foreach (HidDevice device in devices)
{
device.OpenDevice();
device.Write(msg);
Logger.WriteLine("USB-KB " + device.Attributes.ProductHexId + ":" + BitConverter.ToString(msg));
device.CloseDevice();
}
@@ -217,27 +218,28 @@ namespace GHelper
var devices = GetHidDevices(deviceIds);
if (devices.Count() > 0) Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg));
//Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg));
foreach (HidDevice device in devices)
{
device.OpenDevice();
device.Write(msg);
Logger.WriteLine("USB-KB " + device.Attributes.ProductHexId + ":" + BitConverter.ToString(msg));
device.CloseDevice();
}
if (Program.config.ContainsModel("TUF"))
Program.wmi.TUFKeyboardPower(
flags.Contains(AuraDev19b6.AwakeKeyb),
flags.Contains(AuraDev19b6.BootKeyb),
flags.Contains(AuraDev19b6.SleepKeyb),
flags.Contains(AuraDev19b6.AwakeKeyb),
flags.Contains(AuraDev19b6.BootKeyb),
flags.Contains(AuraDev19b6.SleepKeyb),
flags.Contains(AuraDev19b6.ShutdownKeyb));
}
public static void ApplyXGMLight(bool status)
{
byte value = status? (byte)0x50:(byte)0;
byte value = status ? (byte)0x50 : (byte)0;
var msg = new byte[] { 0x5e, 0xc5, value };
foreach (HidDevice device in GetHidDevices(new int[] { 0x1970 }))
@@ -273,7 +275,7 @@ namespace GHelper
byte[] msg = AuraMessage(Mode, Color1, Color2, _speed);
var devices = GetHidDevices(deviceIds);
if (devices.Count() > 0) Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg));
//if (devices.Count() > 0) Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg));
foreach (HidDevice device in devices)
{
@@ -282,6 +284,7 @@ namespace GHelper
device.Write(MESSAGE_SET);
device.Write(MESSAGE_APPLY);
device.CloseDevice();
Logger.WriteLine("USB-KB " + device.Capabilities.FeatureReportByteLength + "|" + device.Capabilities.InputReportByteLength + device.Description + device.DevicePath + ":" + BitConverter.ToString(msg));
}
if (Program.config.ContainsModel("TUF"))
@@ -299,7 +302,8 @@ namespace GHelper
myKey.SetValue("TurnOffKeybdLight", value, RegistryValueKind.DWord);
myKey.Close();
}
} catch (Exception ex)
}
catch (Exception ex)
{
Logger.WriteLine(ex.Message);
}

View File

@@ -462,11 +462,16 @@ namespace GHelper
int mode = Program.config.getConfig("performance_mode");
byte[] curve = Program.config.getFanConfig(device);
if (def == 1 || curve.Length != 16)
if (def == 1 || ASUSWmi.IsEmptyCurve(curve))
{
curve = Program.wmi.GetFanCurve(device, mode);
if (ASUSWmi.IsEmptyCurve(curve))
curve = Program.config.getDefaultCurve(device);
if (curve.Length != 16 || curve.All(singleByte => singleByte == 0))
curve = Program.config.getDefaultCurve(device);
curve = ASUSWmi.FixFanCurve(curve);
}
//Debug.WriteLine(BitConverter.ToString(curve));

View File

@@ -16,7 +16,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.61</AssemblyVersion>
<AssemblyVersion>0.62</AssemblyVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">