Skip to content

Commit

Permalink
Fix for possible animatrix custom picture support on older (2021) models
Browse files Browse the repository at this point in the history
  • Loading branch information
seerge committed Mar 8, 2023
1 parent 4e6fa6d commit 8c0d84b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 33 deletions.
9 changes: 9 additions & 0 deletions ASUSWmi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 30 additions & 6 deletions AnimeMatrix/AnimeMatrixDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Starlight.Communication;
using System.Diagnostics;
using System.Text;
using System.Management;

namespace Starlight.AnimeMatrix
{
Expand Down Expand Up @@ -75,11 +76,32 @@ public class AnimeMatrixDevice : Device
private byte[] _displayBuffer = new byte[UpdatePageLength * 3];
private List<byte[]> frames = new List<byte[]>();

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()
Expand Down Expand Up @@ -183,6 +205,7 @@ public void Clear(bool present = false)

public void Present()
{

Set(Packet<AnimeMatrixPacket>(0xC0, 0x02)
.AppendData(BitConverter.GetBytes((ushort)(UpdatePageLength * 0 + 1)))
.AppendData(BitConverter.GetBytes((ushort)UpdatePageLength))
Expand All @@ -195,12 +218,13 @@ public void Present()
.AppendData(_displayBuffer[(UpdatePageLength * 1)..(UpdatePageLength * 2)])
);

Set(Packet<AnimeMatrixPacket>(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<AnimeMatrixPacket>(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<AnimeMatrixPacket>(0xC0, 0x03));
}
Expand Down
28 changes: 10 additions & 18 deletions Fans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 16 additions & 9 deletions NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8c0d84b

Please sign in to comment.