From 1ebc2021f68e9fb820f3d243b472aca2e9593e51 Mon Sep 17 00:00:00 2001 From: seerge Date: Thu, 20 Apr 2023 14:53:37 +0200 Subject: [PATCH] KB Brightness control for TUF models --- app/ASUSWmi.cs | 7 ++++ app/Aura.cs | 15 ++++++++ app/GHelper.csproj | 2 +- app/Keyboard.Designer.cs | 79 ++++++++++++++++++++++++++-------------- app/Keyboard.cs | 12 +++++- app/Settings.Designer.cs | 4 +- app/Settings.cs | 3 -- 7 files changed, 87 insertions(+), 35 deletions(-) diff --git a/app/ASUSWmi.cs b/app/ASUSWmi.cs index 4ea27428..8f781511 100644 --- a/app/ASUSWmi.cs +++ b/app/ASUSWmi.cs @@ -48,6 +48,7 @@ public class ASUSWmi public const int PPT_APUC1 = 0x001200C1; // Actual Power Limit (PPT_LIMIT_FAST) AND Sustained Power Limit (STAPM_LIMIT) public const int PPT_APUC2 = 0x001200C2; // does nothing on G14 2022 + public const int TUF_KB_BRIGHTNESS = 0x00050021; public const int TUF_KB = 0x00100056; public const int TUF_KB_STATE = 0x00100057; @@ -260,6 +261,12 @@ public class ASUSWmi } + public void TUFKeyboardBrightness(int brightness) + { + int param = 0x80 | (brightness & 0x7F); + DeviceSet(TUF_KB_BRIGHTNESS, param, "TUF Brightness"); + } + public void TUFKeyboardRGB(int mode, Color color, int speed) { diff --git a/app/Aura.cs b/app/Aura.cs index 3dca693e..71729e63 100644 --- a/app/Aura.cs +++ b/app/Aura.cs @@ -1,5 +1,6 @@ using HidLibrary; using System.Diagnostics; +using static Starlight.AnimeMatrix.BuiltInAnimation; namespace GHelper { @@ -195,6 +196,9 @@ namespace GHelper } Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg)); + + if (Program.config.ContainsModel("TUF")) + Program.wmi.TUFKeyboardBrightness(brightness); } @@ -209,6 +213,17 @@ namespace GHelper if (sleep) flags.Add(AuraDev19b6.SleepKeyb); if (shutdown) flags.Add(AuraDev19b6.ShutdownKeyb); + flags.Add(AuraDev19b6.AwakeBar); + flags.Add(AuraDev19b6.BootBar); + flags.Add(AuraDev19b6.SleepBar); + flags.Add(AuraDev19b6.ShutdownBar); + + flags.Add(AuraDev19b6.AwakeLid); + flags.Add(AuraDev19b6.BootLid); + flags.Add(AuraDev19b6.SleepLid); + flags.Add(AuraDev19b6.ShutdownLid); + + byte[] msg = AuraDev19b6Extensions.ToBytes(flags.ToArray()); Debug.WriteLine(BitConverter.ToString(msg)); diff --git a/app/GHelper.csproj b/app/GHelper.csproj index f4fe00bb..f67ca863 100644 --- a/app/GHelper.csproj +++ b/app/GHelper.csproj @@ -16,7 +16,7 @@ x64 False True - 0.54 + 0.55 diff --git a/app/Keyboard.Designer.cs b/app/Keyboard.Designer.cs index 26d95b8c..dc88604f 100644 --- a/app/Keyboard.Designer.cs +++ b/app/Keyboard.Designer.cs @@ -31,6 +31,7 @@ namespace GHelper private void InitializeComponent() { groupBox1 = new GroupBox(); + pictureHelp = new PictureBox(); textFNF4 = new TextBox(); comboFNF4 = new RComboBox(); labelFNF4 = new Label(); @@ -41,6 +42,8 @@ namespace GHelper comboM3 = new RComboBox(); labelM3 = new Label(); groupLight = new GroupBox(); + labelBrightness = new Label(); + trackBrightness = new TrackBar(); labelSpeed = new Label(); comboKeyboardSpeed = new RComboBox(); checkShutdown = new CheckBox(); @@ -51,11 +54,11 @@ namespace GHelper checkNoOverdrive = new CheckBox(); checkKeyboardAuto = new CheckBox(); checkTopmost = new CheckBox(); - pictureHelp = new PictureBox(); groupBox1.SuspendLayout(); - groupLight.SuspendLayout(); - groupOther.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureHelp).BeginInit(); + groupLight.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)trackBrightness).BeginInit(); + groupOther.SuspendLayout(); SuspendLayout(); // // groupBox1 @@ -73,11 +76,22 @@ namespace GHelper groupBox1.Dock = DockStyle.Top; groupBox1.Location = new Point(10, 10); groupBox1.Name = "groupBox1"; - groupBox1.Size = new Size(810, 242); + groupBox1.Size = new Size(840, 242); groupBox1.TabIndex = 0; groupBox1.TabStop = false; groupBox1.Text = Properties.Strings.KeyBindings; // + // pictureHelp + // + pictureHelp.BackgroundImage = Properties.Resources.icons8_help_64; + pictureHelp.BackgroundImageLayout = ImageLayout.Zoom; + pictureHelp.Cursor = Cursors.Hand; + pictureHelp.Location = new Point(744, 57); + pictureHelp.Name = "pictureHelp"; + pictureHelp.Size = new Size(32, 32); + pictureHelp.TabIndex = 9; + pictureHelp.TabStop = false; + // // textFNF4 // textFNF4.Location = new Point(415, 176); @@ -88,12 +102,13 @@ namespace GHelper // // comboFNF4 // + comboFNF4.BorderColor = Color.White; + comboFNF4.ButtonColor = Color.FromArgb(255, 255, 255); comboFNF4.FormattingEnabled = true; comboFNF4.Location = new Point(93, 175); comboFNF4.Name = "comboFNF4"; comboFNF4.Size = new Size(312, 40); comboFNF4.TabIndex = 7; - comboFNF4.BorderColor = Color.White; // // labelFNF4 // @@ -122,14 +137,14 @@ namespace GHelper // // comboM4 // + comboM4.BorderColor = Color.White; + comboM4.ButtonColor = Color.FromArgb(255, 255, 255); comboM4.FormattingEnabled = true; comboM4.Items.AddRange(new object[] { Properties.Strings.PerformanceMode, Properties.Strings.OpenGHelper, Properties.Strings.Custom }); comboM4.Location = new Point(93, 112); comboM4.Name = "comboM4"; comboM4.Size = new Size(312, 40); comboM4.TabIndex = 3; - comboM4.BorderColor = Color.White; - // // labelM4 // @@ -142,14 +157,14 @@ namespace GHelper // // comboM3 // + comboM3.BorderColor = Color.White; + comboM3.ButtonColor = Color.FromArgb(255, 255, 255); comboM3.FormattingEnabled = true; comboM3.Items.AddRange(new object[] { Properties.Strings.Default, Properties.Strings.VolumeMute, Properties.Strings.PlayPause, Properties.Strings.PrintScreen, Properties.Strings.ToggleAura, Properties.Strings.Custom }); comboM3.Location = new Point(93, 54); comboM3.Name = "comboM3"; comboM3.Size = new Size(312, 40); comboM3.TabIndex = 1; - comboM3.BorderColor = Color.White; - // // labelM3 // @@ -162,6 +177,8 @@ namespace GHelper // // groupLight // + groupLight.Controls.Add(labelBrightness); + groupLight.Controls.Add(trackBrightness); groupLight.Controls.Add(labelSpeed); groupLight.Controls.Add(comboKeyboardSpeed); groupLight.Controls.Add(checkShutdown); @@ -171,15 +188,30 @@ namespace GHelper groupLight.Dock = DockStyle.Top; groupLight.Location = new Point(10, 252); groupLight.Name = "groupLight"; - groupLight.Size = new Size(810, 320); + groupLight.Size = new Size(840, 374); groupLight.TabIndex = 1; groupLight.TabStop = false; groupLight.Text = Properties.Strings.KeyboardBacklight; // + // labelBrightness + // + labelBrightness.Location = new Point(25, 284); + labelBrightness.Name = "labelBrightness"; + labelBrightness.Size = new Size(197, 49); + labelBrightness.TabIndex = 0; + labelBrightness.Text = "Brightness"; + // + // trackBrightness + // + trackBrightness.Location = new Point(228, 284); + trackBrightness.Name = "trackBrightness"; + trackBrightness.Size = new Size(612, 90); + trackBrightness.TabIndex = 1; + // // labelSpeed // labelSpeed.AutoSize = true; - labelSpeed.Location = new Point(25, 237); + labelSpeed.Location = new Point(25, 235); labelSpeed.MaximumSize = new Size(200, 0); labelSpeed.Name = "labelSpeed"; labelSpeed.Size = new Size(198, 32); @@ -195,7 +227,7 @@ namespace GHelper comboKeyboardSpeed.FormattingEnabled = true; comboKeyboardSpeed.ItemHeight = 32; comboKeyboardSpeed.Items.AddRange(new object[] { "Slow", "Normal", "Fast" }); - comboKeyboardSpeed.Location = new Point(230, 234); + comboKeyboardSpeed.Location = new Point(230, 232); comboKeyboardSpeed.Margin = new Padding(4, 10, 4, 8); comboKeyboardSpeed.Name = "comboKeyboardSpeed"; comboKeyboardSpeed.Size = new Size(291, 40); @@ -248,9 +280,9 @@ namespace GHelper groupOther.Controls.Add(checkKeyboardAuto); groupOther.Controls.Add(checkTopmost); groupOther.Dock = DockStyle.Top; - groupOther.Location = new Point(10, 572); + groupOther.Location = new Point(10, 626); groupOther.Name = "groupOther"; - groupOther.Size = new Size(810, 225); + groupOther.Size = new Size(840, 225); groupOther.TabIndex = 2; groupOther.TabStop = false; groupOther.Text = Properties.Strings.Other; @@ -267,7 +299,6 @@ namespace GHelper // // checkKeyboardAuto // - checkKeyboardAuto.AutoEllipsis = true; checkKeyboardAuto.AutoSize = true; checkKeyboardAuto.Location = new Point(25, 51); checkKeyboardAuto.MaximumSize = new Size(780, 0); @@ -287,22 +318,11 @@ namespace GHelper checkTopmost.Text = Properties.Strings.WindowTop; checkTopmost.UseVisualStyleBackColor = true; // - // pictureHelp - // - pictureHelp.BackgroundImageLayout = ImageLayout.Zoom; - pictureHelp.Cursor = Cursors.Hand; - pictureHelp.BackgroundImage = Properties.Resources.icons8_help_64; - pictureHelp.Location = new Point(744, 57); - pictureHelp.Name = "pictureHelp"; - pictureHelp.Size = new Size(32, 32); - pictureHelp.TabIndex = 9; - pictureHelp.TabStop = false; - // // Keyboard // AutoScaleDimensions = new SizeF(13F, 32F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(830, 858); + ClientSize = new Size(860, 890); Controls.Add(groupOther); Controls.Add(groupLight); Controls.Add(groupBox1); @@ -317,11 +337,12 @@ namespace GHelper Text = Properties.Strings.ExtraSettings; groupBox1.ResumeLayout(false); groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureHelp).EndInit(); groupLight.ResumeLayout(false); groupLight.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)trackBrightness).EndInit(); groupOther.ResumeLayout(false); groupOther.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)pictureHelp).EndInit(); ResumeLayout(false); } @@ -349,5 +370,7 @@ namespace GHelper private CheckBox checkKeyboardAuto; private CheckBox checkNoOverdrive; private PictureBox pictureHelp; + private TrackBar trackBrightness; + private Label labelBrightness; } } \ No newline at end of file diff --git a/app/Keyboard.cs b/app/Keyboard.cs index 6bde429b..cbf82f91 100644 --- a/app/Keyboard.cs +++ b/app/Keyboard.cs @@ -88,8 +88,18 @@ namespace GHelper checkNoOverdrive.Checked = (Program.config.getConfig("no_overdrive") == 1); checkNoOverdrive.CheckedChanged += CheckNoOverdrive_CheckedChanged; - pictureHelp.Click += PictureHelp_Click; + int kb_brightness = Program.config.getConfig("keyboard_brightness"); + trackBrightness.Value = (kb_brightness >= 0 && kb_brightness <= 3) ? kb_brightness : 3; + pictureHelp.Click += PictureHelp_Click; + trackBrightness.Scroll += TrackBrightness_Scroll; + + } + + private void TrackBrightness_Scroll(object? sender, EventArgs e) + { + Program.config.setConfig("keyboard_brightness", trackBrightness.Value); + Aura.ApplyBrightness(trackBrightness.Value); } private void PictureHelp_Click(object? sender, EventArgs e) diff --git a/app/Settings.Designer.cs b/app/Settings.Designer.cs index 5d88c4e7..53202484 100644 --- a/app/Settings.Designer.cs +++ b/app/Settings.Designer.cs @@ -596,9 +596,9 @@ namespace GHelper tableGPU.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); tableGPU.Controls.Add(buttonEco, 0, 0); tableGPU.Controls.Add(buttonStandard, 1, 0); + tableGPU.Controls.Add(buttonXGM, 2, 0); + tableGPU.Controls.Add(buttonOptimized, 2, 0); tableGPU.Controls.Add(buttonUltimate, 2, 0); - tableGPU.Controls.Add(buttonXGM, 3, 0); - tableGPU.Controls.Add(buttonOptimized, 3, 0); tableGPU.Location = new Point(16, 60); tableGPU.Margin = new Padding(8, 4, 8, 4); tableGPU.Name = "tableGPU"; diff --git a/app/Settings.cs b/app/Settings.cs index 67c88fee..fd1d58f8 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -1181,10 +1181,7 @@ namespace GHelper tableScreen.ColumnCount = 0; } - //tableLayoutMatrix.ColumnCount = 0; - - } public void InitXGM()