From 7702dc8e3868adc0af06ca66f563f7c77ec0ce81 Mon Sep 17 00:00:00 2001 From: seerge Date: Sat, 25 Mar 2023 14:37:37 +0100 Subject: [PATCH] Support for TUF RGB keyboards and other fixes --- app/ASUSWmi.cs | 53 +++++++- app/AnimeMatrix/AnimeMatrixDevice.cs | 116 ++++++++++++++--- app/Aura.cs | 188 ++++++++++++++++++--------- app/GHelper.csproj | 2 +- app/Program.cs | 9 +- app/Settings.Designer.cs | 70 ++++++---- app/Settings.cs | 130 ++++++++---------- 7 files changed, 373 insertions(+), 195 deletions(-) diff --git a/app/ASUSWmi.cs b/app/ASUSWmi.cs index 709ca1d8..ae477eae 100644 --- a/app/ASUSWmi.cs +++ b/app/ASUSWmi.cs @@ -1,4 +1,6 @@ -using System.Management; +using GHelper; +using System.Diagnostics; +using System.Management; using System.Runtime.InteropServices; public class ASUSWmi @@ -38,6 +40,9 @@ public class ASUSWmi public const int PPT_APUC1 = 0x001200C1; public const int PPT_APUC2 = 0x001200C2; + public const int TUF_KB = 0x00100056; + public const int TUF_KB_STATE = 0x00100057; + public const int PerformanceBalanced = 0; public const int PerformanceTurbo = 1; public const int PerformanceSilent = 2; @@ -146,21 +151,21 @@ public class ASUSWmi } - public void DeviceSet(uint DeviceID, int Status) + public byte[] DeviceSet(uint DeviceID, int Status) { byte[] args = new byte[8]; BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0); BitConverter.GetBytes((uint)Status).CopyTo(args, 4); - CallMethod(DEVS, args); + return CallMethod(DEVS, args); } - public void DeviceSet(uint DeviceID, byte[] Params) + public byte[] DeviceSet(uint DeviceID, byte[] Params) { byte[] args = new byte[4 + Params.Length]; BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0); Params.CopyTo(args, 4); - CallMethod(DEVS, args); + return CallMethod(DEVS, args); } @@ -232,6 +237,44 @@ public class ASUSWmi } + public void TUFKeyboardRGB(int mode, Color color, int speed) + { + + byte[] setting = new byte[12]; + setting[0] = (byte)1; + setting[1] = (byte)mode; + setting[2] = color.R; + setting[3] = color.G; + setting[4] = color.B; + setting[5] = (byte)speed; + + DeviceSet(TUF_KB, setting); + Debug.WriteLine(BitConverter.ToString(setting)); + + /* + uint flags, boot = 1, awake = 1, sleep = 1, keyboard = 1; + + flags = 0; + if (boot != 0) + flags |= (1 << 1); + if (awake != 0) + flags |= (1 << 3); + if (sleep != 0) + flags |= (1 << 5); + if (keyboard != 0) + flags |= (1 << 7); + + byte[] state = new byte[12]; + state[0] = 0xbd; + state[1] = (byte)((cmd != 0) ? (1 << 2) : 0); + state[2] = (byte)flags; + + DeviceSet(TUF_KB, state); + Debug.WriteLine(BitConverter.ToString(state)); + */ + + } + public void SubscribeToEvents(Action EventHandler) { ManagementEventWatcher watcher = new ManagementEventWatcher(); diff --git a/app/AnimeMatrix/AnimeMatrixDevice.cs b/app/AnimeMatrix/AnimeMatrixDevice.cs index 17c42fa0..73d029cf 100644 --- a/app/AnimeMatrix/AnimeMatrixDevice.cs +++ b/app/AnimeMatrix/AnimeMatrixDevice.cs @@ -2,6 +2,7 @@ using Starlight.Communication; using System.Management; +using System.Runtime.CompilerServices; using System.Text; namespace Starlight.AnimeMatrix @@ -56,6 +57,14 @@ namespace Starlight.AnimeMatrix } } + public enum AnimeType + { + GA401, + GA402 + } + + + public enum BrightnessMode : byte { Off = 0, @@ -74,29 +83,35 @@ namespace Starlight.AnimeMatrix List frames = new List(); public int MaxRows = 61; - public int FullRows = 11; - public int FullEvenRows = -1; + //public int FullRows = 11; + //public int FullEvenRows = -1; public int MaxColumns = 34; private int frameIndex = 0; + private static AnimeType _model = AnimeType.GA402; + public AnimeMatrixDevice() : base(0x0B05, 0x193B, 640) { string model = GetModel(); if (model.Contains("401")) { + + _model = AnimeType.GA401; + MaxColumns = 33; - FullRows = 7; - FullEvenRows = 3; + //FullRows = 7; + //FullEvenRows = 3; MaxRows = 55; LedCount = 1214; UpdatePageLength = 410; } + _displayBuffer = new byte[LedCount]; } @@ -144,6 +159,70 @@ namespace Starlight.AnimeMatrix } + public static int FirstX(int y) + { + switch (_model) + { + case AnimeType.GA401: + if (y < 5) + { + return 0; + } + else + { + return (y + 1) / 2 - 3; + } + case AnimeType.GA402: + if (y < 11) + { + return 0; + } else + { + return (y) / 2 - 5; + } + default: + throw new ArgumentException("Invalid anime type", nameof(_model)); + } + } + + public static int Width(int y) + { + switch (_model) + { + case AnimeType.GA401: + return 33; + case AnimeType.GA402: + return 34; + default: + throw new ArgumentException("Invalid anime type", nameof(_model)); + } + } + + public static int Pitch(int y) + { + switch (_model) + { + case AnimeType.GA401: + switch (y) + { + case 0: + case 2: + case 4: + return 33; + case 1: + case 3: + return 35; // Some rows are padded + default: + return 36 - y / 2; + } + case AnimeType.GA402: + return Width(y) - FirstX(y); + default: + throw new ArgumentException("Invalid anime type", nameof(_model)); + } + } + + /* public int XStart(int row) { return (int)Math.Ceiling(Math.Max(0, row - FullRows) / 2.0); @@ -158,19 +237,30 @@ namespace Starlight.AnimeMatrix } return MaxColumns; } + */ - public int RowToLinearAddress(int row) + public int RowToLinearAddress(int y) { - EnsureRowInRange(row); + EnsureRowInRange(y); int ret = 0; - for (var i = 0; i < row; i++) - ret += XEnd(i) - XStart(i); + for (var i = 0; i < y; i++) + ret += Pitch(i); return ret; } + public void SetLedPlanar(int x, int y, byte value) + { + EnsureRowInRange(y); + + if (x >= FirstX(y) && x < Width(y)) + { + SetLedLinear(RowToLinearAddress(y) - FirstX(y) + x, value); + } + } + public void WakeUp() { Set(Packet(Encoding.ASCII.GetBytes("ASUS Tech.Inc."))); @@ -196,15 +286,7 @@ namespace Starlight.AnimeMatrix Set(Packet(0xC0, 0x03)); } - public void SetLedPlanar(int x, int y, byte value) - { - EnsureRowInRange(y); - var start = RowToLinearAddress(y) - XStart(y); - if (x >= XStart(y) && x < MaxColumns) - { - SetLedLinear(start + x, value); - } - } + public void Clear(bool present = false) { diff --git a/app/Aura.cs b/app/Aura.cs index 0407b372..93420d4e 100644 --- a/app/Aura.cs +++ b/app/Aura.cs @@ -1,78 +1,142 @@ using HidLibrary; -public class Aura +namespace GHelper { - static byte[] MESSAGE_SET = { 0x5d, 0xb5, 0,0,0 }; - static byte[] MESSAGE_APPLY = { 0x5d, 0xb4}; - public const int Static = 0; - public const int Breathe = 1; - public const int Strobe = 2; - public const int Rainbow = 3; - public const int Dingding = 4; - - public const int SpeedSlow = 0xe1; - public const int SpeedMedium = 0xeb; - public const int SpeedHigh = 0xf5; - - public static int Mode = Static; - public static Color Color1 = Color.White; - public static Color Color2 = Color.Black; - public static int Speed = SpeedSlow; - - public static byte[] AuraMessage(int mode, Color color, Color color2, int speed) - { - byte[] msg = new byte[17]; - msg[0] = 0x5d; - msg[1] = 0xb3; - msg[2] = 0x00; // Zone - msg[3] = (byte)mode; // Aura Mode - msg[4] = (byte)(color.R); // R - msg[5] = (byte)(color.G); // G - msg[6] = (byte)(color.B); // B - msg[7] = (byte)speed; // aura.speed as u8; - msg[8] = 0; // aura.direction as u8; - msg[10] = (byte)(color2.R); // R - msg[11] = (byte)(color2.G); // G - msg[12] = (byte)(color2.B); // B - return msg; - } - - public static void ApplyAura() + public class Aura { - HidDevice[] HidDeviceList; - int[] deviceIds = { 0x1854, 0x1869, 0x1866, 0x19b6, 0x1822, 0x1837, 0x1854, 0x184a, 0x183d, 0x8502, 0x1807, 0x17e0 }; + static byte[] MESSAGE_SET = { 0x5d, 0xb5, 0, 0, 0 }; + static byte[] MESSAGE_APPLY = { 0x5d, 0xb4 }; - HidDeviceList = HidDevices.Enumerate(0x0b05, deviceIds).ToArray(); - if (Mode == Dingding) - { - Mode = 10; - Speed = SpeedMedium; - } - else if (Mode == Rainbow) - { - Speed = SpeedMedium; - } - else - { - Speed = SpeedSlow; - } + private static int mode = 0; + private static int speed = 1; + public static Color Color1 = Color.White; + public static Color Color2 = Color.Black; - foreach (HidDevice device in HidDeviceList) + + public static Dictionary GetSpeeds() { - if (device.IsConnected && device.Description.Contains("HID")) + return new Dictionary { - device.OpenDevice(); - byte[] msg = AuraMessage(Mode, Color1, Color2, Speed); - device.Write(msg); - device.Write(MESSAGE_SET); - device.Write(MESSAGE_APPLY); - device.CloseDevice(); + { 0, "Slow" }, + { 1, "Normal" }, + { 2, "Fast" } + }; + } + public static Dictionary GetModes() + { + return new Dictionary + { + { 0, "Static" }, + { 1, "Breathe" }, + { 2, "Rainbow" }, + { 10, "Strobe" }, + }; + } + + + public static int Mode + { + get { return mode; } + set + { + if (GetModes().ContainsKey(value)) + mode = value; + else + mode = 0; } } + public static bool HasSecondColor() + { + return mode == 1; + } + + public static int Speed + { + get { return speed; } + set + { + if (GetSpeeds().ContainsKey(value)) + speed = value; + else + speed = 1; + } + + } + + public static void SetColor(int colorCode) + { + Color1 = Color.FromArgb(colorCode); + } + + public static void SetColor2(int colorCode) + { + Color2 = Color.FromArgb(colorCode); + } + + public static byte[] AuraMessage(int mode, Color color, Color color2, int speed) + { + + byte[] msg = new byte[17]; + msg[0] = 0x5d; + msg[1] = 0xb3; + msg[2] = 0x00; // Zone + msg[3] = (byte)mode; // Aura Mode + msg[4] = (byte)(color.R); // R + msg[5] = (byte)(color.G); // G + msg[6] = (byte)(color.B); // B + msg[7] = (byte)speed; // aura.speed as u8; + msg[8] = 0; // aura.direction as u8; + msg[10] = (byte)(color2.R); // R + msg[11] = (byte)(color2.G); // G + msg[12] = (byte)(color2.B); // B + return msg; + } + + public static void ApplyAura() + { + + HidDevice[] HidDeviceList; + int[] deviceIds = { 0x1854, 0x1869, 0x1866, 0x19b6, 0x1822, 0x1837, 0x1854, 0x184a, 0x183d, 0x8502, 0x1807, 0x17e0 }; + + HidDeviceList = HidDevices.Enumerate(0x0b05, deviceIds).ToArray(); + + int _speed; + + switch (Speed) + { + case 1: + _speed = 0xeb; + break; + case 2: + _speed = 0xf5; + break; + default: + _speed = 0xe1; + break; + } + + + Program.wmi.TUFKeyboardRGB(Mode, Color1, _speed); + + foreach (HidDevice device in HidDeviceList) + { + if (device.IsConnected && device.Description.Contains("HID")) + { + device.OpenDevice(); + byte[] msg = AuraMessage(Mode, Color1, Color2, _speed); + device.Write(msg); + device.Write(MESSAGE_SET); + device.Write(MESSAGE_APPLY); + device.CloseDevice(); + } + } + + } } -} + +} \ No newline at end of file diff --git a/app/GHelper.csproj b/app/GHelper.csproj index da8c9599..48d22344 100644 --- a/app/GHelper.csproj +++ b/app/GHelper.csproj @@ -16,7 +16,7 @@ x64 False True - 0.38 + 0.39 diff --git a/app/Program.cs b/app/Program.cs index 16a150e0..66ffe58e 100644 --- a/app/Program.cs +++ b/app/Program.cs @@ -23,8 +23,7 @@ namespace GHelper public static SettingsForm settingsForm = new SettingsForm(); public static ToastForm toast = new ToastForm(); - private static IntPtr unRegPowerNotify; - private static IntPtr ds; + public static IntPtr unRegPowerNotify; private static long lastAuto; private static long lastTheme; @@ -56,7 +55,7 @@ namespace GHelper SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged); - ds = settingsForm.Handle; + var ds = settingsForm.Handle; trayIcon.MouseClick += TrayIcon_MouseClick; @@ -72,10 +71,6 @@ namespace GHelper SetAutoModes(); HardwareMonitor.RecreateGpuTemperatureProvider(); - // Subscribing for monitor power on events - var settingGuid = new NativeMethods.PowerSettingGuid(); - unRegPowerNotify = NativeMethods.RegisterPowerSettingNotification(ds, settingGuid.ConsoleDisplayState, NativeMethods.DEVICE_NOTIFY_WINDOW_HANDLE); - // Subscribing for system power change events SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; diff --git a/app/Settings.Designer.cs b/app/Settings.Designer.cs index 52be8dd9..fbbbac98 100644 --- a/app/Settings.Designer.cs +++ b/app/Settings.Designer.cs @@ -79,12 +79,13 @@ namespace GHelper labelSreen = new Label(); panelKeyboard = new Panel(); tableLayoutKeyboard = new TableLayoutPanel(); - buttonKeyboard = new RButton(); comboKeyboard = new RComboBox(); + comboKeyboardSpeed = new RComboBox(); panelColor = new Panel(); pictureColor2 = new PictureBox(); pictureColor = new PictureBox(); buttonKeyboardColor = new RButton(); + buttonKeyboard = new RButton(); pictureKeyboard = new PictureBox(); labelKeyboard = new Label(); panelMatrix.SuspendLayout(); @@ -868,9 +869,10 @@ namespace GHelper tableLayoutKeyboard.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); tableLayoutKeyboard.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); tableLayoutKeyboard.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); - tableLayoutKeyboard.Controls.Add(buttonKeyboard, 2, 0); tableLayoutKeyboard.Controls.Add(comboKeyboard, 0, 0); - tableLayoutKeyboard.Controls.Add(panelColor, 1, 0); + tableLayoutKeyboard.Controls.Add(comboKeyboardSpeed, 1, 0); + tableLayoutKeyboard.Controls.Add(panelColor, 2, 0); + tableLayoutKeyboard.Controls.Add(buttonKeyboard, 3, 0); tableLayoutKeyboard.Location = new Point(16, 50); tableLayoutKeyboard.Margin = new Padding(8); tableLayoutKeyboard.Name = "tableLayoutKeyboard"; @@ -879,24 +881,6 @@ namespace GHelper tableLayoutKeyboard.Size = new Size(772, 60); tableLayoutKeyboard.TabIndex = 39; // - // buttonKeyboard - // - buttonKeyboard.Activated = false; - buttonKeyboard.BackColor = Color.FromArgb(230, 230, 230); - buttonKeyboard.BorderColor = Color.Transparent; - buttonKeyboard.BorderRadius = 2; - buttonKeyboard.Dock = DockStyle.Top; - buttonKeyboard.FlatAppearance.BorderSize = 0; - buttonKeyboard.FlatStyle = FlatStyle.Flat; - buttonKeyboard.Location = new Point(390, 8); - buttonKeyboard.Margin = new Padding(4, 8, 4, 8); - buttonKeyboard.Name = "buttonKeyboard"; - buttonKeyboard.Secondary = true; - buttonKeyboard.Size = new Size(185, 44); - buttonKeyboard.TabIndex = 37; - buttonKeyboard.Text = "Extra"; - buttonKeyboard.UseVisualStyleBackColor = false; - // // comboKeyboard // comboKeyboard.BorderColor = Color.White; @@ -906,7 +890,7 @@ namespace GHelper comboKeyboard.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); comboKeyboard.FormattingEnabled = true; comboKeyboard.ItemHeight = 32; - comboKeyboard.Items.AddRange(new object[] { "Static", "Breathe", "Strobe", "Rainbow", "Dingding" }); + comboKeyboard.Items.AddRange(new object[] { "Static", "Breathe", "Rainbow", "Strobe" }); comboKeyboard.Location = new Point(4, 10); comboKeyboard.Margin = new Padding(4, 10, 4, 8); comboKeyboard.Name = "comboKeyboard"; @@ -914,6 +898,23 @@ namespace GHelper comboKeyboard.TabIndex = 35; comboKeyboard.TabStop = false; // + // comboKeyboardSpeed + // + comboKeyboardSpeed.BorderColor = Color.White; + comboKeyboardSpeed.ButtonColor = SystemColors.ControlLight; + comboKeyboardSpeed.Dock = DockStyle.Top; + comboKeyboardSpeed.FlatStyle = FlatStyle.Flat; + comboKeyboardSpeed.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); + comboKeyboardSpeed.FormattingEnabled = true; + comboKeyboardSpeed.ItemHeight = 32; + comboKeyboardSpeed.Items.AddRange(new object[] { "Slow", "Normal", "Fast" }); + comboKeyboardSpeed.Location = new Point(197, 10); + comboKeyboardSpeed.Margin = new Padding(4, 10, 4, 8); + comboKeyboardSpeed.Name = "comboKeyboardSpeed"; + comboKeyboardSpeed.Size = new Size(185, 40); + comboKeyboardSpeed.TabIndex = 38; + comboKeyboardSpeed.TabStop = false; + // // panelColor // panelColor.AutoSize = true; @@ -921,7 +922,7 @@ namespace GHelper panelColor.Controls.Add(pictureColor); panelColor.Controls.Add(buttonKeyboardColor); panelColor.Dock = DockStyle.Fill; - panelColor.Location = new Point(197, 8); + panelColor.Location = new Point(390, 8); panelColor.Margin = new Padding(4, 8, 4, 8); panelColor.Name = "panelColor"; panelColor.Size = new Size(185, 44); @@ -930,7 +931,7 @@ namespace GHelper // pictureColor2 // pictureColor2.Anchor = AnchorStyles.Top | AnchorStyles.Right; - pictureColor2.Location = new Point(123, 12); + pictureColor2.Location = new Point(126, 12); pictureColor2.Margin = new Padding(8); pictureColor2.Name = "pictureColor2"; pictureColor2.Size = new Size(20, 20); @@ -962,9 +963,27 @@ namespace GHelper buttonKeyboardColor.Secondary = false; buttonKeyboardColor.Size = new Size(185, 44); buttonKeyboardColor.TabIndex = 39; - buttonKeyboardColor.Text = "Color "; + buttonKeyboardColor.Text = " Color ."; buttonKeyboardColor.UseVisualStyleBackColor = false; // + // buttonKeyboard + // + buttonKeyboard.Activated = false; + buttonKeyboard.BackColor = Color.FromArgb(230, 230, 230); + buttonKeyboard.BorderColor = Color.Transparent; + buttonKeyboard.BorderRadius = 2; + buttonKeyboard.Dock = DockStyle.Top; + buttonKeyboard.FlatAppearance.BorderSize = 0; + buttonKeyboard.FlatStyle = FlatStyle.Flat; + buttonKeyboard.Location = new Point(583, 8); + buttonKeyboard.Margin = new Padding(4, 8, 4, 8); + buttonKeyboard.Name = "buttonKeyboard"; + buttonKeyboard.Secondary = true; + buttonKeyboard.Size = new Size(185, 44); + buttonKeyboard.TabIndex = 37; + buttonKeyboard.Text = "Extra"; + buttonKeyboard.UseVisualStyleBackColor = false; + // // pictureKeyboard // pictureKeyboard.BackgroundImage = Properties.Resources.icons8_keyboard_48; @@ -1103,5 +1122,6 @@ namespace GHelper private RButton buttonKeyboardColor; private RButton buttonFans; private Label labelMidFan; + private RComboBox comboKeyboardSpeed; } } \ No newline at end of file diff --git a/app/Settings.cs b/app/Settings.cs index a318bf65..e4732800 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -66,10 +66,6 @@ namespace GHelper buttonQuit.Click += ButtonQuit_Click; - comboKeyboard.DropDownStyle = ComboBoxStyle.DropDownList; - comboKeyboard.SelectedIndex = 0; - comboKeyboard.SelectedValueChanged += ComboKeyboard_SelectedValueChanged; - buttonKeyboardColor.Click += ButtonKeyboardColor_Click; buttonFans.Click += ButtonFans_Click; @@ -133,8 +129,13 @@ namespace GHelper t.Start(); t.Join(); + // Subscribing for monitor power on events + var settingGuid = new NativeMethods.PowerSettingGuid(); + Program.unRegPowerNotify = NativeMethods.RegisterPowerSettingNotification(Handle, settingGuid.ConsoleDisplayState, NativeMethods.DEVICE_NOTIFY_WINDOW_HANDLE); + } + private void TrackBattery_ValueChanged(object? sender, EventArgs e) { SetBatteryChargeLimit(trackBattery.Value); @@ -255,6 +256,7 @@ namespace GHelper protected override void WndProc(ref Message m) { + switch (m.Msg) { case NativeMethods.WM_POWERBROADCAST: @@ -511,12 +513,13 @@ namespace GHelper { ColorDialog colorDlg = new ColorDialog(); - colorDlg.AllowFullOpen = false; + colorDlg.AllowFullOpen = true; colorDlg.Color = pictureColor2.BackColor; if (colorDlg.ShowDialog() == DialogResult.OK) { - SetAuraColor(color2: colorDlg.Color); + Program.config.setConfig("aura_color2", colorDlg.Color.ToArgb()); + SetAura(); } } @@ -561,45 +564,42 @@ namespace GHelper private void ButtonKeyboardColor_Click(object? sender, EventArgs e) { - if (sender is null) - return; - - Button but = (Button)sender; - ColorDialog colorDlg = new ColorDialog(); - colorDlg.AllowFullOpen = false; + colorDlg.AllowFullOpen = true; colorDlg.Color = pictureColor.BackColor; if (colorDlg.ShowDialog() == DialogResult.OK) { - SetAuraColor(color1: colorDlg.Color); + Program.config.setConfig("aura_color", colorDlg.Color.ToArgb()); + SetAura(); } } public void InitAura() { - int mode = Program.config.getConfig("aura_mode"); - int colorCode = Program.config.getConfig("aura_color"); - int colorCode2 = Program.config.getConfig("aura_color2"); + Aura.Mode = Program.config.getConfig("aura_mode"); + Aura.Speed = Program.config.getConfig("aura_speed"); + Aura.SetColor(Program.config.getConfig("aura_color")); + Aura.SetColor2(Program.config.getConfig("aura_color2")); - int speed = Program.config.getConfig("aura_speed"); + comboKeyboard.DropDownStyle = ComboBoxStyle.DropDownList; + comboKeyboard.DataSource = new BindingSource(Aura.GetModes(), null); + comboKeyboard.DisplayMember = "Value"; + comboKeyboard.ValueMember = "Key"; + comboKeyboard.SelectedValue = Aura.Mode; + comboKeyboard.SelectedValueChanged += ComboKeyboard_SelectedValueChanged; - Color color = Color.FromArgb(255, 255, 255); - Color color2 = Color.FromArgb(0, 0, 0); + comboKeyboardSpeed.DropDownStyle = ComboBoxStyle.DropDownList; + comboKeyboardSpeed.DataSource = new BindingSource(Aura.GetSpeeds(), null); + comboKeyboardSpeed.DisplayMember = "Value"; + comboKeyboardSpeed.ValueMember = "Key"; + comboKeyboardSpeed.SelectedValue = Aura.Speed; + comboKeyboardSpeed.SelectedValueChanged += ComboKeyboardSpeed_SelectedValueChanged; - if (mode == -1) - mode = 0; - if (colorCode != -1) - color = Color.FromArgb(colorCode); - - if (colorCode2 != -1) - color2 = Color.FromArgb(colorCode2); - - SetAuraColor(color, color2, false); - SetAuraMode(mode, false); - - Aura.Mode = mode; + pictureColor.BackColor = Aura.Color1; + pictureColor2.BackColor = Aura.Color2; + pictureColor2.Visible = Aura.HasSecondColor(); } public void InitMatrix() @@ -629,67 +629,42 @@ namespace GHelper } - public void SetAuraColor(Color? color1 = null, Color? color2 = null, bool apply = true) + public void SetAura() { - - if (color1 is not null) - { - Aura.Color1 = (Color)color1; - Program.config.setConfig("aura_color", Aura.Color1.ToArgb()); - - } - - if (color2 is not null) - { - Aura.Color2 = (Color)color2; - Program.config.setConfig("aura_color2", Aura.Color2.ToArgb()); - } - - if (apply) - Aura.ApplyAura(); + Aura.Mode = Program.config.getConfig("aura_mode"); + Aura.Speed = Program.config.getConfig("aura_speed"); + Aura.SetColor(Program.config.getConfig("aura_color")); + Aura.SetColor2(Program.config.getConfig("aura_color2")); pictureColor.BackColor = Aura.Color1; pictureColor2.BackColor = Aura.Color2; - } + pictureColor2.Visible = Aura.HasSecondColor(); - public void SetAuraMode(int mode = 0, bool apply = true) - { - - //Debug.WriteLine(mode); - - if (mode > 4) mode = 0; - - pictureColor2.Visible = (mode == Aura.Breathe); - - if (Aura.Mode == mode) return; // same mode - - Aura.Mode = mode; - - Program.config.setConfig("aura_mode", mode); - - comboKeyboard.SelectedValueChanged -= ComboKeyboard_SelectedValueChanged; - comboKeyboard.SelectedIndex = mode; - comboKeyboard.SelectedValueChanged += ComboKeyboard_SelectedValueChanged; - - if (apply) - Aura.ApplyAura(); + Aura.ApplyAura(); } public void CycleAuraMode() { - SetAuraMode(Program.config.getConfig("aura_mode") + 1); + if (comboKeyboard.SelectedIndex < comboKeyboard.Items.Count-1) + comboKeyboard.SelectedIndex += 1; + else + comboKeyboard.SelectedIndex = 0; } private void ComboKeyboard_SelectedValueChanged(object? sender, EventArgs e) { - if (sender is null) - return; - - ComboBox cmb = (ComboBox)sender; - SetAuraMode(cmb.SelectedIndex); + Program.config.setConfig("aura_mode", (int)comboKeyboard.SelectedValue); + SetAura(); } + private void ComboKeyboardSpeed_SelectedValueChanged(object? sender, EventArgs e) + { + Program.config.setConfig("aura_speed", (int)comboKeyboardSpeed.SelectedValue); + SetAura(); + } + + private void Button120Hz_Click(object? sender, EventArgs e) { Program.config.setConfig("screen_auto", 0); @@ -1088,8 +1063,7 @@ namespace GHelper } - tableLayoutKeyboard.ColumnCount = 0; - tableLayoutMatrix.ColumnCount = 0; + //tableLayoutMatrix.ColumnCount = 0; }