Minor tweaks

This commit is contained in:
seerge
2023-03-27 14:28:28 +02:00
parent 7ab3b450cd
commit 089b339e61
8 changed files with 187 additions and 89 deletions

View File

@@ -1,6 +1,4 @@
using GHelper;
using System.Diagnostics;
using System.Management;
using System.Management;
using System.Runtime.InteropServices;
public class ASUSWmi
@@ -12,6 +10,10 @@ public class ASUSWmi
const uint DSTS = 0x53545344;
const uint DEVS = 0x53564544;
public const uint UniversalControl = 0x00100021;
public const int KB_Light_Up = 0xc4;
public const int KB_Light_Down = 0xc5;
public const uint CPU_Fan = 0x00110013;
public const uint GPU_Fan = 0x00110014;
public const uint Mid_Fan = 0x00110031;

View File

@@ -359,7 +359,7 @@ namespace Starlight.AnimeMatrix
public void PresentText(string text, float fontSize = 8F)
public void PresentText(string text, float fontSize = 8.5F)
{
using (Bitmap bmp = new Bitmap(MaxColumns * 3, MaxRows))
{
@@ -378,21 +378,22 @@ namespace Starlight.AnimeMatrix
g.DrawString(text, font, Brushes.White, -textSize.Width/2, -textSize.Height / 2);
*/
g.DrawString(text, font, Brushes.White, 12, -2);
g.DrawString(text, font, Brushes.White, 5, -2);
}
}
GenerateFrame(bmp);
GenerateFrame(bmp, System.Drawing.Drawing2D.InterpolationMode.Bicubic);
Present();
}
}
public void GenerateFrame(Image image)
public void GenerateFrame(Image image, System.Drawing.Drawing2D.InterpolationMode interpolation = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic)
{
int width = MaxColumns * 3;
int height = MaxRows;
int targetWidth = MaxColumns * 2;
float scale;
@@ -403,14 +404,14 @@ namespace Starlight.AnimeMatrix
using (var graph = Graphics.FromImage(bmp))
{
var scaleWidth = (int)(image.Width * scale);
var scaleHeight = (int)(image.Height * scale);
var scaleWidth = (float)(image.Width * scale);
var scaleHeight = (float)(image.Height * scale);
graph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
graph.InterpolationMode = interpolation;
graph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
graph.DrawImage(image, (int)Math.Round(targetWidth - scaleWidth/1.5), 0, (int)Math.Round(scaleWidth/1.5), scaleHeight);
graph.DrawImage(image, (float)Math.Round(targetWidth - scaleWidth * targetWidth / width), 0, (float)Math.Round(scaleWidth * targetWidth / width), scaleHeight);
}
@@ -420,12 +421,12 @@ namespace Starlight.AnimeMatrix
if (x % 2 == y % 2)
{
var pixel = bmp.GetPixel(x, y);
SetLedPlanar(x / 2, y, (byte)((pixel.R + pixel.G + pixel.B) / 3));
var color = (pixel.R + pixel.G + pixel.B) / 3;
if (color < 10) color = 0;
SetLedPlanar(x / 2, y, (byte)color);
}
}
}
}
private void EnsureRowInRange(int row)

View File

