Timer fix

This commit is contained in:
seerge
2023-03-06 00:14:37 +01:00
parent 24014dd20f
commit e3e9022111
5 changed files with 24 additions and 19 deletions

View File

@@ -2,6 +2,7 @@
using System.Management;
using System.Runtime.InteropServices;
public class ASUSWmi
{

View File

@@ -1,8 +1,8 @@
// Source thanks to https://github.com/vddCore/Starlight :)
// Source thanks to https://github.com/vddCore/Starlight with some adjustments from me
using Starlight.Communication;
using System.Diagnostics;
using System.Text;
using Starlight.Communication;
namespace Starlight.AnimeMatrix
{
@@ -89,6 +89,7 @@ namespace Starlight.AnimeMatrix
public void PresentNextFrame()
{
//Debug.WriteLine(frameIndex);
if (frameIndex >= frames.Count) frameIndex = 0;
_displayBuffer = frames[frameIndex];
Present();
@@ -118,7 +119,7 @@ namespace Starlight.AnimeMatrix
}
public int Columns(int row)
{
EnsureRowInRange(row);
EnsureRowInRange(row);
return 34 - EmptyColumns(row);
}
@@ -230,7 +231,7 @@ namespace Starlight.AnimeMatrix
var enabled = enable ? (byte)0x00 : (byte)0x80;
Set(Packet<AnimeMatrixPacket>(0xC4, 0x01, enabled));
}
public void SetBuiltInAnimation(bool enable, BuiltInAnimation animation)
{
SetBuiltInAnimation(enable);
@@ -265,13 +266,13 @@ namespace Starlight.AnimeMatrix
for (int x = 0; x < bmp.Width; x++)
{
var pixel = bmp.GetPixel(x, y);
byte color = (byte)((pixel.R + pixel.G + pixel.B) / 3);
byte color = (byte)(Math.Max((pixel.R + pixel.G + pixel.B) / 3 - 10, 0));
SetLedPlanar(x, y, color);
}
}
}
}
private void EnsureRowInRange(int row)
{
if (row < 0 || row >= Rows)

View File

@@ -1,4 +1,5 @@
using System.Text.Json;
public class AppConfig
{

View File

@@ -61,6 +61,7 @@ namespace GHelper
settingsForm.InitGPUMode();
settingsForm.InitBoost();
settingsForm.InitAura();
settingsForm.InitMatrix();
settingsForm.VisualiseGPUAuto(config.getConfig("gpu_auto"));
settingsForm.VisualiseScreenAuto(config.getConfig("screen_auto"));
@@ -82,6 +83,9 @@ namespace GHelper
settingsForm.AutoGPUMode(isPlugged);
settingsForm.AutoScreen(isPlugged);
settingsForm.AutoPerformance(isPlugged);
settingsForm.SetAnimeMatrix();
settingsForm.SetBatteryChargeLimit(config.getConfig("charge_limit"));
}

View File

@@ -18,7 +18,7 @@ namespace GHelper
static int buttonActive = 5;
static System.Timers.Timer aTimer = default!;
static System.Timers.Timer matrixTimer = new System.Timers.Timer(100);
static System.Timers.Timer matrixTimer = new System.Timers.Timer();
public string perfName = "Balanced";
@@ -81,9 +81,6 @@ namespace GHelper
labelCPUFan.Click += LabelCPUFan_Click;
labelGPUFan.Click += LabelCPUFan_Click;
InitMatrix();
comboMatrix.DropDownStyle = ComboBoxStyle.DropDownList;
comboMatrixRunning.DropDownStyle = ComboBoxStyle.DropDownList;
comboMatrix.SelectedValueChanged += ComboMatrix_SelectedValueChanged;
@@ -92,6 +89,7 @@ namespace GHelper
buttonMatrix.Click += ButtonMatrix_Click;
matrixTimer.Enabled = false;
matrixTimer.Interval = 100;
matrixTimer.Elapsed += MatrixTimer_Elapsed;
SetTimer();
@@ -177,22 +175,25 @@ namespace GHelper
private void ComboMatrixRunning_SelectedValueChanged(object? sender, EventArgs e)
{
Program.config.setConfig("matrix_running", comboMatrixRunning.SelectedIndex);
SetAnimeMatrix();
}
private void ComboMatrix_SelectedValueChanged(object? sender, EventArgs e)
{
Program.config.setConfig("matrix_brightness", comboMatrix.SelectedIndex);
SetAnimeMatrix();
}
private void SetAnimeMatrix()
public void SetAnimeMatrix()
{
int brightness = comboMatrix.SelectedIndex;
int running = comboMatrixRunning.SelectedIndex;
int brightness = Program.config.getConfig("matrix_brightness");
int running = Program.config.getConfig("matrix_running");
//var mat = new AnimeMatrixDevice();
if (brightness < 0) brightness = 0;
if (running < 0) running = 0;
BuiltInAnimation animation = new BuiltInAnimation(
(BuiltInAnimation.Running)running,
@@ -201,6 +202,7 @@ namespace GHelper
BuiltInAnimation.Startup.StaticEmergence
);
matrixTimer.Enabled = false;
if (brightness == 0)
{
@@ -222,10 +224,6 @@ namespace GHelper
}
}
//mat.Dispose();
Program.config.setConfig("matrix_brightness", comboMatrix.SelectedIndex);
Program.config.setConfig("matrix_running", comboMatrixRunning.SelectedIndex);
}