Performance tweaks

This commit is contained in:
Serge
2023-07-26 23:57:20 +02:00
parent b9625f2748
commit 5830220a3d
5 changed files with 38 additions and 49 deletions

View File

@@ -75,8 +75,11 @@ namespace GHelper
public static Color Color1 = Color.White; public static Color Color1 = Color.White;
public static Color Color2 = Color.Black; public static Color Color2 = Color.Black;
static bool isTuf = AppConfig.ContainsModel("Tuf");
static bool isStrix = AppConfig.ContainsModel("Strix");
static System.Timers.Timer timer = new System.Timers.Timer(1000);
static System.Timers.Timer timer = new System.Timers.Timer(2000);
static HidDevice? auraDevice = null; static HidDevice? auraDevice = null;
static AsusUSB() static AsusUSB()
@@ -141,7 +144,7 @@ namespace GHelper
public static Dictionary<int, string> GetModes() public static Dictionary<int, string> GetModes()
{ {
if (AppConfig.ContainsModel("TUF")) if (isTuf)
{ {
_modes.Remove(3); _modes.Remove(3);
} }
@@ -185,7 +188,7 @@ namespace GHelper
public static bool HasSecondColor() public static bool HasSecondColor()
{ {
return (mode == 1 && !AppConfig.ContainsModel("TUF")); return (mode == 1 && !isTuf);
} }
public static int Speed public static int Speed
@@ -289,8 +292,7 @@ namespace GHelper
Task.Run(async () => Task.Run(async () =>
{ {
if (AppConfig.ContainsModel("TUF")) if (isTuf) Program.acpi.TUFKeyboardBrightness(brightness);
Program.acpi.TUFKeyboardBrightness(brightness);
byte[] msg = { AURA_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness }; byte[] msg = { AURA_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };
byte[] msgBackup = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness }; byte[] msgBackup = { INPUT_HID_ID, 0xba, 0xc5, 0xc4, (byte)brightness };
@@ -390,7 +392,7 @@ namespace GHelper
device.CloseDevice(); device.CloseDevice();
} }
if (AppConfig.ContainsModel("TUF")) if (isTuf)
Program.acpi.TUFKeyboardPower( Program.acpi.TUFKeyboardPower(
flags.Contains(AuraDev19b6.AwakeKeyb), flags.Contains(AuraDev19b6.AwakeKeyb),
flags.Contains(AuraDev19b6.BootKeyb), flags.Contains(AuraDev19b6.BootKeyb),
@@ -410,6 +412,7 @@ namespace GHelper
device.OpenDevice(); device.OpenDevice();
if (device.ReadFeatureData(out byte[] data, AURA_HID_ID)) if (device.ReadFeatureData(out byte[] data, AURA_HID_ID))
{ {
Logger.WriteLine("Aura Device:" + device.DevicePath);
auraDevice = device; auraDevice = device;
return; return;
} }
@@ -422,36 +425,33 @@ namespace GHelper
public static void ApplyColor(Color color) public static void ApplyColor(Color color)
{ {
Task.Run(async () => if (isTuf)
{ {
if (AppConfig.ContainsModel("TUF")) Program.acpi.TUFKeyboardRGB(0, color, 0);
{ return;
Program.acpi.TUFKeyboardRGB(0, color, 0); }
return;
}
if (auraDevice is null || !auraDevice.IsConnected) GetAuraDevice(); if (auraDevice is null || !auraDevice.IsConnected) GetAuraDevice();
if (auraDevice is null || !auraDevice.IsConnected) return; if (auraDevice is null || !auraDevice.IsConnected) return;
byte[] msg = new byte[40]; byte[] msg = new byte[40];
int start = 9; int start = 9;
msg[0] = AURA_HID_ID; msg[0] = AURA_HID_ID;
msg[1] = 0xBC; msg[1] = 0xbc;
msg[2] = 1; msg[2] = 1;
msg[3] = 1; msg[3] = 1;
msg[4] = 0; msg[4] = isStrix ? (byte)4 : (byte)0;
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
msg[start + i * 3] = color.R; // R msg[start + i * 3] = color.R; // R
msg[start + 1 + i * 3] = color.G; // G msg[start + 1 + i * 3] = color.G; // G
msg[start + 2 + i * 3] = color.B; // B msg[start + 2 + i * 3] = color.B; // B
} }
//Logger.WriteLine(BitConverter.ToString(msg)); //Logger.WriteLine(BitConverter.ToString(msg));
auraDevice.WriteFeatureData(msg); //auraDevice.Write(msg);
});
} }
@@ -561,7 +561,7 @@ namespace GHelper
if (AsusACPI.IsInvalidCurve(curve)) return -1; if (AsusACPI.IsInvalidCurve(curve)) return -1;
InitXGM(); //InitXGM();
byte[] msg = new byte[19]; byte[] msg = new byte[19];
Array.Copy(new byte[] { 0x5e, 0xd1, 0x01 }, msg, 3); Array.Copy(new byte[] { 0x5e, 0xd1, 0x01 }, msg, 3);

View File

@@ -174,22 +174,12 @@ public static class HardwareControl
public static float? GetCPUTemp() { public static float? GetCPUTemp() {
if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastUpdate) < 1000) return cpuTemp; var last = DateTimeOffset.Now.ToUnixTimeSeconds();
lastUpdate = DateTimeOffset.Now.ToUnixTimeMilliseconds(); if (Math.Abs(last - lastUpdate) < 2) return cpuTemp;
lastUpdate = last;
cpuTemp = Program.acpi.DeviceGet(AsusACPI.Temp_CPU); cpuTemp = Program.acpi.DeviceGet(AsusACPI.Temp_CPU);
//Debug.WriteLine(cpuTemp);
if (cpuTemp < 0) try
{
using (var ct = new PerformanceCounter("Thermal Zone Information", "Temperature", @"\_TZ.THRM", true))
{
cpuTemp = ct.NextValue() - 273;
}
}
catch (Exception ex)
{
Debug.WriteLine("Failed reading CPU temp :" + ex.Message);
}
return cpuTemp; return cpuTemp;
} }

View File

@@ -139,6 +139,7 @@ namespace GHelper.Peripherals
DetectMouse(new ChakramXWired()); DetectMouse(new ChakramXWired());
DetectMouse(new GladiusIII()); DetectMouse(new GladiusIII());
DetectMouse(new GladiusIIIWired()); DetectMouse(new GladiusIIIWired());
UpdateSettingsView();
} }
public static void DetectMouse(AsusMouse am) public static void DetectMouse(AsusMouse am)

