From 8c0d84b65bf6c2d08ecfd89d49a32b6382cfa2b6 Mon Sep 17 00:00:00 2001 From: seerge Date: Wed, 8 Mar 2023 19:15:21 +0100 Subject: [PATCH] Fix for possible animatrix custom picture support on older (2021) models --- ASUSWmi.cs | 9 ++++++++ AnimeMatrix/AnimeMatrixDevice.cs | 36 ++++++++++++++++++++++++++------ Fans.cs | 28 +++++++++---------------- NativeMethods.cs | 25 ++++++++++++++-------- Settings.cs | 6 ++++++ 5 files changed, 71 insertions(+), 33 deletions(-) diff --git a/ASUSWmi.cs b/ASUSWmi.cs index d13e7efbd..416f3e4a3 100644 --- a/ASUSWmi.cs +++ b/ASUSWmi.cs @@ -42,6 +42,15 @@ public class ASUSWmi public const int GPUModeUltimate = 2; + public const int MaxTotal = 150; + public const int MinTotal = 15; + public const int DefaultTotal = 125; + + public const int MaxCPU = 90; + public const int MinCPU = 15; + public const int DefaultCPU = 80; + + [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] private static extern IntPtr CreateFile( string lpFileName, diff --git a/AnimeMatrix/AnimeMatrixDevice.cs b/AnimeMatrix/AnimeMatrixDevice.cs index 7bfa5623a..68c26a392 100644 --- a/AnimeMatrix/AnimeMatrixDevice.cs +++ b/AnimeMatrix/AnimeMatrixDevice.cs @@ -3,6 +3,7 @@ using Starlight.Communication; using System.Diagnostics; using System.Text; +using System.Management; namespace Starlight.AnimeMatrix { @@ -75,11 +76,32 @@ public class AnimeMatrixDevice : Device private byte[] _displayBuffer = new byte[UpdatePageLength * 3]; private List frames = new List(); + private int pages = 3; + private int frameIndex = 0; public AnimeMatrixDevice() : base(0x0B05, 0x193B, 640) { + string model = GetModel(); + Debug.WriteLine(model); + if (model is not null && model.Contains("401")) + { + pages = 2; + } + } + + + public string GetModel() + { + using (var searcher = new ManagementObjectSearcher(@"Select * from Win32_ComputerSystem")) + { + foreach (var process in searcher.Get()) + return process["Model"].ToString(); + } + + return null; + } public byte[] GetBuffer() @@ -183,6 +205,7 @@ public void Clear(bool present = false) public void Present() { + Set(Packet(0xC0, 0x02) .AppendData(BitConverter.GetBytes((ushort)(UpdatePageLength * 0 + 1))) .AppendData(BitConverter.GetBytes((ushort)UpdatePageLength)) @@ -195,12 +218,13 @@ public void Present() .AppendData(_displayBuffer[(UpdatePageLength * 1)..(UpdatePageLength * 2)]) ); - Set(Packet(0xC0, 0x02) - .AppendData(BitConverter.GetBytes((ushort)(UpdatePageLength * 2 + 1))) - .AppendData(BitConverter.GetBytes((ushort)(LedCount - UpdatePageLength * 2))) - .AppendData( - _displayBuffer[(UpdatePageLength * 2)..(UpdatePageLength * 2 + (LedCount - UpdatePageLength * 2))]) - ); + if (pages > 2) + Set(Packet(0xC0, 0x02) + .AppendData(BitConverter.GetBytes((ushort)(UpdatePageLength * 2 + 1))) + .AppendData(BitConverter.GetBytes((ushort)(LedCount - UpdatePageLength * 2))) + .AppendData( + _displayBuffer[(UpdatePageLength * 2)..(UpdatePageLength * 2 + (LedCount - UpdatePageLength * 2))]) + ); Set(Packet(0xC0, 0x03)); } diff --git a/Fans.cs b/Fans.cs index 715262a89..7178cbe7a 100644 --- a/Fans.cs +++ b/Fans.cs @@ -11,14 +11,6 @@ public partial class Fans : Form Series seriesCPU; Series seriesGPU; - const int MaxTotal = 150; - const int MinTotal = 15; - const int DefaultTotal = 125; - - const int MaxCPU = 90; - const int MinCPU = 15; - const int DefaultCPU = 80; - void SetChart(Chart chart, int device) { @@ -91,11 +83,11 @@ public Fans() buttonReset.Click += ButtonReset_Click; buttonApply.Click += ButtonApply_Click; - trackTotal.Maximum = MaxTotal; - trackTotal.Minimum = MinTotal; + trackTotal.Maximum = ASUSWmi.MaxTotal; + trackTotal.Minimum = ASUSWmi.MinTotal; - trackCPU.Maximum = MaxCPU; - trackCPU.Minimum = MinCPU; + trackCPU.Maximum = ASUSWmi.MaxCPU; + trackCPU.Minimum = ASUSWmi.MinCPU; trackCPU.Scroll += TrackCPU_Scroll; trackTotal.Scroll += TrackTotal_Scroll; @@ -167,13 +159,13 @@ public void InitPower(bool changed = false) ApplyLabel(apply); } - if (limit_total < 0) limit_total = DefaultTotal; - if (limit_total > MaxTotal) limit_total = MaxTotal; - if (limit_total < MinTotal) limit_total = MinTotal; + if (limit_total < 0) limit_total = ASUSWmi.DefaultTotal; + if (limit_total > ASUSWmi.MaxTotal) limit_total = ASUSWmi.MaxTotal; + if (limit_total < ASUSWmi.MinTotal) limit_total = ASUSWmi.MinTotal; - if (limit_cpu < 0) limit_cpu = DefaultCPU; - if (limit_cpu > MaxCPU) limit_cpu = MaxCPU; - if (limit_cpu < MinCPU) limit_cpu = MinCPU; + if (limit_cpu < 0) limit_cpu = ASUSWmi.DefaultCPU; + if (limit_cpu > ASUSWmi.MaxCPU) limit_cpu = ASUSWmi.MaxCPU; + if (limit_cpu < ASUSWmi.MinCPU) limit_cpu = ASUSWmi.MinCPU; if (limit_cpu > limit_total) limit_cpu = limit_total; trackTotal.Value = limit_total; diff --git a/NativeMethods.cs b/NativeMethods.cs index 5e45fa1e1..a15e31325 100644 --- a/NativeMethods.cs +++ b/NativeMethods.cs @@ -254,20 +254,27 @@ public static string FindLaptopScreen() deviceNum = 0; } - counter = 0; - for (uint id = 0; EnumDisplayDevicesA(null, id, ref d, 0); id++) + + try { - if ((d.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) != 0) + counter = 0; + for (uint id = 0; EnumDisplayDevicesA(null, id, ref d, 0); id++) { - //Debug.WriteLine(d.DeviceID); - //Debug.WriteLine(d.DeviceName); - if (counter == deviceNum) + if ((d.StateFlags & DisplayDeviceStateFlags.AttachedToDesktop) != 0) { - laptopScreen = d.DeviceName; + //Debug.WriteLine(d.DeviceID); + //Debug.WriteLine(d.DeviceName); + if (counter == deviceNum) + { + laptopScreen = d.DeviceName; + } + counter++; } - counter++; - } + } + } catch + { + Debug.WriteLine("Failed to enumerate displays"); } // Mismatch between active screens and enumerated screens, fallback to old method diff --git a/Settings.cs b/Settings.cs index cee2f1754..bc455e311 100644 --- a/Settings.cs +++ b/Settings.cs @@ -693,6 +693,12 @@ public void SetPower() int limit_total = Program.config.getConfigPerf("limit_total"); int limit_cpu = Program.config.getConfigPerf("limit_cpu"); + if (limit_total > ASUSWmi.MaxTotal) return; + if (limit_total < ASUSWmi.MinTotal) return; + + if (limit_cpu > ASUSWmi.MaxCPU) return; + if (limit_cpu < ASUSWmi.MinCPU) return; + Program.wmi.DeviceSet(ASUSWmi.PPT_TotalA0, limit_total); Program.wmi.DeviceSet(ASUSWmi.PPT_TotalA1, limit_total); Program.wmi.DeviceSet(ASUSWmi.PPT_CPUB0, limit_cpu);