From e3e9022111b749bc2469f561d5a59cda38fa14ad Mon Sep 17 00:00:00 2001 From: seerge Date: Mon, 6 Mar 2023 00:14:37 +0100 Subject: [PATCH] Timer fix --- ASUSWmi.cs | 1 + AnimeMatrix/AnimeMatrixDevice.cs | 15 ++++++++------- AppConfig.cs | 1 + Program.cs | 4 ++++ Settings.cs | 22 ++++++++++------------ 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/ASUSWmi.cs b/ASUSWmi.cs index baa3e2b9..f81fc4b6 100644 --- a/ASUSWmi.cs +++ b/ASUSWmi.cs @@ -2,6 +2,7 @@ using System.Management; using System.Runtime.InteropServices; + public class ASUSWmi { diff --git a/AnimeMatrix/AnimeMatrixDevice.cs b/AnimeMatrix/AnimeMatrixDevice.cs index def8fed6..7bfa5623 100644 --- a/AnimeMatrix/AnimeMatrixDevice.cs +++ b/AnimeMatrix/AnimeMatrixDevice.cs @@ -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(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) diff --git a/AppConfig.cs b/AppConfig.cs index 4a717098..0b545b57 100644 --- a/AppConfig.cs +++ b/AppConfig.cs @@ -1,4 +1,5 @@ using System.Text.Json; + public class AppConfig { diff --git a/Program.cs b/Program.cs index 6d661236..c25eea5a 100644 --- a/Program.cs +++ b/Program.cs @@ -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")); } diff --git a/Settings.cs b/Settings.cs index 64b6e02f..721bc3b4 100644 --- a/Settings.cs +++ b/Settings.cs @@ -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); }