View File

@@ -1207,6 +1207,7 @@ namespace GHelper
panelPeripherals.Padding = new Padding(20, 20, 20, 10); panelPeripherals.Padding = new Padding(20, 20, 20, 10);
panelPeripherals.Size = new Size(827, 198); panelPeripherals.Size = new Size(827, 198);
panelPeripherals.TabIndex = 4; panelPeripherals.TabIndex = 4;
panelPeripherals.Visible = false;
// //
// tableLayoutPeripherals // tableLayoutPeripherals
// //

View File

@@ -236,6 +236,7 @@ namespace GHelper
{ {
screenControl.InitScreen(); screenControl.InitScreen();
gpuControl.InitXGM(); gpuControl.InitXGM();
PeripheralsProvider.RefreshBatteryForAllDevices();
updateControl.CheckForUpdates(); updateControl.CheckForUpdates();
} }
} }
@@ -823,14 +824,11 @@ namespace GHelper
battery = Properties.Strings.Charging + ": " + Math.Round((decimal)HardwareControl.batteryRate, 1).ToString() + "W"; battery = Properties.Strings.Charging + ": " + Math.Round((decimal)HardwareControl.batteryRate, 1).ToString() + "W";
if (HardwareControl.gpuTemp > 0) if (HardwareControl.gpuTemp > 0)
{ {
gpuTemp = $": {HardwareControl.gpuTemp}°C"; gpuTemp = $": {HardwareControl.gpuTemp}°C";
} }
PeripheralsProvider.RefreshBatteryForAllDevices();
Program.settingsForm.BeginInvoke(delegate Program.settingsForm.BeginInvoke(delegate
{ {
labelCPUFan.Text = "CPU" + cpuTemp + " " + HardwareControl.cpuFan; labelCPUFan.Text = "CPU" + cpuTemp + " " + HardwareControl.cpuFan;
@@ -839,7 +837,6 @@ namespace GHelper
labelMidFan.Text = "Mid " + HardwareControl.midFan; labelMidFan.Text = "Mid " + HardwareControl.midFan;
if (!batteryMouseOver) labelBattery.Text = battery; if (!batteryMouseOver) labelBattery.Text = battery;
VisualizePeripherals();
}); });
string trayTip = "CPU" + cpuTemp + " " + HardwareControl.cpuFan; string trayTip = "CPU" + cpuTemp + " " + HardwareControl.cpuFan;