diff --git a/app/AnimeMatrix/AniMatrixControl.cs b/app/AnimeMatrix/AniMatrixControl.cs index 2fa65cf0..d1ca6496 100644 --- a/app/AnimeMatrix/AniMatrixControl.cs +++ b/app/AnimeMatrix/AniMatrixControl.cs @@ -40,9 +40,16 @@ namespace GHelper.AnimeMatrix try { if (AppConfig.IsSlash()) - deviceSlash = new SlashDevice(); + { + if (AppConfig.IsSlashAura()) + deviceSlash = new SlashDeviceAura(); + else + deviceSlash = new SlashDevice(); + } else + { deviceMatrix = new AnimeMatrixDevice(); + } matrixTimer = new System.Timers.Timer(100); matrixTimer.Elapsed += MatrixTimer_Elapsed; @@ -103,7 +110,7 @@ namespace GHelper.AnimeMatrix deviceSlash.SetEnabled(true); deviceSlash.Init(); - + switch ((SlashMode)running) { case SlashMode.Static: @@ -111,7 +118,8 @@ namespace GHelper.AnimeMatrix if (custom is not null && custom.Length > 0) { deviceSlash.SetCustom(AppConfig.StringToBytes(custom)); - } else + } + else { deviceSlash.SetStatic(brightness); } @@ -137,7 +145,7 @@ namespace GHelper.AnimeMatrix public void SetLidMode(bool force = false) { bool matrixLid = AppConfig.Is("matrix_lid"); - + if (deviceSlash is not null) { deviceSlash.SetLidMode(true); @@ -268,8 +276,8 @@ namespace GHelper.AnimeMatrix StartMatrixTimer(1000); Logger.WriteLine("Matrix Clock"); } - - + + private void SlashTimer_start(int interval = 60000) { // 100% to 0% in 1hr = 1% every 36 seconds @@ -279,18 +287,18 @@ namespace GHelper.AnimeMatrix // create the timer if first call // this way, the timer only spawns if user tries to use battery pattern - if(slashTimer == default(System.Timers.Timer)) + if (slashTimer == default(System.Timers.Timer)) { slashTimer = new System.Timers.Timer(interval); slashTimer.Elapsed += SlashTimer_elapsed; slashTimer.AutoReset = true; } // only write if interval changed - if(slashTimer.Interval != interval) + if (slashTimer.Interval != interval) { slashTimer.Interval = interval; } - + slashTimer.Start(); } @@ -304,7 +312,7 @@ namespace GHelper.AnimeMatrix if (deviceSlash is null) return; //kill timer if called but not in battery pattern mode - if((SlashMode)AppConfig.Get("matrix_running", 0) != SlashMode.BatteryLevel) + if ((SlashMode)AppConfig.Get("matrix_running", 0) != SlashMode.BatteryLevel) { slashTimer.Stop(); slashTimer.Dispose(); diff --git a/app/AnimeMatrix/SlashDevice.cs b/app/AnimeMatrix/SlashDevice.cs index 13053a3e..6dbee0c8 100644 --- a/app/AnimeMatrix/SlashDevice.cs +++ b/app/AnimeMatrix/SlashDevice.cs @@ -1,7 +1,6 @@ using GHelper.AnimeMatrix.Communication; using System.Management; using System.Text; -using System.Timers; namespace GHelper.AnimeMatrix { @@ -26,16 +25,16 @@ namespace GHelper.AnimeMatrix BatteryLevel, } - internal class SlashPacket : Packet - { - public SlashPacket(byte[] command) : base(0x5E, 128, command) - { - } - } - public class SlashDevice : Device { + internal class SlashPacket : Packet + { + public SlashPacket(byte[] command) : base(0x5E, 128, command) + { + } + } + public static Dictionary Modes = new Dictionary { { SlashMode.Bounce, "Bounce"}, @@ -85,7 +84,7 @@ namespace GHelper.AnimeMatrix { SlashMode.Buzzer, 0x44}, }; - public SlashDevice() : base(0x0B05, 0x193B, 128) + public SlashDevice(ushort productId = 0x193B) : base(0x0B05, productId, 128) { } @@ -135,23 +134,23 @@ namespace GHelper.AnimeMatrix } public static double GetBatteryChargePercentage() + { + double batteryCharge = 0; + try { - double batteryCharge = 0; - try + ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Battery"); + foreach (ManagementObject battery in searcher.Get()) { - ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Battery"); - foreach (ManagementObject battery in searcher.Get()) - { - batteryCharge = Convert.ToDouble(battery["EstimatedChargeRemaining"]); - break; // Assuming only one battery - } + batteryCharge = Convert.ToDouble(battery["EstimatedChargeRemaining"]); + break; // Assuming only one battery } - catch (ManagementException e) - { - Console.WriteLine("An error occurred while querying for WMI data: " + e.Message); - } - return batteryCharge; } + catch (ManagementException e) + { + Console.WriteLine("An error occurred while querying for WMI data: " + e.Message); + } + return batteryCharge; + } private byte[] GetBatteryPattern(int brightness, double percentage) { @@ -159,23 +158,23 @@ namespace GHelper.AnimeMatrix // set brightness to reflect battery's percentage within that range int bracket = (int)Math.Floor(percentage / 14.2857); - if(bracket >= 7) return Enumerable.Repeat((byte)(brightness * 85.333), 7).ToArray(); - + if (bracket >= 7) return Enumerable.Repeat((byte)(brightness * 85.333), 7).ToArray(); + byte[] batteryPattern = Enumerable.Repeat((byte)(0x00), 7).ToArray(); - for (int i = 6; i > 6-bracket; i--) + for (int i = 6; i > 6 - bracket; i--) { batteryPattern[i] = (byte)(brightness * 85.333); } //set the "selected" bracket to the percentage of that bracket filled from 0 to 255 as a hex - batteryPattern[6-bracket] = (byte)(((percentage % 14.2857) * brightness * 85.333) / 14.2857); + batteryPattern[6 - bracket] = (byte)(((percentage % 14.2857) * brightness * 85.333) / 14.2857); return batteryPattern; } public void SetBatteryPattern(int brightness) { - SetCustom(GetBatteryPattern(brightness, 100*(GetBatteryChargePercentage()/AppConfig.Get("charge_limit",100)))); + SetCustom(GetBatteryPattern(brightness, 100 * (GetBatteryChargePercentage() / AppConfig.Get("charge_limit", 100)))); } public void SetCustom(byte[] data) @@ -214,9 +213,22 @@ namespace GHelper.AnimeMatrix public void Set(Packet packet, string? log = null) { _usbProvider?.Set(packet.Data); - if (log is not null) Logger.WriteLine($"{log}:" + BitConverter.ToString(packet.Data).Substring(0,48)); + if (log is not null) Logger.WriteLine($"{log}:" + BitConverter.ToString(packet.Data).Substring(0, 48)); + } + } + + public class SlashDeviceAura : SlashDevice + { + public SlashDeviceAura(): base(0x193B) + { } + internal new class SlashPacket : Packet + { + public SlashPacket(byte[] command) : base(0x5D, 128, command) + { + } + } } } \ No newline at end of file diff --git a/app/AppConfig.cs b/app/AppConfig.cs index 6e12a1b2..f46be871 100644 --- a/app/AppConfig.cs +++ b/app/AppConfig.cs @@ -405,6 +405,11 @@ public static class AppConfig return ContainsModel("GA403") || ContainsModel("GU605") || ContainsModel("GA605"); } + public static bool IsSlashAura() + { + return ContainsModel("GA605"); + } + public static bool IsInputBacklight() { return ContainsModel("GA503") || IsSlash(); @@ -583,7 +588,7 @@ public static class AppConfig public static bool IsFanRequired() { - return ContainsModel("GA402X") || ContainsModel("G513") || ContainsModel("G713R") || ContainsModel("G713P") || ContainsModel("GU605") || ContainsModel("GA605") || ContainsModel("GA403") || ContainsModel("G634J") || ContainsModel("G834J") || ContainsModel("G614J") || ContainsModel("G814J") || ContainsModel("FX507V"); + return ContainsModel("GA402X") || ContainsModel("G513") || ContainsModel("G713R") || ContainsModel("G713P") || ContainsModel("GU605") || ContainsModel("GA403") || ContainsModel("G634J") || ContainsModel("G834J") || ContainsModel("G614J") || ContainsModel("G814J") || ContainsModel("FX507V"); } public static bool IsAMDLight()