This commit is contained in:
Serge
2023-11-12 22:26:33 +01:00
parent 96ade7c9a0
commit 435ddbb951
3 changed files with 232 additions and 216 deletions

View File

@@ -1,4 +1,5 @@
using GHelper; using GHelper;
using GHelper.USB;
using System.Management; using System.Management;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@@ -549,7 +550,7 @@ public class AsusACPI
DeviceSet(TUF_KB_BRIGHTNESS, param, "TUF Brightness"); DeviceSet(TUF_KB_BRIGHTNESS, param, "TUF Brightness");
} }
public void TUFKeyboardRGB(int mode, Color color, int speed, string? log = "TUF RGB") public void TUFKeyboardRGB(AuraMode mode, Color color, int speed, string? log = "TUF RGB")
{ {
byte[] setting = new byte[6]; byte[] setting = new byte[6];

View File

@@ -699,8 +699,8 @@ namespace GHelper
public void InitAura() public void InitAura()
{ {
Aura.Mode = AppConfig.Get("aura_mode"); Aura.Mode = (AuraMode)AppConfig.Get("aura_mode");
Aura.Speed = AppConfig.Get("aura_speed"); Aura.Speed = (AuraSpeed)AppConfig.Get("aura_speed");
Aura.SetColor(AppConfig.Get("aura_color")); Aura.SetColor(AppConfig.Get("aura_color"));
Aura.SetColor2(AppConfig.Get("aura_color2")); Aura.SetColor2(AppConfig.Get("aura_color2"));

View File

@@ -31,27 +31,45 @@ namespace GHelper.USB
public bool ShutdownRear; public bool ShutdownRear;
} }
public enum AuraMode : int
{
AuraStatic = 0,
AuraBreathe = 1,
AuraColorCycle = 2,
AuraRainbow = 3,
Star = 4,
Rain = 5,
Highlight = 6,
Laser = 7,
Ripple = 8,
AuraStrobe = 10,
Comet = 11,
Flash = 12,
HEATMAP = 20,
GPUMODE = 21,
}
public enum AuraSpeed : int
{
Slow = 0,
Normal = 1,
Fast = 2,
}
public static class Aura public static class Aura
{ {
public const int HEATMAP = 20;
public const int GPUMODE = 21;
public static readonly byte[] LED_INIT1 = new byte[] { AsusHid.AURA_ID, 0xb9 };
public static readonly byte[] LED_INIT2 = Encoding.ASCII.GetBytes("]ASUS Tech.Inc.");
public static readonly byte[] LED_INIT3 = new byte[] { AsusHid.AURA_ID, 0x05, 0x20, 0x31, 0, 0x1a };
public static readonly byte[] LED_INIT4 = Encoding.ASCII.GetBytes("^ASUS Tech.Inc.");
public static readonly byte[] LED_INIT5 = new byte[] { 0x5e, 0x05, 0x20, 0x31, 0, 0x1a };
static byte[] MESSAGE_APPLY = { AsusHid.AURA_ID, 0xb4 }; static byte[] MESSAGE_APPLY = { AsusHid.AURA_ID, 0xb4 };
static byte[] MESSAGE_SET = { AsusHid.AURA_ID, 0xb5, 0, 0, 0 }; static byte[] MESSAGE_SET = { AsusHid.AURA_ID, 0xb5, 0, 0, 0 };
private static int mode = 0; private static AuraMode mode = AuraMode.AuraStatic;
private static int speed = 1; private static AuraSpeed speed = AuraSpeed.Normal;
public static Color Color1 = Color.White; public static Color Color1 = Color.White;
public static Color Color2 = Color.Black; public static Color Color2 = Color.Black;
static bool isTuf = AppConfig.IsTUF() || AppConfig.IsVivobook(); static bool isACPI = AppConfig.IsTUF() || AppConfig.IsVivobook();
static bool isStrix = AppConfig.IsStrix(); static bool isStrix = AppConfig.IsStrix();
static public bool isSingleColor = false; static public bool isSingleColor = false;
@@ -60,6 +78,196 @@ namespace GHelper.USB
static System.Timers.Timer timer = new System.Timers.Timer(1000); static System.Timers.Timer timer = new System.Timers.Timer(1000);
private static Dictionary<AuraMode, string> _modesSingleColor = new Dictionary<AuraMode, string>
{
{ AuraMode.AuraStatic, Properties.Strings.AuraStatic },
{ AuraMode.AuraBreathe, Properties.Strings.AuraBreathe },
{ AuraMode.AuraStrobe, Properties.Strings.AuraStrobe },
};
private static Dictionary<AuraMode, string> _modes = new Dictionary<AuraMode, string>
{
{ AuraMode.AuraStatic, Properties.Strings.AuraStatic },
{ AuraMode.AuraBreathe, Properties.Strings.AuraBreathe },
{ AuraMode.AuraColorCycle, Properties.Strings.AuraColorCycle },
{ AuraMode.AuraRainbow, Properties.Strings.AuraRainbow },
{ AuraMode.AuraStrobe, Properties.Strings.AuraStrobe },
{ AuraMode.HEATMAP, "Heatmap"},
{ AuraMode.GPUMODE, "GPU Mode" }
};
private static Dictionary<AuraMode, string> _modesStrix = new Dictionary<AuraMode, string>
{
{ AuraMode.AuraStatic, Properties.Strings.AuraStatic },
{ AuraMode.AuraBreathe, Properties.Strings.AuraBreathe },
{ AuraMode.AuraColorCycle, Properties.Strings.AuraColorCycle },
{ AuraMode.AuraRainbow, Properties.Strings.AuraRainbow },
{ AuraMode.Star, "Star" },
{ AuraMode.Rain, "Rain" },
{ AuraMode.Highlight, "Highlight" },
{ AuraMode.Laser, "Laser" },
{ AuraMode.Ripple, "Ripple" },
{ AuraMode.AuraStrobe, Properties.Strings.AuraStrobe},
{ AuraMode.Comet, "Comet" },
{ AuraMode.Flash, "Flash" },
{ AuraMode.HEATMAP, "Heatmap"},
};
static Aura()
{
timer.Elapsed += Timer_Elapsed;
isSingleColor = AppConfig.IsSingleColor(); // Mono Color
if (AppConfig.ContainsModel("GA402X") || AppConfig.ContainsModel("GA402N"))
using (var stream = AsusHid.FindHidStream(AsusHid.AURA_ID))
{
if (stream is null) return;
if (stream.Device.ReleaseNumberBcd == 22 || stream.Device.ReleaseNumberBcd == 23) isSingleColor = true;
stream.Close();
}
}
private static void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{
SetHeatmap();
}
static void SetHeatmap(bool init = false)
{
float cpuTemp = (float)HardwareControl.GetCPUTemp();
int freeze = 20, cold = 40, warm = 65, hot = 90;
Color color;
//Debug.WriteLine(cpuTemp);
if (cpuTemp < cold) color = ColorUtilities.GetWeightedAverage(Color.Blue, Color.Green, ((float)cpuTemp - freeze) / (cold - freeze));
else if (cpuTemp < warm) color = ColorUtilities.GetWeightedAverage(Color.Green, Color.Yellow, ((float)cpuTemp - cold) / (warm - cold));
else if (cpuTemp < hot) color = ColorUtilities.GetWeightedAverage(Color.Yellow, Color.Red, ((float)cpuTemp - warm) / (hot - warm));
else color = Color.Red;
ApplyColor(color, init);
}
public static Dictionary<AuraSpeed, string> GetSpeeds()
{
return new Dictionary<AuraSpeed, string>
{
{ AuraSpeed.Slow, Properties.Strings.AuraSlow },
{ AuraSpeed.Normal, Properties.Strings.AuraNormal },
{ AuraSpeed.Fast, Properties.Strings.AuraFast }
};
}
public static Dictionary<AuraMode, string> GetModes()
{
if (isACPI)
{
_modes.Remove(AuraMode.AuraRainbow);
}
if (isSingleColor)
{
return _modesSingleColor;
}
if (AppConfig.IsAdvantageEdition())
{
return _modes;
}
if (AppConfig.IsStrix() && !AppConfig.IsStrixLimitedRGB())
{
return _modesStrix;
}
return _modes;
}
public static AuraMode Mode
{
get { return mode; }
set
{
mode = GetModes().ContainsKey(value) ? value : AuraMode.AuraStatic;
}
}
public static AuraSpeed Speed
{
get { return speed; }
set
{
speed = GetSpeeds().ContainsKey(value) ? value : AuraSpeed.Normal;
}
}
public static void SetColor(int colorCode)
{
Color1 = Color.FromArgb(colorCode);
}
public static void SetColor2(int colorCode)
{
Color2 = Color.FromArgb(colorCode);
}
public static bool HasSecondColor()
{
return mode == AuraMode.AuraBreathe && !isACPI;
}
public static byte[] AuraMessage(AuraMode mode, Color color, Color color2, int speed, bool mono = false)
{
byte[] msg = new byte[17];
msg[0] = AsusHid.AURA_ID;
msg[1] = 0xb3;
msg[2] = 0x00; // Zone
msg[3] = (byte)mode; // Aura Mode
msg[4] = color.R; // R
msg[5] = mono ? (byte)0 : color.G; // G
msg[6] = mono ? (byte)0 : color.B; // B
msg[7] = (byte)speed; // aura.speed as u8;
msg[8] = 0; // aura.direction as u8;
msg[9] = mode == AuraMode.AuraBreathe ? (byte)1 : (byte)0;
msg[10] = color2.R; // R
msg[11] = mono ? (byte)0 : color2.G; // G
msg[12] = mono ? (byte)0 : color2.B; // B
return msg;
}
public static void Init()
{
Task.Run(async () =>
{
AsusHid.Write(new List<byte[]> {
new byte[] { AsusHid.AURA_ID, 0xb9 },
Encoding.ASCII.GetBytes("]ASUS Tech.Inc."),
new byte[] { AsusHid.AURA_ID, 0x05, 0x20, 0x31, 0, 0x1a },
Encoding.ASCII.GetBytes("^ASUS Tech.Inc."),
new byte[] { 0x5e, 0x05, 0x20, 0x31, 0, 0x1a }
});
});
}
public static void ApplyBrightness(int brightness, string log = "Backlight", bool delay = false)
{
Task.Run(async () =>
{
if (delay) await Task.Delay(TimeSpan.FromSeconds(1));
if (isACPI) Program.acpi.TUFKeyboardBrightness(brightness);
AsusHid.Write(new byte[] { AsusHid.AURA_ID, 0xba, 0xc5, 0xc4, (byte)brightness }, AsusHid.AURA_ID, log);
if (AppConfig.ContainsModel("GA503"))
AsusHid.Write(new byte[] { AsusHid.INPUT_ID, 0xba, 0xc5, 0xc4, (byte)brightness }, AsusHid.INPUT_ID, log);
});
}
static byte[] AuraPowerMessage(AuraPower flags) static byte[] AuraPowerMessage(AuraPower flags)
{ {
byte keyb = 0, bar = 0, lid = 0, rear = 0; byte keyb = 0, bar = 0, lid = 0, rear = 0;
@@ -101,199 +309,6 @@ namespace GHelper.USB
return new byte[] { 0x5d, 0xbd, 0x01, keyb, bar, lid, rear, 0xFF }; return new byte[] { 0x5d, 0xbd, 0x01, keyb, bar, lid, rear, 0xFF };
} }
static Aura()
{
timer.Elapsed += Timer_Elapsed;
isSingleColor = AppConfig.IsSingleColor(); // Mono Color
using (var stream = AsusHid.FindHidStream(AsusHid.AURA_ID))
{
if (stream is null) return;
if (stream.Device.ReleaseNumberBcd == 22 || stream.Device.ReleaseNumberBcd == 23 && (AppConfig.ContainsModel("GA402X") || AppConfig.ContainsModel("GA402N"))) isSingleColor = true;
stream.Close();
}
}
private static void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{
SetHeatmap();
}
static void SetHeatmap(bool init = false)
{
float cpuTemp = (float)HardwareControl.GetCPUTemp();
int freeze = 20, cold = 40, warm = 65, hot = 90;
Color color;
//Debug.WriteLine(cpuTemp);
if (cpuTemp < cold) color = ColorUtilities.GetWeightedAverage(Color.Blue, Color.Green, ((float)cpuTemp - freeze) / (cold - freeze));
else if (cpuTemp < warm) color = ColorUtilities.GetWeightedAverage(Color.Green, Color.Yellow, ((float)cpuTemp - cold) / (warm - cold));
else if (cpuTemp < hot) color = ColorUtilities.GetWeightedAverage(Color.Yellow, Color.Red, ((float)cpuTemp - warm) / (hot - warm));
else color = Color.Red;
ApplyColor(color, init);
}
public static Dictionary<int, string> GetSpeeds()
{
return new Dictionary<int, string>
{
{ 0, Properties.Strings.AuraSlow },
{ 1, Properties.Strings.AuraNormal },
{ 2, Properties.Strings.AuraFast }
};
}
static Dictionary<int, string> _modesSingleColor = new Dictionary<int, string>
{
{ 0, Properties.Strings.AuraStatic },
{ 1, Properties.Strings.AuraBreathe },
{ 10, Properties.Strings.AuraStrobe },
};
static Dictionary<int, string> _modes = new Dictionary<int, string>
{
{ 0, Properties.Strings.AuraStatic },
{ 1, Properties.Strings.AuraBreathe },
{ 2, Properties.Strings.AuraColorCycle },
{ 3, Properties.Strings.AuraRainbow },
{ 10, Properties.Strings.AuraStrobe },
{ HEATMAP, "Heatmap"},
{ GPUMODE, "GPU Mode" }
};
static Dictionary<int, string> _modesStrix = new Dictionary<int, string>
{
{ 0, Properties.Strings.AuraStatic },
{ 1, Properties.Strings.AuraBreathe },
{ 2, Properties.Strings.AuraColorCycle },
{ 3, Properties.Strings.AuraRainbow },
{ 4, "Star" },
{ 5, "Rain" },
{ 6, "Highlight" },
{ 7, "Laser" },
{ 8, "Ripple" },
{ 10, Properties.Strings.AuraStrobe},
{ 11, "Comet" },
{ 12, "Flash" },
{ HEATMAP, "Heatmap"}
};
public static Dictionary<int, string> GetModes()
{
if (isTuf)
{
_modes.Remove(3);
}
if (isSingleColor)
{
return _modesSingleColor;
}
if (AppConfig.IsAdvantageEdition())
{
return _modes;
}
if (AppConfig.IsStrix() && !AppConfig.IsStrixLimitedRGB())
{
return _modesStrix;
}
return _modes;
}
public static int Mode
{
get { return mode; }
set
{
if (GetModes().ContainsKey(value))
mode = value;
else
mode = 0;
}
}
public static bool HasSecondColor()
{
return mode == 1 && !isTuf;
}
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, bool mono = false)
{
byte[] msg = new byte[17];
msg[0] = AsusHid.AURA_ID;
msg[1] = 0xb3;
msg[2] = 0x00; // Zone
msg[3] = (byte)mode; // Aura Mode
msg[4] = color.R; // R
msg[5] = mono ? (byte)0 : color.G; // G
msg[6] = mono ? (byte)0 : color.B; // B
msg[7] = (byte)speed; // aura.speed as u8;
msg[8] = 0; // aura.direction as u8;
msg[9] = mode == 1 ? (byte)1 : (byte)0;
msg[10] = color2.R; // R
msg[11] = mono ? (byte)0 : color2.G; // G
msg[12] = mono ? (byte)0 : color2.B; // B
return msg;
}
public static void Init()
{
Task.Run(async () =>
{
AsusHid.Write(new List<byte[]> { LED_INIT1, LED_INIT2, LED_INIT3, LED_INIT4, LED_INIT5 });
});
}
public static void ApplyBrightness(int brightness, string log = "Backlight", bool delay = false)
{
Task.Run(async () =>
{
if (delay) await Task.Delay(TimeSpan.FromSeconds(1));
if (isTuf) Program.acpi.TUFKeyboardBrightness(brightness);
AsusHid.Write(new byte[] { AsusHid.AURA_ID, 0xba, 0xc5, 0xc4, (byte)brightness }, AsusHid.AURA_ID, log);
if (AppConfig.ContainsModel("GA503")) AsusHid.Write(new byte[] { AsusHid.INPUT_ID, 0xba, 0xc5, 0xc4, (byte)brightness }, AsusHid.INPUT_ID, log);
});
}
public static void ApplyPower() public static void ApplyPower()
{ {
@@ -331,7 +346,7 @@ namespace GHelper.USB
AsusHid.Write(AuraPowerMessage(flags)); AsusHid.Write(AuraPowerMessage(flags));
if (isTuf) if (isACPI)
Program.acpi.TUFKeyboardPower( Program.acpi.TUFKeyboardPower(
flags.AwakeKeyb, flags.AwakeKeyb,
flags.BootKeyb, flags.BootKeyb,
@@ -343,7 +358,7 @@ namespace GHelper.USB
public static void ApplyColor(Color color, bool init = false) public static void ApplyColor(Color color, bool init = false)
{ {
if (isTuf) if (isACPI)
{ {
Program.acpi.TUFKeyboardRGB(0, color, 0, null); Program.acpi.TUFKeyboardRGB(0, color, 0, null);
return; return;
@@ -405,7 +420,7 @@ namespace GHelper.USB
public static void ApplyGPUColor() public static void ApplyGPUColor()
{ {
if (AppConfig.Get("aura_mode") != GPUMODE) return; if ((AuraMode)AppConfig.Get("aura_mode") != AuraMode.GPUMODE) return;
switch (GPUModeControl.gpuMode) switch (GPUModeControl.gpuMode)
{ {
@@ -425,31 +440,31 @@ namespace GHelper.USB
public static void ApplyAura() public static void ApplyAura()
{ {
Mode = AppConfig.Get("aura_mode"); Mode = (AuraMode)AppConfig.Get("aura_mode");
Speed = AppConfig.Get("aura_speed"); Speed = (AuraSpeed)AppConfig.Get("aura_speed");
SetColor(AppConfig.Get("aura_color")); SetColor(AppConfig.Get("aura_color"));
SetColor2(AppConfig.Get("aura_color2")); SetColor2(AppConfig.Get("aura_color2"));
timer.Enabled = false; timer.Enabled = false;
if (Mode == HEATMAP) if (Mode == AuraMode.HEATMAP)
{ {
SetHeatmap(true); SetHeatmap(true);
timer.Enabled = true; timer.Enabled = true;
return; return;
} }
if (Mode == GPUMODE) if (Mode == AuraMode.GPUMODE)
{ {
ApplyGPUColor(); ApplyGPUColor();
return; return;
} }
int _speed = (Speed == 1) ? 0xeb : (Speed == 2) ? 0xf5 : 0xe1; int _speed = (Speed == AuraSpeed.Normal) ? 0xeb : (Speed == AuraSpeed.Fast) ? 0xf5 : 0xe1;
AsusHid.Write(new List<byte[]> { AuraMessage(Mode, Color1, Color2, _speed, isSingleColor), MESSAGE_APPLY, MESSAGE_SET }); AsusHid.Write(new List<byte[]> { AuraMessage(Mode, Color1, Color2, _speed, isSingleColor), MESSAGE_APPLY, MESSAGE_SET });
if (isTuf) if (isACPI)
Program.acpi.TUFKeyboardRGB(Mode, Color1, _speed); Program.acpi.TUFKeyboardRGB(Mode, Color1, _speed);
} }