@@ -1,7 +1,5 @@
using HidLibrary;
using Microsoft.VisualBasic.ApplicationServices;
using System.Diagnostics;
using static Starlight.AnimeMatrix.BuiltInAnimation;
namespace GHelper
{
@@ -36,7 +34,7 @@ namespace GHelper
{
a |= (uint)n;
}
return new byte[] {0x5d, 0xbd, 0x01, (byte)(a & 0xff), (byte)((a & 0xff00) >> 8), (byte)((a & 0xff0000) >> 16) };
return new byte[] { 0x5d, 0xbd, 0x01, (byte)(a & 0xff), (byte)((a & 0xff00) >> 8), (byte)((a & 0xff0000) >> 16) };
}
public static ushort BitOr(this AuraDev19b6 self, AuraDev19b6 rhs)
@@ -56,6 +54,7 @@ namespace GHelper
static byte[] MESSAGE_SET = { 0x5d, 0xb5, 0, 0, 0 };
static byte[] MESSAGE_APPLY = { 0x5d, 0xb4 };
static int[] deviceIds = { 0x1854, 0x1869, 0x1866, 0x19b6, 0x1822, 0x1837, 0x1854, 0x184a, 0x183d, 0x8502, 0x1807, 0x17e0 };
private static int mode = 0;
private static int speed = 1;
@@ -145,6 +144,22 @@ namespace GHelper
}
public static void ApplyBrightness(int brightness)
{
HidDevice[] HidDeviceList = HidDevices.Enumerate(0x0b05, deviceIds).ToArray();
byte[] msg = { 0x5a, 0xba, 0xc5, 0xc4, (byte)brightness };
foreach (HidDevice device in HidDeviceList)
if (device.IsConnected && device.Description.Contains("HID"))
{
device.OpenDevice();
device.Write(msg);
device.CloseDevice();
}
}
public static void ApplyAuraPower(bool awake = true, bool boot = false, bool sleep = false, bool shutdown = false)
{
@@ -176,10 +191,7 @@ namespace GHelper
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();
HidDevice[] HidDeviceList = HidDevices.Enumerate(0x0b05, deviceIds).ToArray();
int _speed;

150
app/Keyboard.Designer.cs generated
View File

@@ -41,14 +41,18 @@ namespace GHelper
comboM3 = new RComboBox();
labelM3 = new Label();
groupLight = new GroupBox();
checkAwake = new CheckBox();
checkBoot = new CheckBox();
checkSleep = new CheckBox();
checkShutdown = new CheckBox();
comboKeyboardSpeed = new RComboBox();
labelSpeed = new Label();
comboKeyboardSpeed = new RComboBox();
checkShutdown = new CheckBox();
checkSleep = new CheckBox();
checkBoot = new CheckBox();
checkAwake = new CheckBox();
groupOther = new GroupBox();
checkKeyboardAuto = new CheckBox();
checkTopmost = new CheckBox();
groupBox1.SuspendLayout();
groupLight.SuspendLayout();
groupOther.SuspendLayout();
SuspendLayout();
//
// groupBox1
@@ -65,7 +69,7 @@ namespace GHelper
groupBox1.Dock = DockStyle.Top;
groupBox1.Location = new Point(10, 10);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(751, 242);
groupBox1.Size = new Size(756, 242);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Key Bindings";
@@ -158,50 +162,19 @@ namespace GHelper
groupLight.Dock = DockStyle.Top;
groupLight.Location = new Point(10, 252);
groupLight.Name = "groupLight";
groupLight.Size = new Size(751, 304);
groupLight.Size = new Size(756, 304);
groupLight.TabIndex = 1;
groupLight.TabStop = false;
groupLight.Text = "Keyboard Backlight";
//
// checkAwake
// labelSpeed
//
checkAwake.AutoSize = true;
checkAwake.Location = new Point(25, 59);
checkAwake.Name = "checkAwake";
checkAwake.Size = new Size(115, 36);
checkAwake.TabIndex = 0;
checkAwake.Text = "Awake";
checkAwake.UseVisualStyleBackColor = true;
//
// checkBoot
//
checkBoot.AutoSize = true;
checkBoot.Location = new Point(25, 101);
checkBoot.Name = "checkBoot";
checkBoot.Size = new Size(96, 36);
checkBoot.TabIndex = 1;
checkBoot.Text = "Boot";
checkBoot.UseVisualStyleBackColor = true;
//
// checkSleep
//
checkSleep.AutoSize = true;
checkSleep.Location = new Point(25, 143);
checkSleep.Name = "checkSleep";
checkSleep.Size = new Size(105, 36);
checkSleep.TabIndex = 2;
checkSleep.Text = "Sleep";
checkSleep.UseVisualStyleBackColor = true;
//
// checkShutdown
//
checkShutdown.AutoSize = true;
checkShutdown.Location = new Point(25, 185);
checkShutdown.Name = "checkShutdown";
checkShutdown.Size = new Size(154, 36);
checkShutdown.TabIndex = 3;
checkShutdown.Text = "Shutdown";
checkShutdown.UseVisualStyleBackColor = true;
labelSpeed.AutoSize = true;
labelSpeed.Location = new Point(25, 237);
labelSpeed.Name = "labelSpeed";
labelSpeed.Size = new Size(198, 32);
labelSpeed.TabIndex = 40;
labelSpeed.Text = "Animation Speed";
//
// comboKeyboardSpeed
//
@@ -219,20 +192,84 @@ namespace GHelper
comboKeyboardSpeed.TabIndex = 39;
comboKeyboardSpeed.TabStop = false;
//
// labelSpeed
// checkShutdown
//
labelSpeed.AutoSize = true;
labelSpeed.Location = new Point(25, 237);
labelSpeed.Name = "labelSpeed";
labelSpeed.Size = new Size(198, 32);
labelSpeed.TabIndex = 40;
labelSpeed.Text = "Animation Speed";
checkShutdown.AutoSize = true;
checkShutdown.Location = new Point(25, 185);
checkShutdown.Name = "checkShutdown";
checkShutdown.Size = new Size(154, 36);
checkShutdown.TabIndex = 3;
checkShutdown.Text = "Shutdown";
checkShutdown.UseVisualStyleBackColor = true;
//
// checkSleep
//
checkSleep.AutoSize = true;
checkSleep.Location = new Point(25, 143);
checkSleep.Name = "checkSleep";
checkSleep.Size = new Size(105, 36);
checkSleep.TabIndex = 2;
checkSleep.Text = "Sleep";
checkSleep.UseVisualStyleBackColor = true;
//
// checkBoot
//
checkBoot.AutoSize = true;
checkBoot.Location = new Point(25, 101);
checkBoot.Name = "checkBoot";
checkBoot.Size = new Size(96, 36);
checkBoot.TabIndex = 1;
checkBoot.Text = "Boot";
checkBoot.UseVisualStyleBackColor = true;
//
// checkAwake
//
checkAwake.AutoSize = true;
checkAwake.Location = new Point(25, 59);
checkAwake.Name = "checkAwake";
checkAwake.Size = new Size(115, 36);
checkAwake.TabIndex = 0;
checkAwake.Text = "Awake";
checkAwake.UseVisualStyleBackColor = true;
//
// groupOther
//
groupOther.Controls.Add(checkKeyboardAuto);
groupOther.Controls.Add(checkTopmost);
groupOther.Dock = DockStyle.Top;
groupOther.Location = new Point(10, 556);
groupOther.Name = "groupOther";
groupOther.Size = new Size(756, 167);
groupOther.TabIndex = 2;
groupOther.TabStop = false;
groupOther.Text = "Other";
//
// checkKeyboardAuto
//
checkKeyboardAuto.AutoSize = true;
checkKeyboardAuto.Location = new Point(25, 51);
checkKeyboardAuto.Name = "checkKeyboardAuto";
checkKeyboardAuto.Size = new Size(712, 36);
checkKeyboardAuto.TabIndex = 2;
checkKeyboardAuto.Text = "Lower backlight brightness on battery and back when plugged";
checkKeyboardAuto.UseVisualStyleBackColor = true;
//
// checkTopmost
//
checkTopmost.AutoSize = true;
checkTopmost.Location = new Point(25, 104);
checkTopmost.Name = "checkTopmost";
checkTopmost.Size = new Size(390, 36);
checkTopmost.TabIndex = 1;
checkTopmost.Text = "Keep app window always on top";
checkTopmost.UseVisualStyleBackColor = true;
//
// Keyboard
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(771, 858);
ClientSize = new Size(776, 858);
Controls.Add(groupOther);
Controls.Add(groupLight);
Controls.Add(groupBox1);
FormBorderStyle = FormBorderStyle.FixedSingle;
@@ -243,11 +280,13 @@ namespace GHelper
Padding = new Padding(10);
ShowIcon = false;
ShowInTaskbar = false;
Text = "Keyboard";
Text = "Extra Settings";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
groupLight.ResumeLayout(false);
groupLight.PerformLayout();
groupOther.ResumeLayout(false);
groupOther.PerformLayout();
ResumeLayout(false);
}
@@ -270,5 +309,8 @@ namespace GHelper
private CheckBox checkShutdown;
private Label labelSpeed;
private RComboBox comboKeyboardSpeed;
private GroupBox groupOther;
private CheckBox checkTopmost;
private CheckBox checkKeyboardAuto;
}
}

