mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Slash Lighting support for GA605
This commit is contained in:
@@ -40,9 +40,16 @@ namespace GHelper.AnimeMatrix
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (AppConfig.IsSlash())
|
if (AppConfig.IsSlash())
|
||||||
deviceSlash = new SlashDevice();
|
{
|
||||||
|
if (AppConfig.IsSlashAura())
|
||||||
|
deviceSlash = new SlashDeviceAura();
|
||||||
|
else
|
||||||
|
deviceSlash = new SlashDevice();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
deviceMatrix = new AnimeMatrixDevice();
|
deviceMatrix = new AnimeMatrixDevice();
|
||||||
|
}
|
||||||
|
|
||||||
matrixTimer = new System.Timers.Timer(100);
|
matrixTimer = new System.Timers.Timer(100);
|
||||||
matrixTimer.Elapsed += MatrixTimer_Elapsed;
|
matrixTimer.Elapsed += MatrixTimer_Elapsed;
|
||||||
@@ -103,7 +110,7 @@ namespace GHelper.AnimeMatrix
|
|||||||
|
|
||||||
deviceSlash.SetEnabled(true);
|
deviceSlash.SetEnabled(true);
|
||||||
deviceSlash.Init();
|
deviceSlash.Init();
|
||||||
|
|
||||||
switch ((SlashMode)running)
|
switch ((SlashMode)running)
|
||||||
{
|
{
|
||||||
case SlashMode.Static:
|
case SlashMode.Static:
|
||||||
@@ -111,7 +118,8 @@ namespace GHelper.AnimeMatrix
|
|||||||
if (custom is not null && custom.Length > 0)
|
if (custom is not null && custom.Length > 0)
|
||||||
{
|
{
|
||||||
deviceSlash.SetCustom(AppConfig.StringToBytes(custom));
|
deviceSlash.SetCustom(AppConfig.StringToBytes(custom));
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
deviceSlash.SetStatic(brightness);
|
deviceSlash.SetStatic(brightness);
|
||||||
}
|
}
|
||||||
@@ -137,7 +145,7 @@ namespace GHelper.AnimeMatrix
|
|||||||
public void SetLidMode(bool force = false)
|
public void SetLidMode(bool force = false)
|
||||||
{
|
{
|
||||||
bool matrixLid = AppConfig.Is("matrix_lid");
|
bool matrixLid = AppConfig.Is("matrix_lid");
|
||||||
|
|
||||||
if (deviceSlash is not null)
|
if (deviceSlash is not null)
|
||||||
{
|
{
|
||||||
deviceSlash.SetLidMode(true);
|
deviceSlash.SetLidMode(true);
|
||||||
@@ -268,8 +276,8 @@ namespace GHelper.AnimeMatrix
|
|||||||
StartMatrixTimer(1000);
|
StartMatrixTimer(1000);
|
||||||
Logger.WriteLine("Matrix Clock");
|
Logger.WriteLine("Matrix Clock");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void SlashTimer_start(int interval = 60000)
|
private void SlashTimer_start(int interval = 60000)
|
||||||
{
|
{
|
||||||
// 100% to 0% in 1hr = 1% every 36 seconds
|
// 100% to 0% in 1hr = 1% every 36 seconds
|
||||||
@@ -279,18 +287,18 @@ namespace GHelper.AnimeMatrix
|
|||||||
|
|
||||||
// create the timer if first call
|
// create the timer if first call
|
||||||
// this way, the timer only spawns if user tries to use battery pattern
|
// this way, the timer only spawns if user tries to use battery pattern
|
||||||
if(slashTimer == default(System.Timers.Timer))
|
if (slashTimer == default(System.Timers.Timer))
|
||||||
{
|
{
|
||||||
slashTimer = new System.Timers.Timer(interval);
|
slashTimer = new System.Timers.Timer(interval);
|
||||||
slashTimer.Elapsed += SlashTimer_elapsed;
|
slashTimer.Elapsed += SlashTimer_elapsed;
|
||||||
slashTimer.AutoReset = true;
|
slashTimer.AutoReset = true;
|
||||||
}
|
}
|
||||||
// only write if interval changed
|
// only write if interval changed
|
||||||
if(slashTimer.Interval != interval)
|
if (slashTimer.Interval != interval)
|
||||||
{
|
{
|
||||||
slashTimer.Interval = interval;
|
slashTimer.Interval = interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
slashTimer.Start();
|
slashTimer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,7 +312,7 @@ namespace GHelper.AnimeMatrix
|
|||||||
if (deviceSlash is null) return;
|
if (deviceSlash is null) return;
|
||||||
|
|
||||||
//kill timer if called but not in battery pattern mode
|
//kill timer if called but not in battery pattern mode
|
||||||
if((SlashMode)AppConfig.Get("matrix_running", 0) != SlashMode.BatteryLevel)
|
if ((SlashMode)AppConfig.Get("matrix_running", 0) != SlashMode.BatteryLevel)
|
||||||
{
|
{
|
||||||
slashTimer.Stop();
|
slashTimer.Stop();
|
||||||
slashTimer.Dispose();
|
slashTimer.Dispose();
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using GHelper.AnimeMatrix.Communication;
|
using GHelper.AnimeMatrix.Communication;
|
||||||
using System.Management;
|
using System.Management;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Timers;
|
|
||||||
|
|
||||||
namespace GHelper.AnimeMatrix
|
namespace GHelper.AnimeMatrix
|
||||||
{
|
{
|
||||||
@@ -26,16 +25,16 @@ namespace GHelper.AnimeMatrix
|
|||||||
BatteryLevel,
|
BatteryLevel,
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class SlashPacket : Packet
|
|
||||||
{
|
|
||||||
public SlashPacket(byte[] command) : base(0x5E, 128, command)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SlashDevice : Device
|
public class SlashDevice : Device
|
||||||
{
|
{
|
||||||
|
|
||||||
|
internal class SlashPacket : Packet
|
||||||
|
{
|
||||||
|
public SlashPacket(byte[] command) : base(0x5E, 128, command)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Dictionary<SlashMode, string> Modes = new Dictionary<SlashMode, string>
|
public static Dictionary<SlashMode, string> Modes = new Dictionary<SlashMode, string>
|
||||||
{
|
{
|
||||||
{ SlashMode.Bounce, "Bounce"},
|
{ SlashMode.Bounce, "Bounce"},
|
||||||
@@ -85,7 +84,7 @@ namespace GHelper.AnimeMatrix
|
|||||||
{ SlashMode.Buzzer, 0x44},
|
{ SlashMode.Buzzer, 0x44},
|
||||||
};
|
};
|
||||||
|
|
||||||
public SlashDevice() : base(0x0B05, 0x193B, 128)
|
public SlashDevice(ushort productId = 0x193B) : base(0x0B05, productId, 128)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,23 +134,23 @@ namespace GHelper.AnimeMatrix
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static double GetBatteryChargePercentage()
|
public static double GetBatteryChargePercentage()
|
||||||
|
{
|
||||||
|
double batteryCharge = 0;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
double batteryCharge = 0;
|
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Battery");
|
||||||
try
|
foreach (ManagementObject battery in searcher.Get())
|
||||||
{
|
{
|
||||||
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Battery");
|
batteryCharge = Convert.ToDouble(battery["EstimatedChargeRemaining"]);
|
||||||
foreach (ManagementObject battery in searcher.Get())
|
break; // Assuming only one battery
|
||||||
{
|
|
||||||
batteryCharge = Convert.ToDouble(battery["EstimatedChargeRemaining"]);
|
|
||||||
break; // Assuming only one battery
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (ManagementException e)
|
|
||||||
{
|
|
||||||
Console.WriteLine("An error occurred while querying for WMI data: " + e.Message);
|
|
||||||
}
|
|
||||||
return batteryCharge;
|
|
||||||
}
|
}
|
||||||
|
catch (ManagementException e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("An error occurred while querying for WMI data: " + e.Message);
|
||||||
|
}
|
||||||
|
return batteryCharge;
|
||||||
|
}
|
||||||
|
|
||||||
private byte[] GetBatteryPattern(int brightness, double percentage)
|
private byte[] GetBatteryPattern(int brightness, double percentage)
|
||||||
{
|
{
|
||||||
@@ -159,23 +158,23 @@ namespace GHelper.AnimeMatrix
|
|||||||
// set brightness to reflect battery's percentage within that range
|
// set brightness to reflect battery's percentage within that range
|
||||||
|
|
||||||
int bracket = (int)Math.Floor(percentage / 14.2857);
|
int bracket = (int)Math.Floor(percentage / 14.2857);
|
||||||
if(bracket >= 7) return Enumerable.Repeat((byte)(brightness * 85.333), 7).ToArray();
|
if (bracket >= 7) return Enumerable.Repeat((byte)(brightness * 85.333), 7).ToArray();
|
||||||
|
|
||||||
byte[] batteryPattern = Enumerable.Repeat((byte)(0x00), 7).ToArray();
|
byte[] batteryPattern = Enumerable.Repeat((byte)(0x00), 7).ToArray();
|
||||||
for (int i = 6; i > 6-bracket; i--)
|
for (int i = 6; i > 6 - bracket; i--)
|
||||||
{
|
{
|
||||||
batteryPattern[i] = (byte)(brightness * 85.333);
|
batteryPattern[i] = (byte)(brightness * 85.333);
|
||||||
}
|
}
|
||||||
|
|
||||||
//set the "selected" bracket to the percentage of that bracket filled from 0 to 255 as a hex
|
//set the "selected" bracket to the percentage of that bracket filled from 0 to 255 as a hex
|
||||||
batteryPattern[6-bracket] = (byte)(((percentage % 14.2857) * brightness * 85.333) / 14.2857);
|
batteryPattern[6 - bracket] = (byte)(((percentage % 14.2857) * brightness * 85.333) / 14.2857);
|
||||||
|
|
||||||
return batteryPattern;
|
return batteryPattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetBatteryPattern(int brightness)
|
public void SetBatteryPattern(int brightness)
|
||||||
{
|
{
|
||||||
SetCustom(GetBatteryPattern(brightness, 100*(GetBatteryChargePercentage()/AppConfig.Get("charge_limit",100))));
|
SetCustom(GetBatteryPattern(brightness, 100 * (GetBatteryChargePercentage() / AppConfig.Get("charge_limit", 100))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCustom(byte[] data)
|
public void SetCustom(byte[] data)
|
||||||
@@ -214,9 +213,22 @@ namespace GHelper.AnimeMatrix
|
|||||||
public void Set(Packet packet, string? log = null)
|
public void Set(Packet packet, string? log = null)
|
||||||
{
|
{
|
||||||
_usbProvider?.Set(packet.Data);
|
_usbProvider?.Set(packet.Data);
|
||||||
if (log is not null) Logger.WriteLine($"{log}:" + BitConverter.ToString(packet.Data).Substring(0,48));
|
if (log is not null) Logger.WriteLine($"{log}:" + BitConverter.ToString(packet.Data).Substring(0, 48));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SlashDeviceAura : SlashDevice
|
||||||
|
{
|
||||||
|
public SlashDeviceAura(): base(0x193B)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal new class SlashPacket : Packet
|
||||||
|
{
|
||||||
|
public SlashPacket(byte[] command) : base(0x5D, 128, command)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,6 +405,11 @@ public static class AppConfig
|
|||||||
return ContainsModel("GA403") || ContainsModel("GU605") || ContainsModel("GA605");
|
return ContainsModel("GA403") || ContainsModel("GU605") || ContainsModel("GA605");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsSlashAura()
|
||||||
|
{
|
||||||
|
return ContainsModel("GA605");
|
||||||
|
}
|
||||||
|
|
||||||
public static bool IsInputBacklight()
|
public static bool IsInputBacklight()
|
||||||
{
|
{
|
||||||
return ContainsModel("GA503") || IsSlash();
|
return ContainsModel("GA503") || IsSlash();
|
||||||
@@ -583,7 +588,7 @@ public static class AppConfig
|
|||||||
|
|
||||||
public static bool IsFanRequired()
|
public static bool IsFanRequired()
|
||||||
{
|
{
|
||||||
return ContainsModel("GA402X") || ContainsModel("G513") || ContainsModel("G713R") || ContainsModel("G713P") || ContainsModel("GU605") || ContainsModel("GA605") || ContainsModel("GA403") || ContainsModel("G634J") || ContainsModel("G834J") || ContainsModel("G614J") || ContainsModel("G814J") || ContainsModel("FX507V");
|
return ContainsModel("GA402X") || ContainsModel("G513") || ContainsModel("G713R") || ContainsModel("G713P") || ContainsModel("GU605") || ContainsModel("GA403") || ContainsModel("G634J") || ContainsModel("G834J") || ContainsModel("G614J") || ContainsModel("G814J") || ContainsModel("FX507V");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsAMDLight()
|
public static bool IsAMDLight()
|
||||||
|
|||||||
Reference in New Issue
Block a user