From 6a44c42cbfd3ca50fc01e5ce7d723426df871c48 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sat, 10 Feb 2024 22:04:45 +0100 Subject: [PATCH 1/9] Slash Lightning --- app/AnimeMatrix/AniMatrixControl.cs | 130 +++++++++++++----- .../Platform/WindowsUsbProvider.cs | 3 +- app/AnimeMatrix/SlashDevice.cs | 62 +++++++++ app/Matrix.cs | 4 +- app/Program.cs | 2 +- app/Settings.cs | 17 ++- 6 files changed, 174 insertions(+), 44 deletions(-) create mode 100644 app/AnimeMatrix/SlashDevice.cs diff --git a/app/AnimeMatrix/AniMatrixControl.cs b/app/AnimeMatrix/AniMatrixControl.cs index f433a8bca..0e0ee65d4 100644 --- a/app/AnimeMatrix/AniMatrixControl.cs +++ b/app/AnimeMatrix/AniMatrixControl.cs @@ -15,14 +15,16 @@ public class AniMatrixControl : NAudio.CoreAudioApi.Interfaces.IMMNotificationCl SettingsForm settings; System.Timers.Timer matrixTimer = default!; - public AnimeMatrixDevice? device; + + public AnimeMatrixDevice? deviceMatrix; + public SlashDevice? deviceSlash; double[]? AudioValues; WasapiCapture? AudioDevice; string? AudioDeviceId; private MMDeviceEnumerator? AudioDeviceEnum; - public bool IsValid => device != null; + public bool IsValid => deviceMatrix != null || deviceSlash != null; private long lastPresent; private List maxes = new List(); @@ -33,30 +35,86 @@ public AniMatrixControl(SettingsForm settingsForm) try { - device = new AnimeMatrixDevice(); - Task.Run(device.WakeUp); - matrixTimer = new System.Timers.Timer(100); - matrixTimer.Elapsed += MatrixTimer_Elapsed; + deviceMatrix = new AnimeMatrixDevice(); } catch { - device = null; + deviceMatrix = null; + } + + if (AppConfig.ContainsModel("GA403")) + { + try + { + deviceSlash = new SlashDevice(); + } + catch + { + deviceSlash = null; + } + } + + if (IsValid) + { + matrixTimer = new System.Timers.Timer(100); + matrixTimer.Elapsed += MatrixTimer_Elapsed; } } - public void SetMatrix(bool wakeUp = false) + public void SetDevice(bool wakeUp = false) { + if (deviceMatrix is not null) SetMatrix(wakeUp); + if (deviceSlash is not null) SetSlash(wakeUp); + } - if (!IsValid) return; - int brightness = AppConfig.Get("matrix_brightness"); - int running = AppConfig.Get("matrix_running"); + public void SetSlash(bool wakeUp = false) + { + if (deviceSlash is null) return; + int brightness = AppConfig.Get("matrix_brightness", 0); + int running = AppConfig.Get("matrix_running", 0); bool auto = AppConfig.Is("matrix_auto"); - if (brightness < 0) brightness = 0; - if (running < 0) running = 0; + Task.Run(() => + { + try + { + deviceSlash.SetProvider(); + } + catch (Exception ex) + { + Logger.WriteLine(ex.Message); + return; + } + + if (wakeUp) deviceSlash.WakeUp(); + + if (brightness == 0 || (auto && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online)) + { + deviceSlash.Init(); + deviceSlash.SetOptions(false); + } else + { + deviceSlash.Init(); + deviceSlash.SetMode((SlashMode)running); + deviceSlash.SetOptions(false, (byte)(brightness*85.333), 0); + deviceSlash.Save(); + } + + + }); + } + + public void SetMatrix(bool wakeUp = false) + { + + if (deviceMatrix is null) return; + + int brightness = AppConfig.Get("matrix_brightness", 0); + int running = AppConfig.Get("matrix_running", 0); + bool auto = AppConfig.Is("matrix_auto"); BuiltInAnimation animation = new BuiltInAnimation( (BuiltInAnimation.Running)running, @@ -72,7 +130,7 @@ public void SetMatrix(bool wakeUp = false) { try { - device.SetProvider(); + deviceMatrix.SetProvider(); } catch (Exception ex) { @@ -80,18 +138,18 @@ public void SetMatrix(bool wakeUp = false) return; } - if (wakeUp) device.WakeUp(); + if (wakeUp) deviceMatrix.WakeUp(); if (brightness == 0 || (auto && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online)) { - device.SetDisplayState(false); - device.SetDisplayState(false); // some devices are dumb + deviceMatrix.SetDisplayState(false); + deviceMatrix.SetDisplayState(false); // some devices are dumb Logger.WriteLine("Matrix Off"); } else { - device.SetDisplayState(true); - device.SetBrightness((BrightnessMode)brightness); + deviceMatrix.SetDisplayState(true); + deviceMatrix.SetBrightness((BrightnessMode)brightness); switch (running) { @@ -105,7 +163,7 @@ public void SetMatrix(bool wakeUp = false) SetMatrixAudio(); break; default: - device.SetBuiltInAnimation(true, animation); + deviceMatrix.SetBuiltInAnimation(true, animation); Logger.WriteLine("Matrix builtin " + animation.AsByte); break; } @@ -134,10 +192,10 @@ private void MatrixTimer_Elapsed(object? sender, ElapsedEventArgs e) switch (AppConfig.Get("matrix_running")) { case 2: - device.PresentNextFrame(); + deviceMatrix.PresentNextFrame(); break; case 3: - device.PresentClock(); + deviceMatrix.PresentClock(); break; } @@ -146,7 +204,7 @@ private void MatrixTimer_Elapsed(object? sender, ElapsedEventArgs e) public void SetMatrixClock() { - device.SetBuiltInAnimation(false); + deviceMatrix.SetBuiltInAnimation(false); StartMatrixTimer(1000); Logger.WriteLine("Matrix Clock"); } @@ -179,7 +237,7 @@ void SetMatrixAudio() { if (!IsValid) return; - device.SetBuiltInAnimation(false); + deviceMatrix.SetBuiltInAnimation(false); StopMatrixTimer(); StopMatrixAudio(); @@ -251,8 +309,8 @@ private void DrawBar(int pos, double h) for (int x = 0; x < 2 - (y % 2); x++) { //color = (byte)(Math.Min(1,(h - y - 2)*2) * 255); - device.SetLedPlanar(x + dx, dy + y, (byte)(h * 255 / 30)); - device.SetLedPlanar(x + dx, dy - y, 255); + deviceMatrix.SetLedPlanar(x + dx, dy + y, (byte)(h * 255 / 30)); + deviceMatrix.SetLedPlanar(x + dx, dy - y, 255); } } @@ -262,7 +320,7 @@ void PresentAudio(double[] audio) if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastPresent) < 70) return; lastPresent = DateTimeOffset.Now.ToUnixTimeMilliseconds(); - device.Clear(); + deviceMatrix.Clear(); int size = 20; double[] bars = new double[size]; @@ -280,7 +338,7 @@ void PresentAudio(double[] audio) for (int i = 0; i < size; i++) DrawBar(20 - i, bars[i] * 20 / maxAverage); - device.Present(); + deviceMatrix.Present(); } @@ -351,8 +409,8 @@ public void SetMatrixPicture(string fileName, bool visualise = true) protected void ProcessPicture(Image image) { - device.SetBuiltInAnimation(false); - device.ClearFrames(); + deviceMatrix.SetBuiltInAnimation(false); + deviceMatrix.ClearFrames(); int matrixX = AppConfig.Get("matrix_x", 0); int matrixY = AppConfig.Get("matrix_y", 0); @@ -380,11 +438,11 @@ protected void ProcessPicture(Image image) image.SelectActiveFrame(dimension, i); if (rotation == MatrixRotation.Planar) - device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast); + deviceMatrix.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast); else - device.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast); + deviceMatrix.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast); - device.AddFrame(); + deviceMatrix.AddFrame(); } @@ -397,11 +455,11 @@ protected void ProcessPicture(Image image) else { if (rotation == MatrixRotation.Planar) - device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast); + deviceMatrix.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast); else - device.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast); + deviceMatrix.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast); - device.Present(); + deviceMatrix.Present(); } } diff --git a/app/AnimeMatrix/Communication/Platform/WindowsUsbProvider.cs b/app/AnimeMatrix/Communication/Platform/WindowsUsbProvider.cs index 2db6e1d8f..0a43b96c0 100644 --- a/app/AnimeMatrix/Communication/Platform/WindowsUsbProvider.cs +++ b/app/AnimeMatrix/Communication/Platform/WindowsUsbProvider.cs @@ -36,9 +36,10 @@ public WindowsUsbProvider(ushort vendorId, ushort productId, int maxFeatureRepor { HidDevice = DeviceList.Local .GetHidDevices(vendorId, productId) - .First(x => x.GetMaxFeatureReportLength() == maxFeatureReportLength); + .First(x => x.GetMaxFeatureReportLength() >= maxFeatureReportLength); Logger.WriteLine("Matrix Device: " + HidDevice.DevicePath); + Logger.WriteLine("Matrix Features: " + HidDevice.GetMaxFeatureReportLength()); } catch diff --git a/app/AnimeMatrix/SlashDevice.cs b/app/AnimeMatrix/SlashDevice.cs new file mode 100644 index 000000000..f0f7e2070 --- /dev/null +++ b/app/AnimeMatrix/SlashDevice.cs @@ -0,0 +1,62 @@ +using GHelper.AnimeMatrix.Communication; +using System.Text; + +namespace GHelper.AnimeMatrix +{ + public enum SlashMode + { + Transmission, + Bitstream + } + + internal class SlashPacket : Packet + { + public SlashPacket(byte[] command) : base(0x5E, 128, command) + { + } + } + + public class SlashDevice : Device + { + public SlashDevice() : base(0x0B05, 0x193B, 640) // 128 + { + } + + public void WakeUp() + { + Set(Packet(Encoding.ASCII.GetBytes("ASUS Tech.Inc."))); + } + + public void Init() + { + Set(Packet(0xD7, 0x00, 0x00, 0x01, 0xAC)); + Set(Packet(0xD2, 0x02, 0x01, 0x08, 0xAB)); + } + + public void Save() + { + Set(Packet(0xD4, 0x00, 0x00, 0x01, 0xAB)); + } + + public void SetMode(SlashMode mode) + { + Set(Packet(0xD2, 0x03, 0x00, 0x0C)); + Set(Packet(0xD3, 0x04, 0x00, 0x0C, 0x01, (mode == SlashMode.Bitstream) ? (byte)0x1D : (byte)0x1A, 0x02, 0x19, 0x03, 0x13, 0x04, 0x11, 0x05, 0x12, 0x06, 0x13)); + } + + public void SetOptions(bool status, byte brightness = 0xFF, byte interval = 0x00) + { + Set(Packet(0xD3, 0x03, 0x01, 0x08, 0xAB, 0xFF, 0x01, status ? (byte)0x01 : (byte)0x00, 0x06, brightness, 0xFF, interval)); + Save(); + Save(); + } + + public void Set(Packet packet) + { + _usbProvider?.Set(packet.Data); + Logger.WriteLine("Slash:" + BitConverter.ToString(packet.Data)); + } + + + } +} \ No newline at end of file diff --git a/app/Matrix.cs b/app/Matrix.cs index c87d61cc8..78c2a4a59 100644 --- a/app/Matrix.cs +++ b/app/Matrix.cs @@ -62,8 +62,8 @@ public Matrix() comboRotation.SelectedValueChanged += ComboRotation_SelectedValueChanged; ; - uiScale = panelPicture.Width / matrixControl.device.MaxColumns / 3; - panelPicture.Height = (int)(matrixControl.device.MaxRows * uiScale); + uiScale = panelPicture.Width / matrixControl.deviceMatrix.MaxColumns / 3; + panelPicture.Height = (int)(matrixControl.deviceMatrix.MaxRows * uiScale); } diff --git a/app/Program.cs b/app/Program.cs index ecf1d2e77..7cd18809d 100644 --- a/app/Program.cs +++ b/app/Program.cs @@ -229,7 +229,7 @@ public static void SetAutoModes(bool powerChanged = false, bool init = false) BatteryControl.AutoBattery(init); - settingsForm.matrixControl.SetMatrix(true); + settingsForm.matrixControl.SetDevice(true); if (AppConfig.IsAlly()) { diff --git a/app/Settings.cs b/app/Settings.cs index bbaec21c5..650ac2b76 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -686,7 +686,7 @@ private void CheckStartup_CheckedChanged(object? sender, EventArgs e) private void CheckMatrix_CheckedChanged(object? sender, EventArgs e) { AppConfig.Set("matrix_auto", checkMatrix.Checked ? 1 : 0); - matrixControl.SetMatrix(); + matrixControl.SetDevice(); } @@ -724,14 +724,14 @@ public void SetMatrixRunning(int mode) private void ComboMatrixRunning_SelectedValueChanged(object? sender, EventArgs e) { AppConfig.Set("matrix_running", comboMatrixRunning.SelectedIndex); - matrixControl.SetMatrix(); + matrixControl.SetDevice(); } private void ComboMatrix_SelectedValueChanged(object? sender, EventArgs e) { AppConfig.Set("matrix_brightness", comboMatrix.SelectedIndex); - matrixControl.SetMatrix(); + matrixControl.SetDevice(); } @@ -896,6 +896,15 @@ public void InitMatrix() return; } + if (matrixControl.deviceSlash is not null) + { + labelMatrix.Text = "Slash Lightning"; + comboMatrixRunning.Items.Clear(); + comboMatrixRunning.Items.Add("Transmission"); + comboMatrixRunning.Items.Add("Bitstream"); + buttonMatrix.Visible = false; + } + comboMatrix.SelectedIndex = Math.Min(AppConfig.Get("matrix_brightness", 0), comboMatrix.Items.Count - 1); comboMatrixRunning.SelectedIndex = Math.Min(AppConfig.Get("matrix_running", 0), comboMatrixRunning.Items.Count - 1); @@ -909,7 +918,7 @@ public void CycleMatrix(int delta) { comboMatrix.SelectedIndex = Math.Min(Math.Max(0, comboMatrix.SelectedIndex + delta), comboMatrix.Items.Count - 1); AppConfig.Set("matrix_brightness", comboMatrix.SelectedIndex); - matrixControl.SetMatrix(); + matrixControl.SetDevice(); Program.toast.RunToast(comboMatrix.GetItemText(comboMatrix.SelectedItem), delta > 0 ? ToastIcon.BacklightUp : ToastIcon.BacklightDown); } From 72888401b93e4e508ef21f72d805a3a3da5b0ff9 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sat, 10 Feb 2024 22:49:17 +0100 Subject: [PATCH 2/9] Slash lightning UI tweaks --- app/AnimeMatrix/AniMatrixControl.cs | 4 ++-- app/AnimeMatrix/SlashDevice.cs | 2 +- app/Settings.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/AnimeMatrix/AniMatrixControl.cs b/app/AnimeMatrix/AniMatrixControl.cs index 0e0ee65d4..ed7a5a7a6 100644 --- a/app/AnimeMatrix/AniMatrixControl.cs +++ b/app/AnimeMatrix/AniMatrixControl.cs @@ -367,7 +367,7 @@ public void OpenMatrixPicture() AppConfig.Set("matrix_running", 2); SetMatrixPicture(fileName); - settings.SetMatrixRunning(2); + settings.VisualiseMatrixRunning(2); } @@ -396,7 +396,7 @@ public void SetMatrixPicture(string fileName, bool visualise = true) } fs.Close(); - if (visualise) settings.VisualiseMatrix(fileName); + if (visualise) settings.VisualiseMatrixPicture(fileName); } } catch diff --git a/app/AnimeMatrix/SlashDevice.cs b/app/AnimeMatrix/SlashDevice.cs index f0f7e2070..ce8075fd3 100644 --- a/app/AnimeMatrix/SlashDevice.cs +++ b/app/AnimeMatrix/SlashDevice.cs @@ -18,7 +18,7 @@ public SlashPacket(byte[] command) : base(0x5E, 128, command) public class SlashDevice : Device { - public SlashDevice() : base(0x0B05, 0x193B, 640) // 128 + public SlashDevice() : base(0x0B05, 0x193B, 128) { } diff --git a/app/Settings.cs b/app/Settings.cs index 650ac2b76..6c85d19c0 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -424,7 +424,7 @@ private void ButtonUpdates_Click(object? sender, EventArgs e) } } - public void VisualiseMatrix(string image) + public void VisualiseMatrixPicture(string image) { if (matrixForm == null || matrixForm.Text == "") return; matrixForm.VisualiseMatrix(image); @@ -712,7 +712,7 @@ private void ButtonMatrix_Click(object? sender, EventArgs e) } - public void SetMatrixRunning(int mode) + public void VisualiseMatrixRunning(int mode) { Invoke(delegate { 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 3/9] 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 ed7a5a7a6..0e938b4c2 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 @@ public class AniMatrixControl : NAudio.CoreAudioApi.Interfaces.IMMNotificationCl 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 @@ public AniMatrixControl(SettingsForm settingsForm) 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 @@ public void SetSlash(bool wakeUp = false) { 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 @@ public void SetMatrix(bool wakeUp = false) 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 @@ public void SetMatrix(bool wakeUp = false) SetMatrixAudio(); break; default: - deviceMatrix.SetBuiltInAnimation(true, animation); - Logger.WriteLine("Matrix builtin " + animation.AsByte); + SetBuiltIn(running); break; } @@ -173,6 +153,19 @@ public void SetMatrix(bool wakeUp = false) } + + 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 @@ private void StopMatrixTimer() 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 @@ void StopMatrixAudio() void SetMatrixAudio() { - if (!IsValid) return; + if (deviceMatrix is null) return; deviceMatrix.SetBuiltInAnimation(false); StopMatrixTimer(); @@ -317,6 +311,8 @@ private void DrawBar(int pos, double h) 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 @@ public void OpenMatrixPicture() 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 5c35b4d2d..5e5c5c471 100644 --- a/app/AnimeMatrix/AnimeMatrixDevice.cs +++ b/app/AnimeMatrix/AnimeMatrixDevice.cs @@ -5,7 +5,7 @@ using System.Drawing.Text; using System.Text; -namespace Starlight.AnimeMatrix +namespace GHelper.AnimeMatrix { public class BuiltInAnimation { @@ -91,7 +91,6 @@ public class AnimeMatrixDevice : Device 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 0a43b96c0..a4d0e0b7a 100644 --- a/app/AnimeMatrix/Communication/Platform/WindowsUsbProvider.cs +++ b/app/AnimeMatrix/Communication/Platform/WindowsUsbProvider.cs @@ -37,14 +37,11 @@ public WindowsUsbProvider(ushort vendorId, ushort productId, int maxFeatureRepor 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 6c85d19c0..5f01a4aab 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -896,7 +896,7 @@ public void InitMatrix() return; } - if (matrixControl.deviceSlash is not null) + if (matrixControl.IsSlash) { labelMatrix.Text = "Slash Lightning"; comboMatrixRunning.Items.Clear(); From ae298873ca0aa17b3184bc798d8049641666aaa4 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sun, 11 Feb 2024 11:44:40 +0100 Subject: [PATCH 4/9] Minor tweaks --- app/AnimeMatrix/AniMatrixControl.cs | 4 ++-- app/AnimeMatrix/SlashDevice.cs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/AnimeMatrix/AniMatrixControl.cs b/app/AnimeMatrix/AniMatrixControl.cs index 0e938b4c2..5349dd0d8 100644 --- a/app/AnimeMatrix/AniMatrixControl.cs +++ b/app/AnimeMatrix/AniMatrixControl.cs @@ -46,7 +46,7 @@ public AniMatrixControl(SettingsForm settingsForm) } catch (Exception ex) { - //Logger.WriteLine(ex.Message); + Logger.WriteLine(ex.Message); } } @@ -89,7 +89,7 @@ public void SetSlash(bool wakeUp = false) { deviceSlash.Init(); deviceSlash.SetMode((SlashMode)running); - deviceSlash.SetOptions(false, (byte)(brightness * 85.333), 0); + deviceSlash.SetOptions(true, (byte)(brightness * 85.333), 0); deviceSlash.Save(); } }); diff --git a/app/AnimeMatrix/SlashDevice.cs b/app/AnimeMatrix/SlashDevice.cs index ce8075fd3..e470bb75c 100644 --- a/app/AnimeMatrix/SlashDevice.cs +++ b/app/AnimeMatrix/SlashDevice.cs @@ -48,7 +48,6 @@ public void SetOptions(bool status, byte brightness = 0xFF, byte interval = 0x00 { Set(Packet(0xD3, 0x03, 0x01, 0x08, 0xAB, 0xFF, 0x01, status ? (byte)0x01 : (byte)0x00, 0x06, brightness, 0xFF, interval)); Save(); - Save(); } public void Set(Packet packet) From 1adec8b6c9884b02fef0d4a34bbe230d6f66b3f5 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sun, 11 Feb 2024 12:03:11 +0100 Subject: [PATCH 5/9] Slash Interval settings --- app/AnimeMatrix/AniMatrixControl.cs | 4 +- app/AnimeMatrix/SlashDevice.cs | 5 ++- app/Settings.Designer.cs | 67 ++++++++++++++++++----------- app/Settings.cs | 13 ++++++ 4 files changed, 62 insertions(+), 27 deletions(-) diff --git a/app/AnimeMatrix/AniMatrixControl.cs b/app/AnimeMatrix/AniMatrixControl.cs index 5349dd0d8..663f734df 100644 --- a/app/AnimeMatrix/AniMatrixControl.cs +++ b/app/AnimeMatrix/AniMatrixControl.cs @@ -64,6 +64,8 @@ public void SetSlash(bool wakeUp = false) int brightness = AppConfig.Get("matrix_brightness", 0); int running = AppConfig.Get("matrix_running", 0); + int inteval = AppConfig.Get("matrix_interval", 0); + bool auto = AppConfig.Is("matrix_auto"); Task.Run(() => @@ -89,7 +91,7 @@ public void SetSlash(bool wakeUp = false) { deviceSlash.Init(); deviceSlash.SetMode((SlashMode)running); - deviceSlash.SetOptions(true, (byte)(brightness * 85.333), 0); + deviceSlash.SetOptions(true, brightness, inteval); deviceSlash.Save(); } }); diff --git a/app/AnimeMatrix/SlashDevice.cs b/app/AnimeMatrix/SlashDevice.cs index e470bb75c..6ebbd1949 100644 --- a/app/AnimeMatrix/SlashDevice.cs +++ b/app/AnimeMatrix/SlashDevice.cs @@ -44,9 +44,10 @@ public void SetMode(SlashMode mode) Set(Packet(0xD3, 0x04, 0x00, 0x0C, 0x01, (mode == SlashMode.Bitstream) ? (byte)0x1D : (byte)0x1A, 0x02, 0x19, 0x03, 0x13, 0x04, 0x11, 0x05, 0x12, 0x06, 0x13)); } - public void SetOptions(bool status, byte brightness = 0xFF, byte interval = 0x00) + public void SetOptions(bool status, int brightness = 0, int interval = 0) { - Set(Packet(0xD3, 0x03, 0x01, 0x08, 0xAB, 0xFF, 0x01, status ? (byte)0x01 : (byte)0x00, 0x06, brightness, 0xFF, interval)); + byte brightnessByte = (byte)(brightness * 85.333); + Set(Packet(0xD3, 0x03, 0x01, 0x08, 0xAB, 0xFF, 0x01, status ? (byte)0x01 : (byte)0x00, 0x06, brightnessByte, 0xFF, (byte)interval)); Save(); } diff --git a/app/Settings.Designer.cs b/app/Settings.Designer.cs index d0b30d58e..979414473 100644 --- a/app/Settings.Designer.cs +++ b/app/Settings.Designer.cs @@ -65,6 +65,7 @@ private void InitializeComponent() panelGPU = new Panel(); labelTipGPU = new Label(); tableAMD = new TableLayoutPanel(); + buttonOverlay = new RButton(); buttonFPS = new RButton(); tableGPU = new TableLayoutPanel(); buttonStopGPU = new RButton(); @@ -118,7 +119,7 @@ private void InitializeComponent() panelAllyTitle = new Panel(); pictureAlly = new PictureBox(); labelAlly = new Label(); - buttonOverlay = new RButton(); + comboInterval = new RComboBox(); panelMatrix.SuspendLayout(); tableLayoutMatrix.SuspendLayout(); panelMatrixTitle.SuspendLayout(); @@ -187,14 +188,16 @@ private void InitializeComponent() tableLayoutMatrix.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); tableLayoutMatrix.Controls.Add(comboMatrix, 0, 0); tableLayoutMatrix.Controls.Add(comboMatrixRunning, 1, 0); + tableLayoutMatrix.Controls.Add(comboInterval, 2, 0); tableLayoutMatrix.Controls.Add(buttonMatrix, 2, 0); tableLayoutMatrix.Dock = DockStyle.Top; tableLayoutMatrix.Location = new Point(20, 60); tableLayoutMatrix.Margin = new Padding(8); tableLayoutMatrix.Name = "tableLayoutMatrix"; - tableLayoutMatrix.RowCount = 1; + tableLayoutMatrix.RowCount = 2; tableLayoutMatrix.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); - tableLayoutMatrix.Size = new Size(787, 64); + tableLayoutMatrix.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F)); + tableLayoutMatrix.Size = new Size(787, 84); tableLayoutMatrix.TabIndex = 43; // // comboMatrix @@ -707,6 +710,28 @@ private void InitializeComponent() tableAMD.TabIndex = 24; tableAMD.Visible = false; // + // buttonOverlay + // + buttonOverlay.Activated = false; + buttonOverlay.BackColor = SystemColors.ControlLightLight; + buttonOverlay.BorderColor = Color.Transparent; + buttonOverlay.BorderRadius = 5; + buttonOverlay.Dock = DockStyle.Fill; + buttonOverlay.FlatAppearance.BorderSize = 0; + buttonOverlay.FlatStyle = FlatStyle.Flat; + buttonOverlay.ForeColor = SystemColors.ControlText; + buttonOverlay.Image = Properties.Resources.icons8_heartbeat_32; + buttonOverlay.ImageAlign = ContentAlignment.MiddleRight; + buttonOverlay.Location = new Point(266, 4); + buttonOverlay.Margin = new Padding(4); + buttonOverlay.Name = "buttonOverlay"; + buttonOverlay.Secondary = false; + buttonOverlay.Size = new Size(254, 72); + buttonOverlay.TabIndex = 12; + buttonOverlay.Text = "AMD Overlay"; + buttonOverlay.TextImageRelation = TextImageRelation.ImageBeforeText; + buttonOverlay.UseVisualStyleBackColor = false; + // // buttonFPS // buttonFPS.Activated = false; @@ -1586,27 +1611,20 @@ private void InitializeComponent() labelAlly.TabIndex = 26; labelAlly.Text = "Ally Controller"; // - // buttonOverlay - // - buttonOverlay.Activated = false; - buttonOverlay.BackColor = SystemColors.ControlLightLight; - buttonOverlay.BorderColor = Color.Transparent; - buttonOverlay.BorderRadius = 5; - buttonOverlay.Dock = DockStyle.Fill; - buttonOverlay.FlatAppearance.BorderSize = 0; - buttonOverlay.FlatStyle = FlatStyle.Flat; - buttonOverlay.ForeColor = SystemColors.ControlText; - buttonOverlay.Image = Properties.Resources.icons8_heartbeat_32; - buttonOverlay.ImageAlign = ContentAlignment.MiddleRight; - buttonOverlay.Location = new Point(266, 4); - buttonOverlay.Margin = new Padding(4); - buttonOverlay.Name = "buttonOverlay"; - buttonOverlay.Secondary = false; - buttonOverlay.Size = new Size(254, 72); - buttonOverlay.TabIndex = 12; - buttonOverlay.Text = "AMD Overlay"; - buttonOverlay.TextImageRelation = TextImageRelation.ImageBeforeText; - buttonOverlay.UseVisualStyleBackColor = false; + // comboInterval + // + comboInterval.BorderColor = Color.White; + comboInterval.ButtonColor = Color.FromArgb(255, 255, 255); + comboInterval.Dock = DockStyle.Top; + comboInterval.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + comboInterval.FormattingEnabled = true; + comboInterval.ItemHeight = 32; + comboInterval.Location = new Point(7, 75); + comboInterval.Margin = new Padding(7, 11, 7, 8); + comboInterval.Name = "comboInterval"; + comboInterval.Size = new Size(248, 40); + comboInterval.TabIndex = 19; + comboInterval.Visible = false; // // SettingsForm // @@ -1784,5 +1802,6 @@ private void InitializeComponent() private RButton buttonFPS; private RButton buttonController; private RButton buttonOverlay; + private RComboBox comboInterval; } } diff --git a/app/Settings.cs b/app/Settings.cs index 5f01a4aab..9094b3b58 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -173,9 +173,11 @@ public SettingsForm() comboMatrix.DropDownStyle = ComboBoxStyle.DropDownList; comboMatrixRunning.DropDownStyle = ComboBoxStyle.DropDownList; + comboInterval.DropDownStyle = ComboBoxStyle.DropDownList; comboMatrix.DropDownClosed += ComboMatrix_SelectedValueChanged; comboMatrixRunning.DropDownClosed += ComboMatrixRunning_SelectedValueChanged; + comboInterval.DropDownClosed += ComboInterval_DropDownClosed; buttonMatrix.Click += ButtonMatrix_Click; @@ -721,6 +723,12 @@ public void VisualiseMatrixRunning(int mode) }); } + private void ComboInterval_DropDownClosed(object? sender, EventArgs e) + { + AppConfig.Set("matrix_interval", comboInterval.SelectedIndex); + matrixControl.SetDevice(); + } + private void ComboMatrixRunning_SelectedValueChanged(object? sender, EventArgs e) { AppConfig.Set("matrix_running", comboMatrixRunning.SelectedIndex); @@ -902,11 +910,16 @@ public void InitMatrix() comboMatrixRunning.Items.Clear(); comboMatrixRunning.Items.Add("Transmission"); comboMatrixRunning.Items.Add("Bitstream"); + + comboInterval.Visible = true; + for (int i = 0; i <= 5; i++) comboInterval.Items.Add($"Interval {i}s"); + buttonMatrix.Visible = false; } comboMatrix.SelectedIndex = Math.Min(AppConfig.Get("matrix_brightness", 0), comboMatrix.Items.Count - 1); comboMatrixRunning.SelectedIndex = Math.Min(AppConfig.Get("matrix_running", 0), comboMatrixRunning.Items.Count - 1); + comboInterval.SelectedIndex = Math.Min(AppConfig.Get("matrix_interval", 0), comboInterval.Items.Count - 1); checkMatrix.Checked = AppConfig.Is("matrix_auto"); checkMatrix.CheckedChanged += CheckMatrix_CheckedChanged; From c4cd7748f669008222a48383e653363b8d578c88 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sun, 11 Feb 2024 12:06:54 +0100 Subject: [PATCH 6/9] UI tweaks --- app/Settings.Designer.cs | 2 +- app/Settings.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Settings.Designer.cs b/app/Settings.Designer.cs index 979414473..73fd98a7b 100644 --- a/app/Settings.Designer.cs +++ b/app/Settings.Designer.cs @@ -194,7 +194,7 @@ private void InitializeComponent() tableLayoutMatrix.Location = new Point(20, 60); tableLayoutMatrix.Margin = new Padding(8); tableLayoutMatrix.Name = "tableLayoutMatrix"; - tableLayoutMatrix.RowCount = 2; + tableLayoutMatrix.RowCount = 1; tableLayoutMatrix.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); tableLayoutMatrix.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F)); tableLayoutMatrix.Size = new Size(787, 84); diff --git a/app/Settings.cs b/app/Settings.cs index 9094b3b58..bf1fdddcb 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -909,10 +909,11 @@ public void InitMatrix() labelMatrix.Text = "Slash Lightning"; comboMatrixRunning.Items.Clear(); comboMatrixRunning.Items.Add("Transmission"); - comboMatrixRunning.Items.Add("Bitstream"); + comboMatrixRunning.Items.Add("Bit Stream"); comboInterval.Visible = true; - for (int i = 0; i <= 5; i++) comboInterval.Items.Add($"Interval {i}s"); + comboInterval.Items.Add($"Interval Off"); + for (int i = 1; i <= 5; i++) comboInterval.Items.Add($"Interval {i}s"); buttonMatrix.Visible = false; } From 763995084366c4e206f451060c313d7e00e2be0e Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sun, 11 Feb 2024 16:08:30 +0100 Subject: [PATCH 7/9] Slash tweaks --- app/AnimeMatrix/AniMatrixControl.cs | 2 +- app/AppConfig.cs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/AnimeMatrix/AniMatrixControl.cs b/app/AnimeMatrix/AniMatrixControl.cs index 663f734df..9d6c04f6b 100644 --- a/app/AnimeMatrix/AniMatrixControl.cs +++ b/app/AnimeMatrix/AniMatrixControl.cs @@ -36,7 +36,7 @@ public AniMatrixControl(SettingsForm settingsForm) try { - if (AppConfig.ContainsModel("GA40")) + if (AppConfig.ContainsModel("GA403")) deviceSlash = new SlashDevice(); else deviceMatrix = new AnimeMatrixDevice(); diff --git a/app/AppConfig.cs b/app/AppConfig.cs index bb148661d..0b9560321 100644 --- a/app/AppConfig.cs +++ b/app/AppConfig.cs @@ -101,6 +101,8 @@ public static string GetModel() } } + //if (_model.Contains("GA402")) _model = "ROG Zephyrus G14 GA403UI"; // Debug Purposes + return _model; } From ab44dbf2b4ad5ad2bd8b903b992109d9a666bb26 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Sun, 11 Feb 2024 21:39:43 +0100 Subject: [PATCH 8/9] More slash modes --- app/AnimeMatrix/AniMatrixControl.cs | 10 +++- app/AnimeMatrix/SlashDevice.cs | 82 +++++++++++++++++++++++++++-- app/AppConfig.cs | 2 +- app/Settings.cs | 9 ++-- app/USB/Aura.cs | 4 +- 5 files changed, 95 insertions(+), 12 deletions(-) diff --git a/app/AnimeMatrix/AniMatrixControl.cs b/app/AnimeMatrix/AniMatrixControl.cs index 9d6c04f6b..d792d7a79 100644 --- a/app/AnimeMatrix/AniMatrixControl.cs +++ b/app/AnimeMatrix/AniMatrixControl.cs @@ -36,7 +36,7 @@ public AniMatrixControl(SettingsForm settingsForm) try { - if (AppConfig.ContainsModel("GA403")) + if (AppConfig.ContainsModel("GA403") || AppConfig.ContainsModel("GU605")) deviceSlash = new SlashDevice(); else deviceMatrix = new AnimeMatrixDevice(); @@ -85,7 +85,7 @@ public void SetSlash(bool wakeUp = false) if (brightness == 0 || (auto && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online)) { deviceSlash.Init(); - deviceSlash.SetOptions(false); + deviceSlash.SetOptions(false, 0, 0); } else { @@ -97,6 +97,12 @@ public void SetSlash(bool wakeUp = false) }); } + public void SetBatteryAuto() + { + if (deviceSlash is not null) deviceSlash.SetBatterySaver(AppConfig.Is("matrix_auto")); + if (deviceMatrix is not null) SetMatrix(); + } + public void SetMatrix(bool wakeUp = false) { diff --git a/app/AnimeMatrix/SlashDevice.cs b/app/AnimeMatrix/SlashDevice.cs index 6ebbd1949..bd00b36f9 100644 --- a/app/AnimeMatrix/SlashDevice.cs +++ b/app/AnimeMatrix/SlashDevice.cs @@ -1,12 +1,26 @@ using GHelper.AnimeMatrix.Communication; +using GHelper.Mode; using System.Text; namespace GHelper.AnimeMatrix { public enum SlashMode { + Bounce, + Slash, + Loading, + BitStream, Transmission, - Bitstream + Flow, + Flux, + Phantom, + Spectrum, + Hazard, + Interfacing, + Ramp, + GameOver, + Start, + Buzzer } internal class SlashPacket : Packet @@ -18,6 +32,53 @@ public SlashPacket(byte[] command) : base(0x5E, 128, command) public class SlashDevice : Device { + + public static Dictionary Modes = new Dictionary + { + { SlashMode.Bounce, "Bounce"}, + { SlashMode.Slash, "Slash"}, + { SlashMode.Loading, "Loading"}, + + { SlashMode.BitStream, "Bit Stream"}, + { SlashMode.Transmission, "Transmission"}, + + { SlashMode.Flow, "Flow"}, + { SlashMode.Flux, "Flux"}, + { SlashMode.Phantom, "Phantom"}, + { SlashMode.Spectrum, "Spectrum"}, + + { SlashMode.Hazard, "Hazard"}, + { SlashMode.Interfacing, "Interfacing"}, + { SlashMode.Ramp, "Ramp"}, + + { SlashMode.GameOver, "Game Over"}, + { SlashMode.Start, "Start"}, + { SlashMode.Buzzer, "Buzzer"}, + }; + + private static Dictionary modeCodes = new Dictionary + { + { SlashMode.Bounce, 0x10}, + { SlashMode.Slash, 0x12}, + { SlashMode.Loading, 0x13}, + + { SlashMode.BitStream, 0x1D}, + { SlashMode.Transmission, 0x1A}, + + { SlashMode.Flow, 0x19}, + { SlashMode.Flux, 0x25}, + { SlashMode.Phantom, 0x24}, + { SlashMode.Spectrum, 0x26}, + + { SlashMode.Hazard, 0x32}, + { SlashMode.Interfacing, 0x33}, + { SlashMode.Ramp, 0x34}, + + { SlashMode.GameOver, 0x42}, + { SlashMode.Start, 0x43}, + { SlashMode.Buzzer, 0x44}, + }; + public SlashDevice() : base(0x0B05, 0x193B, 128) { } @@ -40,15 +101,30 @@ public void Save() public void SetMode(SlashMode mode) { + byte modeByte; + + try + { + modeByte = modeCodes[mode]; + } catch (Exception) + { + modeByte = 0x00; + } + Set(Packet(0xD2, 0x03, 0x00, 0x0C)); - Set(Packet(0xD3, 0x04, 0x00, 0x0C, 0x01, (mode == SlashMode.Bitstream) ? (byte)0x1D : (byte)0x1A, 0x02, 0x19, 0x03, 0x13, 0x04, 0x11, 0x05, 0x12, 0x06, 0x13)); + Set(Packet(0xD3, 0x04, 0x00, 0x0C, 0x01, modeByte, 0x02, 0x19, 0x03, 0x13, 0x04, 0x11, 0x05, 0x12, 0x06, 0x13)); } public void SetOptions(bool status, int brightness = 0, int interval = 0) { byte brightnessByte = (byte)(brightness * 85.333); + Set(Packet(0xD3, 0x03, 0x01, 0x08, 0xAB, 0xFF, 0x01, status ? (byte)0x01 : (byte)0x00, 0x06, brightnessByte, 0xFF, (byte)interval)); - Save(); + } + + public void SetBatterySaver(bool status) + { + Set(Packet(0xD8, 0x01, 0x00, 0x01, status ? (byte)0x80 : (byte)0x00)); } public void Set(Packet packet) diff --git a/app/AppConfig.cs b/app/AppConfig.cs index dc9e1b433..ba64a23f7 100644 --- a/app/AppConfig.cs +++ b/app/AppConfig.cs @@ -101,7 +101,7 @@ public static string GetModel() } } - //if (_model.Contains("GA402")) _model = "ROG Zephyrus G14 GA403UI"; // Debug Purposes + if (_model.Contains("GA402")) _model = "ROG Zephyrus G14 GA403UI"; // Debug Purposes return _model; } diff --git a/app/Settings.cs b/app/Settings.cs index bf1fdddcb..b5f122c1a 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -688,7 +688,7 @@ private void CheckStartup_CheckedChanged(object? sender, EventArgs e) private void CheckMatrix_CheckedChanged(object? sender, EventArgs e) { AppConfig.Set("matrix_auto", checkMatrix.Checked ? 1 : 0); - matrixControl.SetDevice(); + matrixControl.SetBatteryAuto(); } @@ -908,8 +908,11 @@ public void InitMatrix() { labelMatrix.Text = "Slash Lightning"; comboMatrixRunning.Items.Clear(); - comboMatrixRunning.Items.Add("Transmission"); - comboMatrixRunning.Items.Add("Bit Stream"); + + foreach (var item in SlashDevice.Modes) + { + comboMatrixRunning.Items.Add(item.Value); + } comboInterval.Visible = true; comboInterval.Items.Add($"Interval Off"); diff --git a/app/USB/Aura.cs b/app/USB/Aura.cs index ebc6e53f1..239d2143c 100644 --- a/app/USB/Aura.cs +++ b/app/USB/Aura.cs @@ -294,12 +294,10 @@ public static void ApplyBrightness(int brightness, string log = "Backlight", boo if (delay) await Task.Delay(TimeSpan.FromSeconds(1)); if (isACPI) Program.acpi.TUFKeyboardBrightness(brightness); - AsusHid.Write(new byte[] { AsusHid.AURA_ID, 0xBA, 0xC5, 0xC4, (byte)brightness }, log); + AsusHid.WriteInput(new byte[] { AsusHid.INPUT_ID, 0xBA, 0xC5, 0xC4, (byte)brightness }, log); if (AppConfig.IsAlly()) ApplyAura(); - if (AppConfig.IsInputBacklight()) - AsusHid.WriteInput(new byte[] { AsusHid.INPUT_ID, 0xBA, 0xC5, 0xC4, (byte)brightness }, log); }); From f326fa99cc574efa117f42d0b363f7c6b99f5e73 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Mon, 12 Feb 2024 10:14:52 +0100 Subject: [PATCH 9/9] Cleanup --- app/AnimeMatrix/AniMatrixControl.cs | 9 ++++----- app/AnimeMatrix/SlashDevice.cs | 8 ++++---- app/AppConfig.cs | 9 +++++++-- app/USB/Aura.cs | 5 ++++- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/AnimeMatrix/AniMatrixControl.cs b/app/AnimeMatrix/AniMatrixControl.cs index d792d7a79..b2b7033e0 100644 --- a/app/AnimeMatrix/AniMatrixControl.cs +++ b/app/AnimeMatrix/AniMatrixControl.cs @@ -4,7 +4,6 @@ using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Timers; -using static GHelper.AnimeMatrix.BuiltInAnimation; namespace GHelper.AnimeMatrix { @@ -36,7 +35,7 @@ public AniMatrixControl(SettingsForm settingsForm) try { - if (AppConfig.ContainsModel("GA403") || AppConfig.ContainsModel("GU605")) + if (AppConfig.IsSlash()) deviceSlash = new SlashDevice(); else deviceMatrix = new AnimeMatrixDevice(); @@ -165,9 +164,9 @@ public void SetMatrix(bool wakeUp = false) private void SetBuiltIn(int running) { BuiltInAnimation animation = new BuiltInAnimation( - (Running)running, - Sleeping.Starfield, - Shutdown.SeeYa, + (BuiltInAnimation.Running)running, + BuiltInAnimation.Sleeping.Starfield, + BuiltInAnimation.Shutdown.SeeYa, BuiltInAnimation.Startup.StaticEmergence ); deviceMatrix.SetBuiltInAnimation(true, animation); diff --git a/app/AnimeMatrix/SlashDevice.cs b/app/AnimeMatrix/SlashDevice.cs index bd00b36f9..04d6eff55 100644 --- a/app/AnimeMatrix/SlashDevice.cs +++ b/app/AnimeMatrix/SlashDevice.cs @@ -1,5 +1,4 @@ using GHelper.AnimeMatrix.Communication; -using GHelper.Mode; using System.Text; namespace GHelper.AnimeMatrix @@ -38,10 +37,10 @@ public class SlashDevice : Device { SlashMode.Bounce, "Bounce"}, { SlashMode.Slash, "Slash"}, { SlashMode.Loading, "Loading"}, - + { SlashMode.BitStream, "Bit Stream"}, { SlashMode.Transmission, "Transmission"}, - + { SlashMode.Flow, "Flow"}, { SlashMode.Flux, "Flux"}, { SlashMode.Phantom, "Phantom"}, @@ -106,7 +105,8 @@ public void SetMode(SlashMode mode) try { modeByte = modeCodes[mode]; - } catch (Exception) + } + catch (Exception) { modeByte = 0x00; } diff --git a/app/AppConfig.cs b/app/AppConfig.cs index ba64a23f7..fb9d65d1b 100644 --- a/app/AppConfig.cs +++ b/app/AppConfig.cs @@ -101,7 +101,7 @@ public static string GetModel() } } - if (_model.Contains("GA402")) _model = "ROG Zephyrus G14 GA403UI"; // Debug Purposes + //if (_model.Contains("GA402RK")) _model = "ROG Zephyrus G14 GA403UI"; // Debug Purposes return _model; } @@ -379,9 +379,14 @@ public static bool IsSingleColor() return ContainsModel("GA401") || ContainsModel("FX517Z") || ContainsModel("FX516P") || ContainsModel("X13") || IsARCNM() || ContainsModel("GA502IU"); } + public static bool IsSlash() + { + return ContainsModel("GA403") || ContainsModel("GU605"); + } + public static bool IsInputBacklight() { - return ContainsModel("GA503") || ContainsModel("GA403"); + return ContainsModel("GA503") || IsSlash(); } public static bool IsStrix() diff --git a/app/USB/Aura.cs b/app/USB/Aura.cs index 239d2143c..02e347e83 100644 --- a/app/USB/Aura.cs +++ b/app/USB/Aura.cs @@ -294,7 +294,10 @@ public static void ApplyBrightness(int brightness, string log = "Backlight", boo if (delay) await Task.Delay(TimeSpan.FromSeconds(1)); if (isACPI) Program.acpi.TUFKeyboardBrightness(brightness); - AsusHid.WriteInput(new byte[] { AsusHid.INPUT_ID, 0xBA, 0xC5, 0xC4, (byte)brightness }, log); + if (AppConfig.IsInputBacklight()) + AsusHid.WriteInput(new byte[] { AsusHid.INPUT_ID, 0xBA, 0xC5, 0xC4, (byte)brightness }, log); + else + AsusHid.Write(new byte[] { AsusHid.AURA_ID, 0xBA, 0xC5, 0xC4, (byte)brightness }, log); if (AppConfig.IsAlly()) ApplyAura();