View File

@@ -78,8 +78,25 @@ namespace GHelper
checkSleep.CheckedChanged += CheckPower_CheckedChanged;
checkShutdown.CheckedChanged += CheckPower_CheckedChanged;
checkTopmost.Checked = (Program.config.getConfig("topmost") == 1);
checkTopmost.CheckedChanged += CheckTopmost_CheckedChanged; ;
checkKeyboardAuto.Checked = (Program.config.getConfig("keyboard_auto") == 1);
checkKeyboardAuto.CheckedChanged += CheckKeyboardAuto_CheckedChanged;
}
private void CheckKeyboardAuto_CheckedChanged(object? sender, EventArgs e)
{
Program.config.setConfig("keyboard_auto", (checkKeyboardAuto.Checked ? 1 : 0));
}
private void CheckTopmost_CheckedChanged(object? sender, EventArgs e)
{
Program.config.setConfig("topmost", (checkTopmost.Checked ? 1 : 0));
Program.settingsForm.TopMost = checkTopmost.Checked;
}
private void CheckPower_CheckedChanged(object? sender, EventArgs e)
{

View File

@@ -588,7 +588,7 @@ public class NativeMethods
return laptopScreen;
}
public static int GetRefreshRate()
public static int GetRefreshRate(bool max = false)
{
DEVMODE dm = CreateDevmode();
@@ -598,10 +598,22 @@ public class NativeMethods
if (laptopScreen is null)
return -1;
if (max)
{
int i = 0;
while (0 != NativeMethods.EnumDisplaySettingsEx(laptopScreen, i, ref dm))
{
if (dm.dmDisplayFrequency > frequency) frequency = dm.dmDisplayFrequency;
i++;
}
} else
{
if (0 != NativeMethods.EnumDisplaySettingsEx(laptopScreen, NativeMethods.ENUM_CURRENT_SETTINGS, ref dm))
{
frequency = dm.dmDisplayFrequency;
}
}
return frequency;
}

