mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Slash Lightning
This commit is contained in:
@@ -15,14 +15,16 @@ namespace GHelper.AnimeMatrix
|
|||||||
SettingsForm settings;
|
SettingsForm settings;
|
||||||
|
|
||||||
System.Timers.Timer matrixTimer = default!;
|
System.Timers.Timer matrixTimer = default!;
|
||||||
public AnimeMatrixDevice? device;
|
|
||||||
|
public AnimeMatrixDevice? deviceMatrix;
|
||||||
|
public SlashDevice? deviceSlash;
|
||||||
|
|
||||||
double[]? AudioValues;
|
double[]? AudioValues;
|
||||||
WasapiCapture? AudioDevice;
|
WasapiCapture? AudioDevice;
|
||||||
string? AudioDeviceId;
|
string? AudioDeviceId;
|
||||||
private MMDeviceEnumerator? AudioDeviceEnum;
|
private MMDeviceEnumerator? AudioDeviceEnum;
|
||||||
|
|
||||||
public bool IsValid => device != null;
|
public bool IsValid => deviceMatrix != null || deviceSlash != null;
|
||||||
|
|
||||||
private long lastPresent;
|
private long lastPresent;
|
||||||
private List<double> maxes = new List<double>();
|
private List<double> maxes = new List<double>();
|
||||||
@@ -33,31 +35,87 @@ namespace GHelper.AnimeMatrix
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
device = new AnimeMatrixDevice();
|
deviceMatrix = new AnimeMatrixDevice();
|
||||||
Task.Run(device.WakeUp);
|
|
||||||
matrixTimer = new System.Timers.Timer(100);
|
|
||||||
matrixTimer.Elapsed += MatrixTimer_Elapsed;
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
device = null;
|
deviceMatrix = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (AppConfig.ContainsModel("GA403"))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
deviceSlash = new SlashDevice();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
deviceSlash = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsValid)
|
||||||
|
{
|
||||||
|
matrixTimer = new System.Timers.Timer(100);
|
||||||
|
matrixTimer.Elapsed += MatrixTimer_Elapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetDevice(bool wakeUp = false)
|
||||||
|
{
|
||||||
|
if (deviceMatrix is not null) SetMatrix(wakeUp);
|
||||||
|
if (deviceSlash is not null) SetSlash(wakeUp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void SetSlash(bool wakeUp = false)
|
||||||
|
{
|
||||||
|
if (deviceSlash is null) return;
|
||||||
|
|
||||||
|
int brightness = AppConfig.Get("matrix_brightness", 0);
|
||||||
|
int running = AppConfig.Get("matrix_running", 0);
|
||||||
|
bool auto = AppConfig.Is("matrix_auto");
|
||||||
|
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
deviceSlash.SetProvider();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.WriteLine(ex.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wakeUp) deviceSlash.WakeUp();
|
||||||
|
|
||||||
|
if (brightness == 0 || (auto && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online))
|
||||||
|
{
|
||||||
|
deviceSlash.Init();
|
||||||
|
deviceSlash.SetOptions(false);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
deviceSlash.Init();
|
||||||
|
deviceSlash.SetMode((SlashMode)running);
|
||||||
|
deviceSlash.SetOptions(false, (byte)(brightness*85.333), 0);
|
||||||
|
deviceSlash.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetMatrix(bool wakeUp = false)
|
public void SetMatrix(bool wakeUp = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!IsValid) return;
|
if (deviceMatrix is null) return;
|
||||||
|
|
||||||
int brightness = AppConfig.Get("matrix_brightness");
|
|
||||||
int running = AppConfig.Get("matrix_running");
|
|
||||||
|
|
||||||
|
int brightness = AppConfig.Get("matrix_brightness", 0);
|
||||||
|
int running = AppConfig.Get("matrix_running", 0);
|
||||||
bool auto = AppConfig.Is("matrix_auto");
|
bool auto = AppConfig.Is("matrix_auto");
|
||||||
|
|
||||||
if (brightness < 0) brightness = 0;
|
|
||||||
if (running < 0) running = 0;
|
|
||||||
|
|
||||||
BuiltInAnimation animation = new BuiltInAnimation(
|
BuiltInAnimation animation = new BuiltInAnimation(
|
||||||
(BuiltInAnimation.Running)running,
|
(BuiltInAnimation.Running)running,
|
||||||
BuiltInAnimation.Sleeping.Starfield,
|
BuiltInAnimation.Sleeping.Starfield,
|
||||||
@@ -72,7 +130,7 @@ namespace GHelper.AnimeMatrix
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
device.SetProvider();
|
deviceMatrix.SetProvider();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -80,18 +138,18 @@ namespace GHelper.AnimeMatrix
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wakeUp) device.WakeUp();
|
if (wakeUp) deviceMatrix.WakeUp();
|
||||||
|
|
||||||
if (brightness == 0 || (auto && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online))
|
if (brightness == 0 || (auto && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online))
|
||||||
{
|
{
|
||||||
device.SetDisplayState(false);
|
deviceMatrix.SetDisplayState(false);
|
||||||
device.SetDisplayState(false); // some devices are dumb
|
deviceMatrix.SetDisplayState(false); // some devices are dumb
|
||||||
Logger.WriteLine("Matrix Off");
|
Logger.WriteLine("Matrix Off");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
device.SetDisplayState(true);
|
deviceMatrix.SetDisplayState(true);
|
||||||
device.SetBrightness((BrightnessMode)brightness);
|
deviceMatrix.SetBrightness((BrightnessMode)brightness);
|
||||||
|
|
||||||
switch (running)
|
switch (running)
|
||||||
{
|
{
|
||||||
@@ -105,7 +163,7 @@ namespace GHelper.AnimeMatrix
|
|||||||
SetMatrixAudio();
|
SetMatrixAudio();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
device.SetBuiltInAnimation(true, animation);
|
deviceMatrix.SetBuiltInAnimation(true, animation);
|
||||||
Logger.WriteLine("Matrix builtin " + animation.AsByte);
|
Logger.WriteLine("Matrix builtin " + animation.AsByte);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -134,10 +192,10 @@ namespace GHelper.AnimeMatrix
|
|||||||
switch (AppConfig.Get("matrix_running"))
|
switch (AppConfig.Get("matrix_running"))
|
||||||
{
|
{
|
||||||
case 2:
|
case 2:
|
||||||
device.PresentNextFrame();
|
deviceMatrix.PresentNextFrame();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
device.PresentClock();
|
deviceMatrix.PresentClock();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +204,7 @@ namespace GHelper.AnimeMatrix
|
|||||||
|
|
||||||
public void SetMatrixClock()
|
public void SetMatrixClock()
|
||||||
{
|
{
|
||||||
device.SetBuiltInAnimation(false);
|
deviceMatrix.SetBuiltInAnimation(false);
|
||||||
StartMatrixTimer(1000);
|
StartMatrixTimer(1000);
|
||||||
Logger.WriteLine("Matrix Clock");
|
Logger.WriteLine("Matrix Clock");
|
||||||
}
|
}
|
||||||
@@ -179,7 +237,7 @@ namespace GHelper.AnimeMatrix
|
|||||||
{
|
{
|
||||||
if (!IsValid) return;
|
if (!IsValid) return;
|
||||||
|
|
||||||
device.SetBuiltInAnimation(false);
|
deviceMatrix.SetBuiltInAnimation(false);
|
||||||
StopMatrixTimer();
|
StopMatrixTimer();
|
||||||
StopMatrixAudio();
|
StopMatrixAudio();
|
||||||
|
|
||||||
@@ -251,8 +309,8 @@ namespace GHelper.AnimeMatrix
|
|||||||
for (int x = 0; x < 2 - (y % 2); x++)
|
for (int x = 0; x < 2 - (y % 2); x++)
|
||||||
{
|
{
|
||||||
//color = (byte)(Math.Min(1,(h - y - 2)*2) * 255);
|
//color = (byte)(Math.Min(1,(h - y - 2)*2) * 255);
|
||||||
device.SetLedPlanar(x + dx, dy + y, (byte)(h * 255 / 30));
|
deviceMatrix.SetLedPlanar(x + dx, dy + y, (byte)(h * 255 / 30));
|
||||||
device.SetLedPlanar(x + dx, dy - y, 255);
|
deviceMatrix.SetLedPlanar(x + dx, dy - y, 255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +320,7 @@ namespace GHelper.AnimeMatrix
|
|||||||
if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastPresent) < 70) return;
|
if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastPresent) < 70) return;
|
||||||
lastPresent = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
lastPresent = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||||
|
|
||||||
device.Clear();
|
deviceMatrix.Clear();
|
||||||
|
|
||||||
int size = 20;
|
int size = 20;
|
||||||
double[] bars = new double[size];
|
double[] bars = new double[size];
|
||||||
@@ -280,7 +338,7 @@ namespace GHelper.AnimeMatrix
|
|||||||
|
|
||||||
for (int i = 0; i < size; i++) DrawBar(20 - i, bars[i] * 20 / maxAverage);
|
for (int i = 0; i < size; i++) DrawBar(20 - i, bars[i] * 20 / maxAverage);
|
||||||
|
|
||||||
device.Present();
|
deviceMatrix.Present();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -351,8 +409,8 @@ namespace GHelper.AnimeMatrix
|
|||||||
|
|
||||||
protected void ProcessPicture(Image image)
|
protected void ProcessPicture(Image image)
|
||||||
{
|
{
|
||||||
device.SetBuiltInAnimation(false);
|
deviceMatrix.SetBuiltInAnimation(false);
|
||||||
device.ClearFrames();
|
deviceMatrix.ClearFrames();
|
||||||
|
|
||||||
int matrixX = AppConfig.Get("matrix_x", 0);
|
int matrixX = AppConfig.Get("matrix_x", 0);
|
||||||
int matrixY = AppConfig.Get("matrix_y", 0);
|
int matrixY = AppConfig.Get("matrix_y", 0);
|
||||||
@@ -380,11 +438,11 @@ namespace GHelper.AnimeMatrix
|
|||||||
image.SelectActiveFrame(dimension, i);
|
image.SelectActiveFrame(dimension, i);
|
||||||
|
|
||||||
if (rotation == MatrixRotation.Planar)
|
if (rotation == MatrixRotation.Planar)
|
||||||
device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);
|
deviceMatrix.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);
|
||||||
else
|
else
|
||||||
device.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);
|
deviceMatrix.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);
|
||||||
|
|
||||||
device.AddFrame();
|
deviceMatrix.AddFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -397,11 +455,11 @@ namespace GHelper.AnimeMatrix
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (rotation == MatrixRotation.Planar)
|
if (rotation == MatrixRotation.Planar)
|
||||||
device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);
|
deviceMatrix.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);
|
||||||
else
|
else
|
||||||
device.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);
|
deviceMatrix.GenerateFrameDiagonal(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);
|
||||||
|
|
||||||
device.Present();
|
deviceMatrix.Present();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,9 +36,10 @@ namespace GHelper.AnimeMatrix.Communication.Platform
|
|||||||
{
|
{
|
||||||
HidDevice = DeviceList.Local
|
HidDevice = DeviceList.Local
|
||||||
.GetHidDevices(vendorId, productId)
|
.GetHidDevices(vendorId, productId)
|
||||||
.First(x => x.GetMaxFeatureReportLength() == maxFeatureReportLength);
|
.First(x => x.GetMaxFeatureReportLength() >= maxFeatureReportLength);
|
||||||
|
|
||||||
Logger.WriteLine("Matrix Device: " + HidDevice.DevicePath);
|
Logger.WriteLine("Matrix Device: " + HidDevice.DevicePath);
|
||||||
|
Logger.WriteLine("Matrix Features: " + HidDevice.GetMaxFeatureReportLength());
|
||||||
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|||||||
62
app/AnimeMatrix/SlashDevice.cs
Normal file
62
app/AnimeMatrix/SlashDevice.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
using GHelper.AnimeMatrix.Communication;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace GHelper.AnimeMatrix
|
||||||
|
{
|
||||||
|
public enum SlashMode
|
||||||
|
{
|
||||||
|
Transmission,
|
||||||
|
Bitstream
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class SlashPacket : Packet
|
||||||
|
{
|
||||||
|
public SlashPacket(byte[] command) : base(0x5E, 128, command)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SlashDevice : Device
|
||||||
|
{
|
||||||
|
public SlashDevice() : base(0x0B05, 0x193B, 640) // 128
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WakeUp()
|
||||||
|
{
|
||||||
|
Set(Packet<SlashPacket>(Encoding.ASCII.GetBytes("ASUS Tech.Inc.")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init()
|
||||||
|
{
|
||||||
|
Set(Packet<SlashPacket>(0xD7, 0x00, 0x00, 0x01, 0xAC));
|
||||||
|
Set(Packet<SlashPacket>(0xD2, 0x02, 0x01, 0x08, 0xAB));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
{
|
||||||
|
Set(Packet<SlashPacket>(0xD4, 0x00, 0x00, 0x01, 0xAB));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetMode(SlashMode mode)
|
||||||
|
{
|
||||||
|
Set(Packet<SlashPacket>(0xD2, 0x03, 0x00, 0x0C));
|
||||||
|
Set(Packet<SlashPacket>(0xD3, 0x04, 0x00, 0x0C, 0x01, (mode == SlashMode.Bitstream) ? (byte)0x1D : (byte)0x1A, 0x02, 0x19, 0x03, 0x13, 0x04, 0x11, 0x05, 0x12, 0x06, 0x13));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetOptions(bool status, byte brightness = 0xFF, byte interval = 0x00)
|
||||||
|
{
|
||||||
|
Set(Packet<SlashPacket>(0xD3, 0x03, 0x01, 0x08, 0xAB, 0xFF, 0x01, status ? (byte)0x01 : (byte)0x00, 0x06, brightness, 0xFF, interval));
|
||||||
|
Save();
|
||||||
|
Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Set(Packet packet)
|
||||||
|
{
|
||||||
|
_usbProvider?.Set(packet.Data);
|
||||||
|
Logger.WriteLine("Slash:" + BitConverter.ToString(packet.Data));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -62,8 +62,8 @@ namespace GHelper
|
|||||||
comboRotation.SelectedValueChanged += ComboRotation_SelectedValueChanged; ;
|
comboRotation.SelectedValueChanged += ComboRotation_SelectedValueChanged; ;
|
||||||
|
|
||||||
|
|
||||||
uiScale = panelPicture.Width / matrixControl.device.MaxColumns / 3;
|
uiScale = panelPicture.Width / matrixControl.deviceMatrix.MaxColumns / 3;
|
||||||
panelPicture.Height = (int)(matrixControl.device.MaxRows * uiScale);
|
panelPicture.Height = (int)(matrixControl.deviceMatrix.MaxRows * uiScale);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ namespace GHelper
|
|||||||
|
|
||||||
BatteryControl.AutoBattery(init);
|
BatteryControl.AutoBattery(init);
|
||||||
|
|
||||||
settingsForm.matrixControl.SetMatrix(true);
|
settingsForm.matrixControl.SetDevice(true);
|
||||||
|
|
||||||
if (AppConfig.IsAlly())
|
if (AppConfig.IsAlly())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -686,7 +686,7 @@ namespace GHelper
|
|||||||
private void CheckMatrix_CheckedChanged(object? sender, EventArgs e)
|
private void CheckMatrix_CheckedChanged(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
AppConfig.Set("matrix_auto", checkMatrix.Checked ? 1 : 0);
|
AppConfig.Set("matrix_auto", checkMatrix.Checked ? 1 : 0);
|
||||||
matrixControl.SetMatrix();
|
matrixControl.SetDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -724,14 +724,14 @@ namespace GHelper
|
|||||||
private void ComboMatrixRunning_SelectedValueChanged(object? sender, EventArgs e)
|
private void ComboMatrixRunning_SelectedValueChanged(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
AppConfig.Set("matrix_running", comboMatrixRunning.SelectedIndex);
|
AppConfig.Set("matrix_running", comboMatrixRunning.SelectedIndex);
|
||||||
matrixControl.SetMatrix();
|
matrixControl.SetDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void ComboMatrix_SelectedValueChanged(object? sender, EventArgs e)
|
private void ComboMatrix_SelectedValueChanged(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
AppConfig.Set("matrix_brightness", comboMatrix.SelectedIndex);
|
AppConfig.Set("matrix_brightness", comboMatrix.SelectedIndex);
|
||||||
matrixControl.SetMatrix();
|
matrixControl.SetDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -896,6 +896,15 @@ namespace GHelper
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (matrixControl.deviceSlash is not null)
|
||||||
|
{
|
||||||
|
labelMatrix.Text = "Slash Lightning";
|
||||||
|
comboMatrixRunning.Items.Clear();
|
||||||
|
comboMatrixRunning.Items.Add("Transmission");
|
||||||
|
comboMatrixRunning.Items.Add("Bitstream");
|
||||||
|
buttonMatrix.Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
comboMatrix.SelectedIndex = Math.Min(AppConfig.Get("matrix_brightness", 0), comboMatrix.Items.Count - 1);
|
comboMatrix.SelectedIndex = Math.Min(AppConfig.Get("matrix_brightness", 0), comboMatrix.Items.Count - 1);
|
||||||
comboMatrixRunning.SelectedIndex = Math.Min(AppConfig.Get("matrix_running", 0), comboMatrixRunning.Items.Count - 1);
|
comboMatrixRunning.SelectedIndex = Math.Min(AppConfig.Get("matrix_running", 0), comboMatrixRunning.Items.Count - 1);
|
||||||
|
|
||||||
@@ -909,7 +918,7 @@ namespace GHelper
|
|||||||
{
|
{
|
||||||
comboMatrix.SelectedIndex = Math.Min(Math.Max(0, comboMatrix.SelectedIndex + delta), comboMatrix.Items.Count - 1);
|
comboMatrix.SelectedIndex = Math.Min(Math.Max(0, comboMatrix.SelectedIndex + delta), comboMatrix.Items.Count - 1);
|
||||||
AppConfig.Set("matrix_brightness", comboMatrix.SelectedIndex);
|
AppConfig.Set("matrix_brightness", comboMatrix.SelectedIndex);
|
||||||
matrixControl.SetMatrix();
|
matrixControl.SetDevice();
|
||||||
Program.toast.RunToast(comboMatrix.GetItemText(comboMatrix.SelectedItem), delta > 0 ? ToastIcon.BacklightUp : ToastIcon.BacklightDown);
|
Program.toast.RunToast(comboMatrix.GetItemText(comboMatrix.SelectedItem), delta > 0 ? ToastIcon.BacklightUp : ToastIcon.BacklightDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user