From 773a5899d16c959ec989b66ef3c7ddec2b43c21d Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sat, 10 Feb 2024 23:11:31 +0100 Subject: [PATCH] Slash Lightning tweaks --- app/AnimeMatrix/AniMatrixControl.cs | 69 +++++++++---------- app/AnimeMatrix/AnimeMatrixDevice.cs | 3 +- .../Platform/WindowsUsbProvider.cs | 7 +- app/Settings.cs | 2 +- 4 files changed, 37 insertions(+), 44 deletions(-) diff --git a/app/AnimeMatrix/AniMatrixControl.cs b/app/AnimeMatrix/AniMatrixControl.cs index ed7a5a7a..0e938b4c 100644 --- a/app/AnimeMatrix/AniMatrixControl.cs +++ b/app/AnimeMatrix/AniMatrixControl.cs @@ -1,10 +1,10 @@ using NAudio.CoreAudioApi; using NAudio.Wave; -using Starlight.AnimeMatrix; using System.Diagnostics; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Timers; +using static GHelper.AnimeMatrix.BuiltInAnimation; namespace GHelper.AnimeMatrix { @@ -25,6 +25,7 @@ namespace GHelper.AnimeMatrix private MMDeviceEnumerator? AudioDeviceEnum; public bool IsValid => deviceMatrix != null || deviceSlash != null; + public bool IsSlash => deviceSlash != null; private long lastPresent; private List maxes = new List(); @@ -35,30 +36,18 @@ namespace GHelper.AnimeMatrix try { - deviceMatrix = new AnimeMatrixDevice(); - } - catch - { - deviceMatrix = null; - } - - if (AppConfig.ContainsModel("GA403")) - { - try - { + if (AppConfig.ContainsModel("GA40")) deviceSlash = new SlashDevice(); - } - catch - { - deviceSlash = null; - } - } + else + deviceMatrix = new AnimeMatrixDevice(); - if (IsValid) - { matrixTimer = new System.Timers.Timer(100); matrixTimer.Elapsed += MatrixTimer_Elapsed; } + catch (Exception ex) + { + //Logger.WriteLine(ex.Message); + } } @@ -95,15 +84,14 @@ namespace GHelper.AnimeMatrix { deviceSlash.Init(); deviceSlash.SetOptions(false); - } else + } + else { deviceSlash.Init(); deviceSlash.SetMode((SlashMode)running); - deviceSlash.SetOptions(false, (byte)(brightness*85.333), 0); + deviceSlash.SetOptions(false, (byte)(brightness * 85.333), 0); deviceSlash.Save(); } - - }); } @@ -116,13 +104,6 @@ namespace GHelper.AnimeMatrix int running = AppConfig.Get("matrix_running", 0); bool auto = AppConfig.Is("matrix_auto"); - BuiltInAnimation animation = new BuiltInAnimation( - (BuiltInAnimation.Running)running, - BuiltInAnimation.Sleeping.Starfield, - BuiltInAnimation.Shutdown.SeeYa, - BuiltInAnimation.Startup.StaticEmergence - ); - StopMatrixTimer(); StopMatrixAudio(); @@ -163,8 +144,7 @@ namespace GHelper.AnimeMatrix SetMatrixAudio(); break; default: - deviceMatrix.SetBuiltInAnimation(true, animation); - Logger.WriteLine("Matrix builtin " + animation.AsByte); + SetBuiltIn(running); break; } @@ -173,6 +153,19 @@ namespace GHelper.AnimeMatrix } + + private void SetBuiltIn(int running) + { + BuiltInAnimation animation = new BuiltInAnimation( + (Running)running, + Sleeping.Starfield, + Shutdown.SeeYa, + BuiltInAnimation.Startup.StaticEmergence + ); + deviceMatrix.SetBuiltInAnimation(true, animation); + Logger.WriteLine("Matrix builtin: " + animation.AsByte); + } + private void StartMatrixTimer(int interval = 100) { matrixTimer.Interval = interval; @@ -187,7 +180,8 @@ namespace GHelper.AnimeMatrix private void MatrixTimer_Elapsed(object? sender, ElapsedEventArgs e) { - //if (!IsValid) return; + + if (deviceMatrix is null) return; switch (AppConfig.Get("matrix_running")) { @@ -235,7 +229,7 @@ namespace GHelper.AnimeMatrix void SetMatrixAudio() { - if (!IsValid) return; + if (deviceMatrix is null) return; deviceMatrix.SetBuiltInAnimation(false); StopMatrixTimer(); @@ -317,6 +311,8 @@ namespace GHelper.AnimeMatrix void PresentAudio(double[] audio) { + if (deviceMatrix is null) return; + if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastPresent) < 70) return; lastPresent = DateTimeOffset.Now.ToUnixTimeMilliseconds(); @@ -376,7 +372,8 @@ namespace GHelper.AnimeMatrix public void SetMatrixPicture(string fileName, bool visualise = true) { - if (!IsValid) return; + if (deviceMatrix is null) return; + StopMatrixTimer(); try diff --git a/app/AnimeMatrix/AnimeMatrixDevice.cs b/app/AnimeMatrix/AnimeMatrixDevice.cs index 5c35b4d2..5e5c5c47 100644 --- a/app/AnimeMatrix/AnimeMatrixDevice.cs +++ b/app/AnimeMatrix/AnimeMatrixDevice.cs @@ -5,7 +5,7 @@ using System.Drawing.Drawing2D; using System.Drawing.Text; using System.Text; -namespace Starlight.AnimeMatrix +namespace GHelper.AnimeMatrix { public class BuiltInAnimation { @@ -91,7 +91,6 @@ namespace Starlight.AnimeMatrix public int MaxRows = 61; public int MaxColumns = 34; public int LedStart = 0; - public int FullRows = 11; private int frameIndex = 0; diff --git a/app/AnimeMatrix/Communication/Platform/WindowsUsbProvider.cs b/app/AnimeMatrix/Communication/Platform/WindowsUsbProvider.cs index 0a43b96c..a4d0e0b7 100644 --- a/app/AnimeMatrix/Communication/Platform/WindowsUsbProvider.cs +++ b/app/AnimeMatrix/Communication/Platform/WindowsUsbProvider.cs @@ -37,14 +37,11 @@ namespace GHelper.AnimeMatrix.Communication.Platform HidDevice = DeviceList.Local .GetHidDevices(vendorId, productId) .First(x => x.GetMaxFeatureReportLength() >= maxFeatureReportLength); - - Logger.WriteLine("Matrix Device: " + HidDevice.DevicePath); - Logger.WriteLine("Matrix Features: " + HidDevice.GetMaxFeatureReportLength()); - + Logger.WriteLine("Matrix Device: " + HidDevice.DevicePath + " " + HidDevice.GetMaxFeatureReportLength()); } catch { - throw new IOException("AniMe Matrix control device was not found on your machine."); + throw new IOException("Matrix control device was not found on your machine."); } var config = new OpenConfiguration(); diff --git a/app/Settings.cs b/app/Settings.cs index 6c85d19c..5f01a4aa 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -896,7 +896,7 @@ namespace GHelper return; } - if (matrixControl.deviceSlash is not null) + if (matrixControl.IsSlash) { labelMatrix.Text = "Slash Lightning"; comboMatrixRunning.Items.Clear();