View File

@@ -148,6 +148,7 @@ namespace GHelper
if (SystemInformation.PowerStatus.PowerLineStatus == isPlugged) return;
Logger.WriteLine("Windows - Power Mode Changed");
settingsForm.AutoKeyboard(SystemInformation.PowerStatus.PowerLineStatus);
SetAutoModes(true);
}

View File

@@ -2,6 +2,7 @@
using Starlight.AnimeMatrix;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.Globalization;
using System.Reflection;
using System.Text.Json;
using System.Timers;
@@ -133,6 +134,8 @@ namespace GHelper
labelModel.Text = model;
this.TopMost = Program.config.getConfig("topmost") == 1;
Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromSeconds(5));
@@ -687,8 +690,7 @@ namespace GHelper
if (frequency >= 1000)
{
frequency = Program.config.getConfig("max_frequency");
if (frequency <= 60) frequency = 120;
frequency = NativeMethods.GetRefreshRate(true);
}
if (frequency > 0)
@@ -714,7 +716,7 @@ namespace GHelper
{
int frequency = NativeMethods.GetRefreshRate();
int maxFrequency = Program.config.getConfig("max_frequency");
int maxFrequency = NativeMethods.GetRefreshRate(true);
bool screenAuto = (Program.config.getConfig("screen_auto") == 1);
@@ -744,12 +746,8 @@ namespace GHelper
{
button60Hz.Activated = true;
}
else
else if (frequency > 60)
{
if (frequency > 60)
maxFrequency = frequency;
Program.config.setConfig("max_frequency", maxFrequency);
button120Hz.Activated = true;
}
@@ -999,6 +997,19 @@ namespace GHelper
SetPerformanceMode(Program.config.getConfig("performance_mode") + 1, true);
}
public void AutoKeyboard(PowerLineStatus Plugged = PowerLineStatus.Online)
{
if (Program.config.getConfig("keyboard_auto") != 1) return;
if (Plugged == PowerLineStatus.Online)
Program.wmi.DeviceSet(ASUSWmi.UniversalControl, ASUSWmi.KB_Light_Up);
else
Program.wmi.DeviceSet(ASUSWmi.UniversalControl, ASUSWmi.KB_Light_Down);
}
public void AutoPerformance(PowerLineStatus Plugged = PowerLineStatus.Online)
{
int mode = Program.config.getConfig("performance_" + (int)Plugged);