Support for TUF RGB keyboards and other fixes

This commit is contained in:
seerge
2023-03-25 14:37:37 +01:00
parent 8bc9325b3f
commit 7702dc8e38
7 changed files with 373 additions and 195 deletions

View File

@@ -1,4 +1,6 @@
using System.Management; using GHelper;
using System.Diagnostics;
using System.Management;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
public class ASUSWmi public class ASUSWmi
@@ -38,6 +40,9 @@ public class ASUSWmi
public const int PPT_APUC1 = 0x001200C1; public const int PPT_APUC1 = 0x001200C1;
public const int PPT_APUC2 = 0x001200C2; 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 PerformanceBalanced = 0;
public const int PerformanceTurbo = 1; public const int PerformanceTurbo = 1;
public const int PerformanceSilent = 2; 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]; byte[] args = new byte[8];
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0); BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
BitConverter.GetBytes((uint)Status).CopyTo(args, 4); 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]; byte[] args = new byte[4 + Params.Length];
BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0); BitConverter.GetBytes((uint)DeviceID).CopyTo(args, 0);
Params.CopyTo(args, 4); 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<object, EventArrivedEventArgs> EventHandler) public void SubscribeToEvents(Action<object, EventArrivedEventArgs> EventHandler)
{ {
ManagementEventWatcher watcher = new ManagementEventWatcher(); ManagementEventWatcher watcher = new ManagementEventWatcher();

View File

@@ -2,6 +2,7 @@
using Starlight.Communication; using Starlight.Communication;
using System.Management; using System.Management;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
namespace Starlight.AnimeMatrix namespace Starlight.AnimeMatrix
@@ -56,6 +57,14 @@ namespace Starlight.AnimeMatrix
} }
} }
public enum AnimeType
{
GA401,
GA402
}
public enum BrightnessMode : byte public enum BrightnessMode : byte
{ {
Off = 0, Off = 0,
@@ -74,29 +83,35 @@ namespace Starlight.AnimeMatrix
List<byte[]> frames = new List<byte[]>(); List<byte[]> frames = new List<byte[]>();
public int MaxRows = 61; public int MaxRows = 61;
public int FullRows = 11; //public int FullRows = 11;
public int FullEvenRows = -1; //public int FullEvenRows = -1;
public int MaxColumns = 34; public int MaxColumns = 34;
private int frameIndex = 0; private int frameIndex = 0;
private static AnimeType _model = AnimeType.GA402;
public AnimeMatrixDevice() public AnimeMatrixDevice()
: base(0x0B05, 0x193B, 640) : base(0x0B05, 0x193B, 640)
{ {
string model = GetModel(); string model = GetModel();
if (model.Contains("401")) if (model.Contains("401"))
{ {
_model = AnimeType.GA401;
MaxColumns = 33; MaxColumns = 33;
FullRows = 7; //FullRows = 7;
FullEvenRows = 3; //FullEvenRows = 3;
MaxRows = 55; MaxRows = 55;
LedCount = 1214; LedCount = 1214;
UpdatePageLength = 410; UpdatePageLength = 410;
} }
_displayBuffer = new byte[LedCount]; _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) public int XStart(int row)
{ {
return (int)Math.Ceiling(Math.Max(0, row - FullRows) / 2.0); return (int)Math.Ceiling(Math.Max(0, row - FullRows) / 2.0);
@@ -158,19 +237,30 @@ namespace Starlight.AnimeMatrix
} }
return MaxColumns; return MaxColumns;
} }
*/
public int RowToLinearAddress(int row) public int RowToLinearAddress(int y)
{ {
EnsureRowInRange(row); EnsureRowInRange(y);
int ret = 0; int ret = 0;
for (var i = 0; i < row; i++) for (var i = 0; i < y; i++)
ret += XEnd(i) - XStart(i); ret += Pitch(i);
return ret; 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() public void WakeUp()
{ {
Set(Packet<AnimeMatrixPacket>(Encoding.ASCII.GetBytes("ASUS Tech.Inc."))); Set(Packet<AnimeMatrixPacket>(Encoding.ASCII.GetBytes("ASUS Tech.Inc.")));
@@ -196,15 +286,7 @@ namespace Starlight.AnimeMatrix
Set(Packet<AnimeMatrixPacket>(0xC0, 0x03)); Set(Packet<AnimeMatrixPacket>(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) public void Clear(bool present = false)
{ {

View File

@@ -1,78 +1,142 @@
using HidLibrary; 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 class Aura
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()
{ {
HidDevice[] HidDeviceList; static byte[] MESSAGE_SET = { 0x5d, 0xb5, 0, 0, 0 };
int[] deviceIds = { 0x1854, 0x1869, 0x1866, 0x19b6, 0x1822, 0x1837, 0x1854, 0x184a, 0x183d, 0x8502, 0x1807, 0x17e0 }; static byte[] MESSAGE_APPLY = { 0x5d, 0xb4 };
HidDeviceList = HidDevices.Enumerate(0x0b05, deviceIds).ToArray();
if (Mode == Dingding) private static int mode = 0;
{ private static int speed = 1;
Mode = 10; public static Color Color1 = Color.White;
Speed = SpeedMedium; public static Color Color2 = Color.Black;
}
else if (Mode == Rainbow)
{
Speed = SpeedMedium;
}
else
{
Speed = SpeedSlow;
}
foreach (HidDevice device in HidDeviceList)
public static Dictionary<int, string> GetSpeeds()
{ {
if (device.IsConnected && device.Description.Contains("HID")) return new Dictionary<int, string>
{ {
device.OpenDevice(); { 0, "Slow" },
byte[] msg = AuraMessage(Mode, Color1, Color2, Speed); { 1, "Normal" },
device.Write(msg); { 2, "Fast" }
device.Write(MESSAGE_SET); };
device.Write(MESSAGE_APPLY); }
device.CloseDevice(); public static Dictionary<int, string> GetModes()
{
return new Dictionary<int, string>
{
{ 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();
}
}
}
} }
}
}

View File

@@ -16,7 +16,7 @@
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly> <ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyVersion>0.38</AssemblyVersion> <AssemblyVersion>0.39</AssemblyVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -23,8 +23,7 @@ namespace GHelper
public static SettingsForm settingsForm = new SettingsForm(); public static SettingsForm settingsForm = new SettingsForm();
public static ToastForm toast = new ToastForm(); public static ToastForm toast = new ToastForm();
private static IntPtr unRegPowerNotify; public static IntPtr unRegPowerNotify;
private static IntPtr ds;
private static long lastAuto; private static long lastAuto;
private static long lastTheme; private static long lastTheme;
@@ -56,7 +55,7 @@ namespace GHelper
SystemEvents.UserPreferenceChanged += new SystemEvents.UserPreferenceChanged += new
UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged); UserPreferenceChangedEventHandler(SystemEvents_UserPreferenceChanged);
ds = settingsForm.Handle; var ds = settingsForm.Handle;
trayIcon.MouseClick += TrayIcon_MouseClick; trayIcon.MouseClick += TrayIcon_MouseClick;
@@ -72,10 +71,6 @@ namespace GHelper
SetAutoModes(); SetAutoModes();
HardwareMonitor.RecreateGpuTemperatureProvider(); 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 // Subscribing for system power change events
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;

View File

@@ -79,12 +79,13 @@ namespace GHelper
labelSreen = new Label(); labelSreen = new Label();
panelKeyboard = new Panel(); panelKeyboard = new Panel();
tableLayoutKeyboard = new TableLayoutPanel(); tableLayoutKeyboard = new TableLayoutPanel();
buttonKeyboard = new RButton();
comboKeyboard = new RComboBox(); comboKeyboard = new RComboBox();
comboKeyboardSpeed = new RComboBox();
panelColor = new Panel(); panelColor = new Panel();
pictureColor2 = new PictureBox(); pictureColor2 = new PictureBox();
pictureColor = new PictureBox(); pictureColor = new PictureBox();
buttonKeyboardColor = new RButton(); buttonKeyboardColor = new RButton();
buttonKeyboard = new RButton();
pictureKeyboard = new PictureBox(); pictureKeyboard = new PictureBox();
labelKeyboard = new Label(); labelKeyboard = new Label();
panelMatrix.SuspendLayout(); 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.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(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.Location = new Point(16, 50);
tableLayoutKeyboard.Margin = new Padding(8); tableLayoutKeyboard.Margin = new Padding(8);
tableLayoutKeyboard.Name = "tableLayoutKeyboard"; tableLayoutKeyboard.Name = "tableLayoutKeyboard";
@@ -879,24 +881,6 @@ namespace GHelper
tableLayoutKeyboard.Size = new Size(772, 60); tableLayoutKeyboard.Size = new Size(772, 60);
tableLayoutKeyboard.TabIndex = 39; 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
// //
comboKeyboard.BorderColor = Color.White; comboKeyboard.BorderColor = Color.White;
@@ -906,7 +890,7 @@ namespace GHelper
comboKeyboard.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); comboKeyboard.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point);
comboKeyboard.FormattingEnabled = true; comboKeyboard.FormattingEnabled = true;
comboKeyboard.ItemHeight = 32; 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.Location = new Point(4, 10);
comboKeyboard.Margin = new Padding(4, 10, 4, 8); comboKeyboard.Margin = new Padding(4, 10, 4, 8);
comboKeyboard.Name = "comboKeyboard"; comboKeyboard.Name = "comboKeyboard";
@@ -914,6 +898,23 @@ namespace GHelper
comboKeyboard.TabIndex = 35; comboKeyboard.TabIndex = 35;
comboKeyboard.TabStop = false; 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
// //
panelColor.AutoSize = true; panelColor.AutoSize = true;
@@ -921,7 +922,7 @@ namespace GHelper
panelColor.Controls.Add(pictureColor); panelColor.Controls.Add(pictureColor);
panelColor.Controls.Add(buttonKeyboardColor); panelColor.Controls.Add(buttonKeyboardColor);
panelColor.Dock = DockStyle.Fill; 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.Margin = new Padding(4, 8, 4, 8);
panelColor.Name = "panelColor"; panelColor.Name = "panelColor";
panelColor.Size = new Size(185, 44); panelColor.Size = new Size(185, 44);
@@ -930,7 +931,7 @@ namespace GHelper
// pictureColor2 // pictureColor2
// //
pictureColor2.Anchor = AnchorStyles.Top | AnchorStyles.Right; pictureColor2.Anchor = AnchorStyles.Top | AnchorStyles.Right;
pictureColor2.Location = new Point(123, 12); pictureColor2.Location = new Point(126, 12);
pictureColor2.Margin = new Padding(8); pictureColor2.Margin = new Padding(8);
pictureColor2.Name = "pictureColor2"; pictureColor2.Name = "pictureColor2";
pictureColor2.Size = new Size(20, 20); pictureColor2.Size = new Size(20, 20);
@@ -962,9 +963,27 @@ namespace GHelper
buttonKeyboardColor.Secondary = false; buttonKeyboardColor.Secondary = false;
buttonKeyboardColor.Size = new Size(185, 44); buttonKeyboardColor.Size = new Size(185, 44);
buttonKeyboardColor.TabIndex = 39; buttonKeyboardColor.TabIndex = 39;
buttonKeyboardColor.Text = "Color "; buttonKeyboardColor.Text = " Color .";
buttonKeyboardColor.UseVisualStyleBackColor = false; 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
// //
pictureKeyboard.BackgroundImage = Properties.Resources.icons8_keyboard_48; pictureKeyboard.BackgroundImage = Properties.Resources.icons8_keyboard_48;
@@ -1103,5 +1122,6 @@ namespace GHelper
private RButton buttonKeyboardColor; private RButton buttonKeyboardColor;
private RButton buttonFans; private RButton buttonFans;
private Label labelMidFan; private Label labelMidFan;
private RComboBox comboKeyboardSpeed;
} }
} }

View File

@@ -66,10 +66,6 @@ namespace GHelper
buttonQuit.Click += ButtonQuit_Click; buttonQuit.Click += ButtonQuit_Click;
comboKeyboard.DropDownStyle = ComboBoxStyle.DropDownList;
comboKeyboard.SelectedIndex = 0;
comboKeyboard.SelectedValueChanged += ComboKeyboard_SelectedValueChanged;
buttonKeyboardColor.Click += ButtonKeyboardColor_Click; buttonKeyboardColor.Click += ButtonKeyboardColor_Click;
buttonFans.Click += ButtonFans_Click; buttonFans.Click += ButtonFans_Click;
@@ -133,8 +129,13 @@ namespace GHelper
t.Start(); t.Start();
t.Join(); 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) private void TrackBattery_ValueChanged(object? sender, EventArgs e)
{ {
SetBatteryChargeLimit(trackBattery.Value); SetBatteryChargeLimit(trackBattery.Value);
@@ -255,6 +256,7 @@ namespace GHelper
protected override void WndProc(ref Message m) protected override void WndProc(ref Message m)
{ {
switch (m.Msg) switch (m.Msg)
{ {
case NativeMethods.WM_POWERBROADCAST: case NativeMethods.WM_POWERBROADCAST:
@@ -511,12 +513,13 @@ namespace GHelper
{ {
ColorDialog colorDlg = new ColorDialog(); ColorDialog colorDlg = new ColorDialog();
colorDlg.AllowFullOpen = false; colorDlg.AllowFullOpen = true;
colorDlg.Color = pictureColor2.BackColor; colorDlg.Color = pictureColor2.BackColor;
if (colorDlg.ShowDialog() == DialogResult.OK) 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) private void ButtonKeyboardColor_Click(object? sender, EventArgs e)
{ {
if (sender is null)
return;
Button but = (Button)sender;
ColorDialog colorDlg = new ColorDialog(); ColorDialog colorDlg = new ColorDialog();
colorDlg.AllowFullOpen = false; colorDlg.AllowFullOpen = true;
colorDlg.Color = pictureColor.BackColor; colorDlg.Color = pictureColor.BackColor;
if (colorDlg.ShowDialog() == DialogResult.OK) if (colorDlg.ShowDialog() == DialogResult.OK)
{ {
SetAuraColor(color1: colorDlg.Color); Program.config.setConfig("aura_color", colorDlg.Color.ToArgb());
SetAura();
} }
} }
public void InitAura() public void InitAura()
{ {
int mode = Program.config.getConfig("aura_mode"); Aura.Mode = Program.config.getConfig("aura_mode");
int colorCode = Program.config.getConfig("aura_color"); Aura.Speed = Program.config.getConfig("aura_speed");
int colorCode2 = Program.config.getConfig("aura_color2"); 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); comboKeyboardSpeed.DropDownStyle = ComboBoxStyle.DropDownList;
Color color2 = Color.FromArgb(0, 0, 0); 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) pictureColor.BackColor = Aura.Color1;
color = Color.FromArgb(colorCode); pictureColor2.BackColor = Aura.Color2;
pictureColor2.Visible = Aura.HasSecondColor();
if (colorCode2 != -1)
color2 = Color.FromArgb(colorCode2);
SetAuraColor(color, color2, false);
SetAuraMode(mode, false);
Aura.Mode = mode;
} }
public void InitMatrix() public void InitMatrix()
@@ -629,67 +629,42 @@ namespace GHelper
} }
public void SetAuraColor(Color? color1 = null, Color? color2 = null, bool apply = true) public void SetAura()
{ {
Aura.Mode = Program.config.getConfig("aura_mode");
if (color1 is not null) Aura.Speed = Program.config.getConfig("aura_speed");
{ Aura.SetColor(Program.config.getConfig("aura_color"));
Aura.Color1 = (Color)color1; Aura.SetColor2(Program.config.getConfig("aura_color2"));
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();
pictureColor.BackColor = Aura.Color1; pictureColor.BackColor = Aura.Color1;
pictureColor2.BackColor = Aura.Color2; pictureColor2.BackColor = Aura.Color2;
} pictureColor2.Visible = Aura.HasSecondColor();
public void SetAuraMode(int mode = 0, bool apply = true) Aura.ApplyAura();
{
//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();
} }
public void CycleAuraMode() 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) private void ComboKeyboard_SelectedValueChanged(object? sender, EventArgs e)
{ {
if (sender is null) Program.config.setConfig("aura_mode", (int)comboKeyboard.SelectedValue);
return; SetAura();
ComboBox cmb = (ComboBox)sender;
SetAuraMode(cmb.SelectedIndex);
} }
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) private void Button120Hz_Click(object? sender, EventArgs e)
{ {
Program.config.setConfig("screen_auto", 0); Program.config.setConfig("screen_auto", 0);
@@ -1088,8 +1063,7 @@ namespace GHelper
} }
tableLayoutKeyboard.ColumnCount = 0; //tableLayoutMatrix.ColumnCount = 0;
tableLayoutMatrix.ColumnCount = 0;
} }