From 57c893ef77b54ff752983ff669ecc80262be66c7 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Mon, 8 May 2023 19:33:49 +0200 Subject: [PATCH 1/3] XGMobile backlight control --- app/Aura.cs | 17 ++ app/Extra.Designer.cs | 445 +++++++++++++++++++++++------------------- app/Extra.cs | 24 ++- 3 files changed, 276 insertions(+), 210 deletions(-) diff --git a/app/Aura.cs b/app/Aura.cs index bc7acc24..3921a441 100644 --- a/app/Aura.cs +++ b/app/Aura.cs @@ -1,4 +1,5 @@ using HidLibrary; +using OSD; using System.Diagnostics; namespace GHelper @@ -235,6 +236,22 @@ namespace GHelper } + public static void ApplyXGMLight(bool status) + { + byte value = status? (byte)0x50:(byte)0; + var msg = new byte[] { 0x5e, 0xc5, value }; + + foreach (HidDevice device in GetHidDevices(new int[] { 0x1970 })) + { + device.OpenDevice(); + var message = new byte[300]; + Array.Copy(msg, message, msg.Length); + Debug.WriteLine(BitConverter.ToString(message)); + device.WriteFeatureData(message); + device.CloseDevice(); + } + } + public static void ApplyAura() { diff --git a/app/Extra.Designer.cs b/app/Extra.Designer.cs index e4859d78..79cd7db8 100644 --- a/app/Extra.Designer.cs +++ b/app/Extra.Designer.cs @@ -43,31 +43,34 @@ namespace GHelper comboM3 = new RComboBox(); labelM3 = new Label(); groupLight = new GroupBox(); + panelBacklightExtra = new Panel(); + labelBrightness = new Label(); + trackBrightness = new TrackBar(); + labelSpeed = new Label(); + comboKeyboardSpeed = new RComboBox(); + panelXMG = new Panel(); + checkXMG = new CheckBox(); tableBacklight = new TableLayoutPanel(); - checkBootLid = new CheckBox(); - checkShutdown = new CheckBox(); + labelBacklight = new Label(); checkAwake = new CheckBox(); checkBoot = new CheckBox(); checkSleep = new CheckBox(); - labelBacklight = new Label(); - checkSleepBar = new CheckBox(); - checkShutdownBar = new CheckBox(); - labelBacklightBar = new Label(); - checkAwakeBar = new CheckBox(); - checkBootBar = new CheckBox(); - checkSleepLid = new CheckBox(); - checkShutdownLid = new CheckBox(); - labelBacklightLid = new Label(); - checkAwakeLid = new CheckBox(); + checkShutdown = new CheckBox(); labelBacklightLogo = new Label(); checkAwakeLogo = new CheckBox(); checkBootLogo = new CheckBox(); checkSleepLogo = new CheckBox(); checkShutdownLogo = new CheckBox(); - labelBrightness = new Label(); - trackBrightness = new TrackBar(); - labelSpeed = new Label(); - comboKeyboardSpeed = new RComboBox(); + labelBacklightBar = new Label(); + checkAwakeBar = new CheckBox(); + checkBootBar = new CheckBox(); + checkSleepBar = new CheckBox(); + checkShutdownBar = new CheckBox(); + labelBacklightLid = new Label(); + checkAwakeLid = new CheckBox(); + checkBootLid = new CheckBox(); + checkSleepLid = new CheckBox(); + checkShutdownLid = new CheckBox(); groupOther = new GroupBox(); checkUSBC = new CheckBox(); checkNoOverdrive = new CheckBox(); @@ -76,8 +79,10 @@ namespace GHelper groupBindings.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureHelp).BeginInit(); groupLight.SuspendLayout(); - tableBacklight.SuspendLayout(); + panelBacklightExtra.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)trackBrightness).BeginInit(); + panelXMG.SuspendLayout(); + tableBacklight.SuspendLayout(); groupOther.SuspendLayout(); SuspendLayout(); // @@ -197,19 +202,94 @@ namespace GHelper // // groupLight // + groupLight.AutoSize = true; + groupLight.Controls.Add(panelBacklightExtra); + groupLight.Controls.Add(panelXMG); groupLight.Controls.Add(tableBacklight); - groupLight.Controls.Add(labelBrightness); - groupLight.Controls.Add(trackBrightness); - groupLight.Controls.Add(labelSpeed); - groupLight.Controls.Add(comboKeyboardSpeed); groupLight.Dock = DockStyle.Top; groupLight.Location = new Point(10, 252); groupLight.Name = "groupLight"; - groupLight.Size = new Size(848, 444); + groupLight.Size = new Size(848, 475); groupLight.TabIndex = 1; groupLight.TabStop = false; groupLight.Text = "Keyboard Backlight"; // + // panelBacklightExtra + // + panelBacklightExtra.AutoSize = true; + panelBacklightExtra.Controls.Add(labelBrightness); + panelBacklightExtra.Controls.Add(trackBrightness); + panelBacklightExtra.Controls.Add(labelSpeed); + panelBacklightExtra.Controls.Add(comboKeyboardSpeed); + panelBacklightExtra.Dock = DockStyle.Top; + panelBacklightExtra.Location = new Point(3, 319); + panelBacklightExtra.Name = "panelBacklightExtra"; + panelBacklightExtra.Size = new Size(842, 153); + panelBacklightExtra.TabIndex = 43; + // + // labelBrightness + // + labelBrightness.Location = new Point(13, 76); + labelBrightness.Name = "labelBrightness"; + labelBrightness.Size = new Size(197, 49); + labelBrightness.TabIndex = 41; + labelBrightness.Text = "Brightness"; + // + // trackBrightness + // + trackBrightness.Location = new Point(216, 60); + trackBrightness.Maximum = 3; + trackBrightness.Name = "trackBrightness"; + trackBrightness.Size = new Size(600, 90); + trackBrightness.TabIndex = 42; + trackBrightness.TickStyle = TickStyle.TopLeft; + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(13, 15); + labelSpeed.MaximumSize = new Size(200, 0); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(198, 32); + labelSpeed.TabIndex = 44; + labelSpeed.Text = "Animation Speed"; + // + // comboKeyboardSpeed + // + comboKeyboardSpeed.BorderColor = Color.White; + comboKeyboardSpeed.ButtonColor = SystemColors.ControlLight; + 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(220, 12); + comboKeyboardSpeed.Margin = new Padding(4, 10, 4, 8); + comboKeyboardSpeed.Name = "comboKeyboardSpeed"; + comboKeyboardSpeed.Size = new Size(291, 40); + comboKeyboardSpeed.TabIndex = 43; + comboKeyboardSpeed.TabStop = false; + // + // panelXMG + // + panelXMG.Controls.Add(checkXMG); + panelXMG.Dock = DockStyle.Top; + panelXMG.Location = new Point(3, 261); + panelXMG.Name = "panelXMG"; + panelXMG.Size = new Size(842, 58); + panelXMG.TabIndex = 42; + // + // checkXMG + // + checkXMG.AutoSize = true; + checkXMG.Location = new Point(3, 10); + checkXMG.Name = "checkXMG"; + checkXMG.Padding = new Padding(15, 2, 5, 2); + checkXMG.Size = new Size(178, 40); + checkXMG.TabIndex = 2; + checkXMG.Text = "XG Mobile"; + checkXMG.UseVisualStyleBackColor = true; + // // tableBacklight // tableBacklight.AutoSize = true; @@ -218,32 +298,26 @@ namespace GHelper tableBacklight.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); tableBacklight.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); tableBacklight.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F)); - tableBacklight.Controls.Add(labelBacklight, 0, 0); tableBacklight.Controls.Add(checkAwake, 0, 1); tableBacklight.Controls.Add(checkBoot, 0, 2); tableBacklight.Controls.Add(checkSleep, 0, 3); tableBacklight.Controls.Add(checkShutdown, 0, 4); - tableBacklight.Controls.Add(labelBacklightLogo, 1, 0); tableBacklight.Controls.Add(checkAwakeLogo, 1, 1); tableBacklight.Controls.Add(checkBootLogo, 1, 2); tableBacklight.Controls.Add(checkSleepLogo, 1, 3); tableBacklight.Controls.Add(checkShutdownLogo, 1, 4); - tableBacklight.Controls.Add(labelBacklightBar, 2, 0); tableBacklight.Controls.Add(checkAwakeBar, 2, 1); tableBacklight.Controls.Add(checkBootBar, 2, 2); tableBacklight.Controls.Add(checkSleepBar, 2, 3); tableBacklight.Controls.Add(checkShutdownBar, 2, 4); - tableBacklight.Controls.Add(labelBacklightLid, 3, 0); tableBacklight.Controls.Add(checkAwakeLid, 3, 1); tableBacklight.Controls.Add(checkBootLid, 3, 2); tableBacklight.Controls.Add(checkSleepLid, 3, 3); tableBacklight.Controls.Add(checkShutdownLid, 3, 4); - - tableBacklight.Dock = DockStyle.Top; tableBacklight.Location = new Point(3, 35); tableBacklight.Margin = new Padding(0); @@ -257,27 +331,16 @@ namespace GHelper tableBacklight.Size = new Size(842, 226); tableBacklight.TabIndex = 41; // - // checkBootLid + // labelBacklight // - checkBootLid.AutoSize = true; - checkBootLid.Location = new Point(423, 91); - checkBootLid.Name = "checkBootLid"; - checkBootLid.Padding = new Padding(15, 2, 5, 2); - checkBootLid.Size = new Size(116, 40); - checkBootLid.TabIndex = 13; - checkBootLid.Text = Strings.Boot; - checkBootLid.UseVisualStyleBackColor = true; - // - // checkShutdown - // - checkShutdown.AutoSize = true; - checkShutdown.Location = new Point(3, 183); - checkShutdown.Name = "checkShutdown"; - checkShutdown.Padding = new Padding(15, 2, 5, 2); - checkShutdown.Size = new Size(174, 40); - checkShutdown.TabIndex = 4; - checkShutdown.Text = Strings.Shutdown; - checkShutdown.UseVisualStyleBackColor = true; + labelBacklight.AutoSize = true; + labelBacklight.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); + labelBacklight.Location = new Point(3, 0); + labelBacklight.Name = "labelBacklight"; + labelBacklight.Padding = new Padding(10, 5, 5, 5); + labelBacklight.Size = new Size(139, 42); + labelBacklight.TabIndex = 6; + labelBacklight.Text = "Keyboard"; // // checkAwake // @@ -312,121 +375,22 @@ namespace GHelper checkSleep.Text = Strings.Sleep; checkSleep.UseVisualStyleBackColor = true; // - // labelBacklight + // checkShutdown // - labelBacklight.AutoSize = true; - labelBacklight.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); - labelBacklight.Location = new Point(3, 0); - labelBacklight.Name = "labelBacklight"; - labelBacklight.Padding = new Padding(10, 5, 5, 5); - labelBacklight.Size = new Size(139, 42); - labelBacklight.TabIndex = 6; - labelBacklight.Text = "Keyboard"; - // - // checkSleepBar - // - checkSleepBar.AutoSize = true; - checkSleepBar.Location = new Point(213, 137); - checkSleepBar.Name = "checkSleepBar"; - checkSleepBar.Padding = new Padding(15, 2, 5, 2); - checkSleepBar.Size = new Size(125, 40); - checkSleepBar.TabIndex = 9; - checkSleepBar.Text = Strings.Sleep; - checkSleepBar.UseVisualStyleBackColor = true; - // - // checkShutdownBar - // - checkShutdownBar.AutoSize = true; - checkShutdownBar.Location = new Point(213, 183); - checkShutdownBar.Name = "checkShutdownBar"; - checkShutdownBar.Padding = new Padding(15, 2, 5, 2); - checkShutdownBar.Size = new Size(174, 40); - checkShutdownBar.TabIndex = 10; - checkShutdownBar.Text = Strings.Shutdown; - checkShutdownBar.UseVisualStyleBackColor = true; - // - // labelBacklightBar - // - labelBacklightBar.AutoSize = true; - labelBacklightBar.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); - labelBacklightBar.Location = new Point(213, 0); - labelBacklightBar.Name = "labelBacklightBar"; - labelBacklightBar.Padding = new Padding(10, 5, 5, 5); - labelBacklightBar.Size = new Size(124, 42); - labelBacklightBar.TabIndex = 11; - labelBacklightBar.Text = "Lightbar"; - // - // checkAwakeBar - // - checkAwakeBar.AutoSize = true; - checkAwakeBar.Location = new Point(213, 45); - checkAwakeBar.Name = "checkAwakeBar"; - checkAwakeBar.Padding = new Padding(15, 2, 5, 2); - checkAwakeBar.Size = new Size(135, 40); - checkAwakeBar.TabIndex = 7; - checkAwakeBar.Text = Strings.Awake; - checkAwakeBar.UseVisualStyleBackColor = true; - // - // checkBootBar - // - checkBootBar.AutoSize = true; - checkBootBar.Location = new Point(213, 91); - checkBootBar.Name = "checkBootBar"; - checkBootBar.Padding = new Padding(15, 2, 5, 2); - checkBootBar.Size = new Size(116, 40); - checkBootBar.TabIndex = 8; - checkBootBar.Text = Strings.Boot; - checkBootBar.UseVisualStyleBackColor = true; - // - // checkSleepLid - // - checkSleepLid.AutoSize = true; - checkSleepLid.Location = new Point(423, 137); - checkSleepLid.Name = "checkSleepLid"; - checkSleepLid.Padding = new Padding(15, 2, 5, 2); - checkSleepLid.Size = new Size(125, 40); - checkSleepLid.TabIndex = 14; - checkSleepLid.Text = Strings.Sleep; - checkSleepLid.UseVisualStyleBackColor = true; - // - // checkShutdownLid - // - checkShutdownLid.AutoSize = true; - checkShutdownLid.Location = new Point(423, 183); - checkShutdownLid.Name = "checkShutdownLid"; - checkShutdownLid.Padding = new Padding(15, 2, 5, 2); - checkShutdownLid.Size = new Size(174, 40); - checkShutdownLid.TabIndex = 15; - checkShutdownLid.Text = Strings.Shutdown; - checkShutdownLid.UseVisualStyleBackColor = true; - // - // labelBacklightLid - // - labelBacklightLid.AutoSize = true; - labelBacklightLid.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); - labelBacklightLid.Location = new Point(423, 0); - labelBacklightLid.Name = "labelBacklightLid"; - labelBacklightLid.Padding = new Padding(10, 5, 5, 5); - labelBacklightLid.Size = new Size(63, 42); - labelBacklightLid.TabIndex = 16; - labelBacklightLid.Text = "Lid"; - // - // checkAwakeLid - // - checkAwakeLid.AutoSize = true; - checkAwakeLid.Location = new Point(423, 45); - checkAwakeLid.Name = "checkAwakeLid"; - checkAwakeLid.Padding = new Padding(15, 2, 5, 2); - checkAwakeLid.Size = new Size(135, 40); - checkAwakeLid.TabIndex = 12; - checkAwakeLid.Text = Strings.Awake; - checkAwakeLid.UseVisualStyleBackColor = true; + checkShutdown.AutoSize = true; + checkShutdown.Location = new Point(3, 183); + checkShutdown.Name = "checkShutdown"; + checkShutdown.Padding = new Padding(15, 2, 5, 2); + checkShutdown.Size = new Size(174, 40); + checkShutdown.TabIndex = 4; + checkShutdown.Text = Strings.Shutdown; + checkShutdown.UseVisualStyleBackColor = true; // // labelBacklightLogo // labelBacklightLogo.AutoSize = true; labelBacklightLogo.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); - labelBacklightLogo.Location = new Point(633, 0); + labelBacklightLogo.Location = new Point(213, 0); labelBacklightLogo.Name = "labelBacklightLogo"; labelBacklightLogo.Padding = new Padding(10, 5, 5, 5); labelBacklightLogo.Size = new Size(86, 42); @@ -436,7 +400,7 @@ namespace GHelper // checkAwakeLogo // checkAwakeLogo.AutoSize = true; - checkAwakeLogo.Location = new Point(633, 45); + checkAwakeLogo.Location = new Point(213, 45); checkAwakeLogo.Name = "checkAwakeLogo"; checkAwakeLogo.Padding = new Padding(15, 2, 5, 2); checkAwakeLogo.Size = new Size(135, 40); @@ -447,7 +411,7 @@ namespace GHelper // checkBootLogo // checkBootLogo.AutoSize = true; - checkBootLogo.Location = new Point(633, 91); + checkBootLogo.Location = new Point(213, 91); checkBootLogo.Name = "checkBootLogo"; checkBootLogo.Padding = new Padding(15, 2, 5, 2); checkBootLogo.Size = new Size(116, 40); @@ -458,7 +422,7 @@ namespace GHelper // checkSleepLogo // checkSleepLogo.AutoSize = true; - checkSleepLogo.Location = new Point(633, 137); + checkSleepLogo.Location = new Point(213, 137); checkSleepLogo.Name = "checkSleepLogo"; checkSleepLogo.Padding = new Padding(15, 2, 5, 2); checkSleepLogo.Size = new Size(125, 40); @@ -469,7 +433,7 @@ namespace GHelper // checkShutdownLogo // checkShutdownLogo.AutoSize = true; - checkShutdownLogo.Location = new Point(633, 183); + checkShutdownLogo.Location = new Point(213, 183); checkShutdownLogo.Name = "checkShutdownLogo"; checkShutdownLogo.Padding = new Padding(15, 2, 5, 2); checkShutdownLogo.Size = new Size(174, 40); @@ -477,48 +441,115 @@ namespace GHelper checkShutdownLogo.Text = Strings.Shutdown; checkShutdownLogo.UseVisualStyleBackColor = true; // - // labelBrightness + // labelBacklightBar // - labelBrightness.Location = new Point(15, 357); - labelBrightness.Name = "labelBrightness"; - labelBrightness.Size = new Size(197, 49); - labelBrightness.TabIndex = 0; - labelBrightness.Text = "Brightness"; + labelBacklightBar.AutoSize = true; + labelBacklightBar.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); + labelBacklightBar.Location = new Point(423, 0); + labelBacklightBar.Name = "labelBacklightBar"; + labelBacklightBar.Padding = new Padding(10, 5, 5, 5); + labelBacklightBar.Size = new Size(124, 42); + labelBacklightBar.TabIndex = 11; + labelBacklightBar.Text = "Lightbar"; // - // trackBrightness + // checkAwakeBar // - trackBrightness.Location = new Point(218, 341); - trackBrightness.Maximum = 3; - trackBrightness.Name = "trackBrightness"; - trackBrightness.Size = new Size(600, 90); - trackBrightness.TabIndex = 1; - trackBrightness.TickStyle = TickStyle.TopLeft; + checkAwakeBar.AutoSize = true; + checkAwakeBar.Location = new Point(423, 45); + checkAwakeBar.Name = "checkAwakeBar"; + checkAwakeBar.Padding = new Padding(15, 2, 5, 2); + checkAwakeBar.Size = new Size(135, 40); + checkAwakeBar.TabIndex = 7; + checkAwakeBar.Text = Strings.Awake; + checkAwakeBar.UseVisualStyleBackColor = true; // - // labelSpeed + // checkBootBar // - labelSpeed.AutoSize = true; - labelSpeed.Location = new Point(15, 296); - labelSpeed.MaximumSize = new Size(200, 0); - labelSpeed.Name = "labelSpeed"; - labelSpeed.Size = new Size(198, 32); - labelSpeed.TabIndex = 40; - labelSpeed.Text = "Animation Speed"; + checkBootBar.AutoSize = true; + checkBootBar.Location = new Point(423, 91); + checkBootBar.Name = "checkBootBar"; + checkBootBar.Padding = new Padding(15, 2, 5, 2); + checkBootBar.Size = new Size(116, 40); + checkBootBar.TabIndex = 8; + checkBootBar.Text = Strings.Boot; + checkBootBar.UseVisualStyleBackColor = true; // - // comboKeyboardSpeed + // checkSleepBar // - comboKeyboardSpeed.BorderColor = Color.White; - comboKeyboardSpeed.ButtonColor = SystemColors.ControlLight; - 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(222, 293); - comboKeyboardSpeed.Margin = new Padding(4, 10, 4, 8); - comboKeyboardSpeed.Name = "comboKeyboardSpeed"; - comboKeyboardSpeed.Size = new Size(291, 40); - comboKeyboardSpeed.TabIndex = 39; - comboKeyboardSpeed.TabStop = false; + checkSleepBar.AutoSize = true; + checkSleepBar.Location = new Point(423, 137); + checkSleepBar.Name = "checkSleepBar"; + checkSleepBar.Padding = new Padding(15, 2, 5, 2); + checkSleepBar.Size = new Size(125, 40); + checkSleepBar.TabIndex = 9; + checkSleepBar.Text = Strings.Sleep; + checkSleepBar.UseVisualStyleBackColor = true; + // + // checkShutdownBar + // + checkShutdownBar.AutoSize = true; + checkShutdownBar.Location = new Point(423, 183); + checkShutdownBar.Name = "checkShutdownBar"; + checkShutdownBar.Padding = new Padding(15, 2, 5, 2); + checkShutdownBar.Size = new Size(174, 40); + checkShutdownBar.TabIndex = 10; + checkShutdownBar.Text = Strings.Shutdown; + checkShutdownBar.UseVisualStyleBackColor = true; + // + // labelBacklightLid + // + labelBacklightLid.AutoSize = true; + labelBacklightLid.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); + labelBacklightLid.Location = new Point(633, 0); + labelBacklightLid.Name = "labelBacklightLid"; + labelBacklightLid.Padding = new Padding(10, 5, 5, 5); + labelBacklightLid.Size = new Size(63, 42); + labelBacklightLid.TabIndex = 16; + labelBacklightLid.Text = "Lid"; + // + // checkAwakeLid + // + checkAwakeLid.AutoSize = true; + checkAwakeLid.Location = new Point(633, 45); + checkAwakeLid.Name = "checkAwakeLid"; + checkAwakeLid.Padding = new Padding(15, 2, 5, 2); + checkAwakeLid.Size = new Size(135, 40); + checkAwakeLid.TabIndex = 12; + checkAwakeLid.Text = Strings.Awake; + checkAwakeLid.UseVisualStyleBackColor = true; + // + // checkBootLid + // + checkBootLid.AutoSize = true; + checkBootLid.Location = new Point(633, 91); + checkBootLid.Name = "checkBootLid"; + checkBootLid.Padding = new Padding(15, 2, 5, 2); + checkBootLid.Size = new Size(116, 40); + checkBootLid.TabIndex = 13; + checkBootLid.Text = Strings.Boot; + checkBootLid.UseVisualStyleBackColor = true; + // + // checkSleepLid + // + checkSleepLid.AutoSize = true; + checkSleepLid.Location = new Point(633, 137); + checkSleepLid.Name = "checkSleepLid"; + checkSleepLid.Padding = new Padding(15, 2, 5, 2); + checkSleepLid.Size = new Size(125, 40); + checkSleepLid.TabIndex = 14; + checkSleepLid.Text = Strings.Sleep; + checkSleepLid.UseVisualStyleBackColor = true; + // + // checkShutdownLid + // + checkShutdownLid.AutoSize = true; + checkShutdownLid.Location = new Point(633, 183); + checkShutdownLid.Name = "checkShutdownLid"; + checkShutdownLid.Padding = new Padding(15, 2, 5, 2); + checkShutdownLid.Size = new Size(174, 40); + checkShutdownLid.TabIndex = 15; + checkShutdownLid.Text = Strings.Shutdown; + checkShutdownLid.UseVisualStyleBackColor = true; // // groupOther // @@ -527,7 +558,7 @@ namespace GHelper groupOther.Controls.Add(checkKeyboardAuto); groupOther.Controls.Add(checkTopmost); groupOther.Dock = DockStyle.Top; - groupOther.Location = new Point(10, 696); + groupOther.Location = new Point(10, 727); groupOther.Name = "groupOther"; groupOther.Size = new Size(848, 293); groupOther.TabIndex = 2; @@ -557,7 +588,7 @@ namespace GHelper // checkKeyboardAuto // checkKeyboardAuto.AutoSize = true; - checkKeyboardAuto.Location = new Point(25, 51); + checkKeyboardAuto.Location = new Point(25, 52); checkKeyboardAuto.MaximumSize = new Size(780, 0); checkKeyboardAuto.Name = "checkKeyboardAuto"; checkKeyboardAuto.Size = new Size(712, 36); @@ -597,12 +628,17 @@ namespace GHelper ((System.ComponentModel.ISupportInitialize)pictureHelp).EndInit(); groupLight.ResumeLayout(false); groupLight.PerformLayout(); + panelBacklightExtra.ResumeLayout(false); + panelBacklightExtra.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)trackBrightness).EndInit(); + panelXMG.ResumeLayout(false); + panelXMG.PerformLayout(); tableBacklight.ResumeLayout(false); tableBacklight.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)trackBrightness).EndInit(); groupOther.ResumeLayout(false); groupOther.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion @@ -618,15 +654,11 @@ namespace GHelper private RComboBox comboFNF4; private Label labelFNF4; private GroupBox groupLight; - private Label labelSpeed; - private RComboBox comboKeyboardSpeed; private GroupBox groupOther; private CheckBox checkTopmost; private CheckBox checkKeyboardAuto; private CheckBox checkNoOverdrive; private PictureBox pictureHelp; - private TrackBar trackBrightness; - private Label labelBrightness; private CheckBox checkUSBC; private TableLayoutPanel tableBacklight; private CheckBox checkShutdown; @@ -649,5 +681,12 @@ namespace GHelper private CheckBox checkBootLogo; private CheckBox checkSleepLogo; private CheckBox checkShutdownLogo; + private Panel panelBacklightExtra; + private Label labelBrightness; + private TrackBar trackBrightness; + private Label labelSpeed; + private RComboBox comboKeyboardSpeed; + private Panel panelXMG; + private CheckBox checkXMG; } } \ No newline at end of file diff --git a/app/Extra.cs b/app/Extra.cs index fac5286a..b37b8932 100644 --- a/app/Extra.cs +++ b/app/Extra.cs @@ -148,21 +148,20 @@ namespace GHelper checkSleepBar.Visible = false; checkShutdownBar.Visible = false; - labelBacklightLid.Visible = false; - checkAwakeLid.Visible = false; - checkBootLid.Visible = false; - checkSleepLid.Visible = false; - checkShutdownLid.Visible = false; - if (!Program.config.ContainsModel("Z13")) { + labelBacklightLid.Visible = false; + checkAwakeLid.Visible = false; + checkBootLid.Visible = false; + checkSleepLid.Visible = false; + checkShutdownLid.Visible = false; + labelBacklightLogo.Visible = false; checkAwakeLogo.Visible = false; checkBootLogo.Visible = false; checkSleepLogo.Visible = false; checkShutdownLogo.Visible = false; } - } checkTopmost.Checked = (Program.config.getConfig("topmost") == 1); @@ -183,6 +182,17 @@ namespace GHelper pictureHelp.Click += PictureHelp_Click; trackBrightness.Scroll += TrackBrightness_Scroll; + panelXMG.Visible = (Program.wmi.DeviceGet(ASUSWmi.GPUXGConnected) == 1); + checkXMG.Checked = !(Program.config.getConfig("xmg_light") == 0); + checkXMG.CheckedChanged += CheckXMG_CheckedChanged; + + + } + + private void CheckXMG_CheckedChanged(object? sender, EventArgs e) + { + Program.config.setConfig("xmg_light", (checkXMG.Checked ? 1 : 0)); + Aura.ApplyXGMLight(checkXMG.Checked); } private void CheckUSBC_CheckedChanged(object? sender, EventArgs e) From a4488fa93b87265de4f0b46f19d7c788eb1de41f Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Tue, 9 May 2023 14:29:52 +0200 Subject: [PATCH 2/3] GPU Settings will be saved and auto-applied for each mode --- app/Fans.Designer.cs | 38 ++++++++++++++-------------- app/Fans.cs | 59 ++++++++++++++++---------------------------- app/Program.cs | 10 ++++++-- app/Settings.cs | 51 +++++++++++++++++++++++++++----------- app/Startup.cs | 9 +++++++ 5 files changed, 94 insertions(+), 73 deletions(-) diff --git a/app/Fans.Designer.cs b/app/Fans.Designer.cs index cce18163..cf092519 100644 --- a/app/Fans.Designer.cs +++ b/app/Fans.Designer.cs @@ -31,12 +31,12 @@ namespace GHelper /// private void InitializeComponent() { - ChartArea chartArea4 = new ChartArea(); - Title title4 = new Title(); - ChartArea chartArea5 = new ChartArea(); - Title title5 = new Title(); - ChartArea chartArea6 = new ChartArea(); - Title title6 = new Title(); + ChartArea chartArea1 = new ChartArea(); + Title title1 = new Title(); + ChartArea chartArea2 = new ChartArea(); + Title title2 = new Title(); + ChartArea chartArea3 = new ChartArea(); + Title title3 = new Title(); panelFans = new Panel(); labelFansResult = new Label(); labelTip = new Label(); @@ -211,8 +211,8 @@ namespace GHelper // // chartGPU // - chartArea4.Name = "ChartArea1"; - chartGPU.ChartAreas.Add(chartArea4); + chartArea1.Name = "ChartArea1"; + chartGPU.ChartAreas.Add(chartArea1); chartGPU.Dock = DockStyle.Fill; chartGPU.Location = new Point(2, 350); chartGPU.Margin = new Padding(2, 10, 2, 10); @@ -220,13 +220,13 @@ namespace GHelper chartGPU.Size = new Size(760, 320); chartGPU.TabIndex = 17; chartGPU.Text = "chartGPU"; - title4.Name = "Title1"; - chartGPU.Titles.Add(title4); + title1.Name = "Title1"; + chartGPU.Titles.Add(title1); // // chartCPU // - chartArea5.Name = "ChartArea1"; - chartCPU.ChartAreas.Add(chartArea5); + chartArea2.Name = "ChartArea1"; + chartCPU.ChartAreas.Add(chartArea2); chartCPU.Dock = DockStyle.Fill; chartCPU.Location = new Point(2, 10); chartCPU.Margin = new Padding(2, 10, 2, 10); @@ -234,13 +234,13 @@ namespace GHelper chartCPU.Size = new Size(760, 320); chartCPU.TabIndex = 14; chartCPU.Text = "chartCPU"; - title5.Name = "Title1"; - chartCPU.Titles.Add(title5); + title2.Name = "Title1"; + chartCPU.Titles.Add(title2); // // chartMid // - chartArea6.Name = "ChartArea3"; - chartMid.ChartAreas.Add(chartArea6); + chartArea3.Name = "ChartArea3"; + chartMid.ChartAreas.Add(chartArea3); chartMid.Dock = DockStyle.Fill; chartMid.Location = new Point(2, 690); chartMid.Margin = new Padding(2, 10, 2, 10); @@ -248,8 +248,8 @@ namespace GHelper chartMid.Size = new Size(760, 322); chartMid.TabIndex = 14; chartMid.Text = "chartMid"; - title6.Name = "Title3"; - chartMid.Titles.Add(title6); + title3.Name = "Title3"; + chartMid.Titles.Add(title3); chartMid.Visible = false; // // labelFans @@ -352,7 +352,7 @@ namespace GHelper labelInfo.Margin = new Padding(4, 0, 4, 0); labelInfo.Name = "labelInfo"; labelInfo.Padding = new Padding(5); - labelInfo.Size = new Size(523, 92); + labelInfo.Size = new Size(523, 149); labelInfo.TabIndex = 43; labelInfo.Text = "Experimental Feature"; // diff --git a/app/Fans.cs b/app/Fans.cs index e66d8a15..1d979a8f 100644 --- a/app/Fans.cs +++ b/app/Fans.cs @@ -97,9 +97,8 @@ namespace GHelper trackGPUCore.MouseUp += TrackGPU_MouseUp; trackGPUMemory.MouseUp += TrackGPU_MouseUp; - - trackGPUBoost.MouseUp += TrackGPUBoost_MouseUp; - trackGPUTemp.MouseUp += TrackGPUBoost_MouseUp; + trackGPUBoost.MouseUp += TrackGPU_MouseUp; + trackGPUTemp.MouseUp += TrackGPU_MouseUp; //labelInfo.MaximumSize = new Size(280, 0); labelInfo.Text = Properties.Strings.PPTExperimental; @@ -108,41 +107,22 @@ namespace GHelper InitFans(); InitPower(); InitBoost(); + InitGPU(); comboBoost.SelectedValueChanged += ComboBoost_Changed; Shown += Fans_Shown; - InitGPUControl(); } - private void TrackGPUBoost_MouseUp(object? sender, MouseEventArgs e) - { - Program.config.setConfig("gpu_boost", trackGPUBoost.Value); - Program.config.setConfig("gpu_temp", trackGPUTemp.Value); - Program.settingsForm.SetGPUPower(); - } private void TrackGPU_MouseUp(object? sender, MouseEventArgs e) { - try - { - Program.config.setConfig("gpu_core", trackGPUCore.Value); - Program.config.setConfig("gpu_memory", trackGPUMemory.Value); - - int status = nvControl.SetClocks(trackGPUCore.Value, trackGPUMemory.Value); - if (status == -1) Program.RunAsAdmin("gpu"); - } - catch (Exception ex) - { - Logger.WriteLine("F:" + ex.ToString()); - } - - InitGPUControl(); + Program.settingsForm.AutoGPUSettings(true); } - private void InitGPUControl() + public void InitGPU() { if (HardwareControl.GpuControl is not null && HardwareControl.GpuControl.IsNvidia) { @@ -164,8 +144,8 @@ namespace GHelper trackGPUMemory.Value = Math.Max(Math.Min(memory, NvidiaGpuControl.MaxMemoryOffset), NvidiaGpuControl.MinMemoryOffset); labelGPU.Text = gpuTitle; - int gpu_boost = Program.config.getConfig("gpu_boost"); - int gpu_temp = Program.config.getConfig("gpu_temp"); + int gpu_boost = Program.config.getConfigPerf("gpu_boost"); + int gpu_temp = Program.config.getConfigPerf("gpu_temp"); if (gpu_boost < 0) gpu_boost = ASUSWmi.MaxGPUBoost; if (gpu_temp < 0) gpu_temp = ASUSWmi.MaxGPUTemp; @@ -198,15 +178,21 @@ namespace GHelper private void trackGPU_Scroll(object? sender, EventArgs e) { if (sender is null) return; - TrackBar track = (TrackBar)sender; track.Value = (int)Math.Round((float)track.Value / 5) * 5; + + Program.config.setConfigPerf("gpu_core", trackGPUCore.Value); + Program.config.setConfigPerf("gpu_memory", trackGPUMemory.Value); + VisualiseGPUSettings(); } private void trackGPUPower_Scroll(object? sender, EventArgs e) { + Program.config.setConfigPerf("gpu_boost", trackGPUBoost.Value); + Program.config.setConfigPerf("gpu_temp", trackGPUTemp.Value); + VisualiseGPUSettings(); } @@ -367,7 +353,7 @@ namespace GHelper // Yes, that's stupid, but Total slider on 2021 model actually adjusts CPU PPT if (!cpuBmode) { - labelPlatform.Text = "CPU SPPT"; + labelPlatform.Text = "CPU PPT"; } int limit_total; @@ -506,20 +492,17 @@ namespace GHelper checkApplyFans.Checked = false; checkApplyPower.Checked = false; - /* + Program.config.setConfigPerf("auto_apply", 0); + Program.config.setConfigPerf("auto_apply_power", 0); + + Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, Program.config.getConfig("performance_mode"), "PerfMode"); + trackGPUCore.Value = 0; trackGPUMemory.Value = 0; trackGPUBoost.Value = ASUSWmi.MaxGPUBoost; trackGPUTemp.Value = ASUSWmi.MaxGPUTemp; - Program.config.setConfig("gpu_core", ASUSWmi.MaxGPUBoost); - Program.config.setConfig("gpu_memory", ASUSWmi.MaxGPUTemp); - */ - - Program.config.setConfigPerf("auto_apply", 0); - Program.config.setConfigPerf("auto_apply_power", 0); - - Program.wmi.DeviceSet(ASUSWmi.PerformanceMode, Program.config.getConfig("performance_mode"), "PerfMode"); + Program.settingsForm.AutoGPUSettings(true); } private void ChartCPU_MouseUp(object? sender, MouseEventArgs e) diff --git a/app/Program.cs b/app/Program.cs index b8b15882..c672aacb 100644 --- a/app/Program.cs +++ b/app/Program.cs @@ -29,6 +29,8 @@ namespace GHelper private static long lastAuto; private static long lastTheme; + private static long lastAdmin; + private static PowerLineStatus isPlugged = PowerLineStatus.Unknown; // The main entry point for the application @@ -62,7 +64,7 @@ namespace GHelper } Logger.WriteLine("------------"); - Logger.WriteLine("App launched: " + config.GetModel() + " :" + Assembly.GetExecutingAssembly().GetName().Version.ToString() + (IsUserAdministrator()?"A":"N")); + Logger.WriteLine("App launched: " + config.GetModel() + " :" + Assembly.GetExecutingAssembly().GetName().Version.ToString() + (IsUserAdministrator()?"A":"")); Application.EnableVisualStyles(); @@ -292,7 +294,7 @@ namespace GHelper if (action == "gpu") { - HardwareControl.GetNvidiaGpuControl()?.SetClocksFromConfig(); + Startup.ReScheduleAdmin(); settingsForm.FansToggle(); } } @@ -352,6 +354,10 @@ namespace GHelper public static void RunAsAdmin(string? param = null) { + + if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastAdmin) < 2000) return; + lastAdmin = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + // Check if the current user is an administrator if (!IsUserAdministrator()) { diff --git a/app/Settings.cs b/app/Settings.cs index dff3e027..71b8a384 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -1,4 +1,5 @@ using CustomControls; +using GHelper.Gpu; using Starlight.AnimeMatrix; using System; using System.Diagnostics; @@ -7,6 +8,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Text.Json; using System.Timers; +using System.Windows.Forms; using Tools; namespace GHelper @@ -140,7 +142,7 @@ namespace GHelper int trim = model.LastIndexOf("_"); if (trim > 0) model = model.Substring(0, trim); - labelModel.Text = model; + labelModel.Text = model+(Program.IsUserAdministrator()?".":""); TopMost = Program.config.getConfig("topmost") == 1; @@ -1043,11 +1045,14 @@ namespace GHelper } - public void SetGPUPower() + public void AutoGPUSettings(bool launchAsAdmin = false) { - int gpu_boost = Program.config.getConfig("gpu_boost"); - int gpu_temp = Program.config.getConfig("gpu_temp"); + int gpu_boost = Program.config.getConfigPerf("gpu_boost"); + int gpu_temp = Program.config.getConfigPerf("gpu_temp"); + + int gpu_core = Program.config.getConfigPerf("gpu_core"); + int gpu_memory = Program.config.getConfigPerf("gpu_memory"); if (gpu_boost < ASUSWmi.MinGPUBoost || gpu_boost > ASUSWmi.MaxGPUBoost ) return; if (gpu_temp < ASUSWmi.MinGPUTemp || gpu_temp > ASUSWmi.MaxGPUTemp) return; @@ -1062,6 +1067,23 @@ namespace GHelper Program.wmi.DeviceSet(ASUSWmi.PPT_GPUC2, gpu_temp, "PowerLimit C2"); } + if (gpu_core == -1 && gpu_memory == -1) return; + + if (HardwareControl.GpuControl is not null && HardwareControl.GpuControl.IsNvidia) + { + using NvidiaGpuControl nvControl = (NvidiaGpuControl)HardwareControl.GpuControl; + try + { + int status = nvControl.SetClocks(gpu_core, gpu_memory); + if (launchAsAdmin && status == -1) Program.RunAsAdmin("gpu"); + } + catch (Exception ex) + { + Debug.WriteLine(ex.ToString()); + } + } + + } protected void LabelFansResult(string text) @@ -1136,14 +1158,12 @@ namespace GHelper timer.Stop(); timer.Dispose(); SetPower(); - SetGPUPower(); }; timer.Start(); } else { SetPower(); - SetGPUPower(); } } @@ -1201,8 +1221,10 @@ namespace GHelper } AutoFans(); + AutoGPUSettings(); AutoPower(1000); + if (Program.config.getConfigPerfString("scheme") is not null) NativeMethods.SetPowerScheme(Program.config.getConfigPerfString("scheme")); else @@ -1223,6 +1245,7 @@ namespace GHelper fans.InitFans(); fans.InitPower(); fans.InitBoost(); + fans.InitGPU(); } } @@ -1424,10 +1447,10 @@ namespace GHelper labelGPU.Text = Properties.Strings.GPUMode + ": " + Properties.Strings.GPUChanging + " ..."; - Thread t = new Thread(() => - { - Thread.CurrentThread.IsBackground = true; + Task.Run(async () => + { + if (eco == 1) { string[] tokill = { "EADesktop", "RadeonSoftware" }; @@ -1437,18 +1460,18 @@ namespace GHelper Program.wmi.DeviceSet(ASUSWmi.GPUEco, eco, "GPUEco"); - if (eco == 0) - HardwareControl.RecreateGpuControlWithDelay(); - + await Task.Delay(TimeSpan.FromSeconds(1)); Program.settingsForm.BeginInvoke(delegate { - Thread.Sleep(500); InitGPUMode(); AutoScreen(); }); + + if (eco == 0) + HardwareControl.RecreateGpuControlWithDelay(); + }); - t.Start(); } diff --git a/app/Startup.cs b/app/Startup.cs index 139b4073..abbaaa4f 100644 --- a/app/Startup.cs +++ b/app/Startup.cs @@ -14,6 +14,15 @@ public class Startup return (taskService.RootFolder.AllTasks.Any(t => t.Name == taskName)); } + public static void ReScheduleAdmin() + { + if (Program.IsUserAdministrator() && IsScheduled()) + { + UnSchedule(); + Schedule(); + } + } + public static void Schedule() { From 41caaefc97ae061d7b1d35a628e193cd25199045 Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Tue, 9 May 2023 16:05:57 +0200 Subject: [PATCH 3/3] Improved aura logging --- app/Aura.cs | 23 ++++++++++++++--------- app/Gpu/NvidiaGpuControl.cs | 4 ++-- app/Settings.cs | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/Aura.cs b/app/Aura.cs index 3921a441..7fc09698 100644 --- a/app/Aura.cs +++ b/app/Aura.cs @@ -1,6 +1,7 @@ using HidLibrary; using OSD; using System.Diagnostics; +using System.Windows.Forms; namespace GHelper { @@ -197,15 +198,16 @@ namespace GHelper { byte[] msg = { 0x5d, 0xba, 0xc5, 0xc4, (byte)brightness }; - foreach (HidDevice device in GetHidDevices(new int[] { 0x19b6 })) + var devices = GetHidDevices(new int[] { 0x19b6 }); + if (devices.Count() > 0) Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg)); + + foreach (HidDevice device in devices) { device.OpenDevice(); device.Write(msg); device.CloseDevice(); } - Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg)); - if (Program.config.ContainsModel("TUF")) Program.wmi.TUFKeyboardBrightness(brightness); } @@ -216,18 +218,18 @@ namespace GHelper byte[] msg = AuraDev19b6Extensions.ToBytes(flags.ToArray()); - Debug.WriteLine(BitConverter.ToString(msg)); - foreach (HidDevice device in GetHidDevices(new int[] { 0x19b6 })) + var devices = GetHidDevices(new int[] { 0x19b6 }); + if (devices.Count() > 0) Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg)); + + foreach (HidDevice device in devices) { device.OpenDevice(); device.Write(msg); device.CloseDevice(); } - Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg)); - - //if (Program.config.ContainsModel("TUF")) + if (Program.config.ContainsModel("TUF")) Program.wmi.TUFKeyboardPower( flags.Contains(AuraDev19b6.AwakeKeyb), flags.Contains(AuraDev19b6.BootKeyb), @@ -273,7 +275,10 @@ namespace GHelper byte[] msg = AuraMessage(Mode, Color1, Color2, _speed); - foreach (HidDevice device in GetHidDevices(deviceIds)) + var devices = GetHidDevices(deviceIds); + if (devices.Count() > 0) Logger.WriteLine("USB-KB = " + BitConverter.ToString(msg)); + + foreach (HidDevice device in devices) { device.OpenDevice(); device.Write(msg); diff --git a/app/Gpu/NvidiaGpuControl.cs b/app/Gpu/NvidiaGpuControl.cs index 8c859aa7..6629a5de 100644 --- a/app/Gpu/NvidiaGpuControl.cs +++ b/app/Gpu/NvidiaGpuControl.cs @@ -4,6 +4,7 @@ using NvAPIWrapper.Native.GPU; using NvAPIWrapper.Native.GPU.Structures; using NvAPIWrapper.Native.Interfaces.GPU; using System.Diagnostics; +using System.Management; using static NvAPIWrapper.Native.GPU.Structures.PerformanceStates20InfoV1; namespace GHelper.Gpu; @@ -46,7 +47,6 @@ public class NvidiaGpuControl : IGpuControl } - public void GetClocks(out int core, out int memory, out string gpu) { PhysicalGPU internalGpu = _internalGpu!; @@ -86,7 +86,7 @@ public class NvidiaGpuControl : IGpuControl var coreClock = new PerformanceStates20ClockEntryV1(PublicClockDomain.Graphics, new PerformanceStates20ParameterDelta(core * 1000)); var memoryClock = new PerformanceStates20ClockEntryV1(PublicClockDomain.Memory, new PerformanceStates20ParameterDelta(memory * 1000)); - PerformanceStates20ClockEntryV1[] clocks = { coreClock , memoryClock}; + PerformanceStates20ClockEntryV1[] clocks = { coreClock, memoryClock }; PerformanceStates20BaseVoltageEntryV1[] voltages = { }; PerformanceState20[] performanceStates = { new PerformanceState20(PerformanceStateId.P0_3DPerformance, clocks, voltages) }; diff --git a/app/Settings.cs b/app/Settings.cs index 71b8a384..6cc2b9a4 100644 --- a/app/Settings.cs +++ b/app/Settings.cs @@ -948,7 +948,7 @@ namespace GHelper SetGPUMode(ASUSWmi.GPUModeEco); } - public void RefreshSensors(bool force = false) + public async void RefreshSensors(bool force = false) { if (!force && Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastRefresh) < 2000) return;