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;
|
||||
|
||||
System.Timers.Timer matrixTimer = default!;
|
||||
public AnimeMatrixDevice? device;
|
||||
|
||||
public AnimeMatrixDevice? deviceMatrix;
|
||||
public SlashDevice? deviceSlash;
|
||||
|
||||
double[]? AudioValues;
|
||||
WasapiCapture? AudioDevice;
|
||||
string? AudioDeviceId;
|
||||
private MMDeviceEnumerator? AudioDeviceEnum;
|
||||
|
||||
public bool IsValid => device != null;
|
||||
public bool IsValid => deviceMatrix != null || deviceSlash != null;
|
||||
|
||||
private long lastPresent;
|
||||
private List<double> maxes = new List<double>();
|
||||
@@ -33,31 +35,87 @@ namespace GHelper.AnimeMatrix
|
||||
|
||||
try
|
||||
{
|
||||
device = new AnimeMatrixDevice();
|
||||
Task.Run(device.WakeUp);
|
||||
matrixTimer = new System.Timers.Timer(100);
|
||||
matrixTimer.Elapsed += MatrixTimer_Elapsed;
|
||||
deviceMatrix = new AnimeMatrixDevice();
|
||||
}
|
||||
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)
|
||||
{
|
||||
|
||||
if (!IsValid) return;
|
||||
|
||||
int brightness = AppConfig.Get("matrix_brightness");
|
||||
int running = AppConfig.Get("matrix_running");
|
||||
if (deviceMatrix is null) return;
|
||||
|
||||
int brightness = AppConfig.Get("matrix_brightness", 0);
|
||||
int running = AppConfig.Get("matrix_running", 0);
|
||||
bool auto = AppConfig.Is("matrix_auto");
|
||||
|
||||
if (brightness < 0) brightness = 0;
|
||||
if (running < 0) running = 0;
|
||||
|
||||
BuiltInAnimation animation = new BuiltInAnimation(
|
||||
(BuiltInAnimation.Running)running,
|
||||
BuiltInAnimation.Sleeping.Starfield,
|
||||
@@ -72,7 +130,7 @@ namespace GHelper.AnimeMatrix
|
||||
{
|
||||
try
|
||||
{
|
||||
device.SetProvider();
|
||||
deviceMatrix.SetProvider();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -80,18 +138,18 @@ namespace GHelper.AnimeMatrix
|
||||
return;
|
||||
}
|
||||
|
||||
if (wakeUp) device.WakeUp();
|
||||
if (wakeUp) deviceMatrix.WakeUp();
|
||||
|
||||
if (brightness == 0 || (auto && SystemInformation.PowerStatus.PowerLineStatus != PowerLineStatus.Online))
|
||||
{
|
||||
device.SetDisplayState(false);
|
||||
device.SetDisplayState(false); // some devices are dumb
|
||||
deviceMatrix.SetDisplayState(false);
|
||||
deviceMatrix.SetDisplayState(false); // some devices are dumb
|
||||
Logger.WriteLine("Matrix Off");
|
||||
}
|
||||
else
|
||||
{
|
||||
device.SetDisplayState(true);
|
||||
device.SetBrightness((BrightnessMode)brightness);
|
||||
deviceMatrix.SetDisplayState(true);
|
||||
deviceMatrix.SetBrightness((BrightnessMode)brightness);
|
||||
|
||||
switch (running)
|
||||
{
|
||||
@@ -105,7 +163,7 @@ namespace GHelper.AnimeMatrix
|
||||
SetMatrixAudio();
|
||||
break;
|
||||
default:
|
||||
device.SetBuiltInAnimation(true, animation);
|
||||
deviceMatrix.SetBuiltInAnimation(true, animation);
|
||||
Logger.WriteLine("Matrix builtin " + animation.AsByte);
|
||||
break;
|
||||
}
|
||||
@@ -134,10 +192,10 @@ namespace GHelper.AnimeMatrix
|
||||
switch (AppConfig.Get("matrix_running"))
|
||||
{
|
||||
case 2:
|
||||
device.PresentNextFrame();
|
||||
deviceMatrix.PresentNextFrame();
|
||||
break;
|
||||
case 3:
|
||||
device.PresentClock();
|
||||
deviceMatrix.PresentClock();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -146,7 +204,7 @@ namespace GHelper.AnimeMatrix
|
||||
|
||||
public void SetMatrixClock()
|
||||
{
|
||||
device.SetBuiltInAnimation(false);
|
||||
deviceMatrix.SetBuiltInAnimation(false);
|
||||
StartMatrixTimer(1000);
|
||||
Logger.WriteLine("Matrix Clock");
|
||||
}
|
||||
@@ -179,7 +237,7 @@ namespace GHelper.AnimeMatrix
|
||||
{
|
||||
if (!IsValid) return;
|
||||
|
||||
device.SetBuiltInAnimation(false);
|
||||
deviceMatrix.SetBuiltInAnimation(false);
|
||||
StopMatrixTimer();
|
||||
StopMatrixAudio();
|
||||
|
||||
@@ -251,8 +309,8 @@ namespace GHelper.AnimeMatrix
|
||||
for (int x = 0; x < 2 - (y % 2); x++)
|
||||
{
|
||||
//color = (byte)(Math.Min(1,(h - y - 2)*2) * 255);
|
||||
device.SetLedPlanar(x + dx, dy + y, (byte)(h * 255 / 30));
|
||||
device.SetLedPlanar(x + dx, dy - y, 255);
|
||||
deviceMatrix.SetLedPlanar(x + dx, dy + y, (byte)(h * 255 / 30));
|
||||
deviceMatrix.SetLedPlanar(x + dx, dy - y, 255);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,7 +320,7 @@ namespace GHelper.AnimeMatrix
|
||||
if (Math.Abs(DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastPresent) < 70) return;
|
||||
lastPresent = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
|
||||
device.Clear();
|
||||
deviceMatrix.Clear();
|
||||
|
||||
int size = 20;
|
||||
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);
|
||||
|
||||
device.Present();
|
||||
deviceMatrix.Present();
|
||||
}
|
||||
|
||||
|
||||
@@ -351,8 +409,8 @@ namespace GHelper.AnimeMatrix
|
||||
|
||||
protected void ProcessPicture(Image image)
|
||||
{
|
||||
device.SetBuiltInAnimation(false);
|
||||
device.ClearFrames();
|
||||
deviceMatrix.SetBuiltInAnimation(false);
|
||||
deviceMatrix.ClearFrames();
|
||||
|
||||
int matrixX = AppConfig.Get("matrix_x", 0);
|
||||
int matrixY = AppConfig.Get("matrix_y", 0);
|
||||
@@ -380,11 +438,11 @@ namespace GHelper.AnimeMatrix
|
||||
image.SelectActiveFrame(dimension, i);
|
||||
|
||||
if (rotation == MatrixRotation.Planar)
|
||||
device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);
|
||||
deviceMatrix.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);
|
||||
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
|
||||
{
|
||||
if (rotation == MatrixRotation.Planar)
|
||||
device.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);
|
||||
deviceMatrix.GenerateFrame(image, matrixZoom, matrixX, matrixY, matrixQuality, matrixContrast);
|
||||
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
|
||||
.GetHidDevices(vendorId, productId)
|
||||
.First(x => x.GetMaxFeatureReportLength() == maxFeatureReportLength);
|
||||
.First(x => x.GetMaxFeatureReportLength() >= maxFeatureReportLength);
|
||||
|
||||
Logger.WriteLine("Matrix Device: " + HidDevice.DevicePath);
|
||||
Logger.WriteLine("Matrix Features: " + HidDevice.GetMaxFeatureReportLength());
|
||||
|
||||
}
|
||||
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; ;
|
||||
|
||||
|
||||
uiScale = panelPicture.Width / matrixControl.device.MaxColumns / 3;
|
||||
panelPicture.Height = (int)(matrixControl.device.MaxRows * uiScale);
|
||||
uiScale = panelPicture.Width / matrixControl.deviceMatrix.MaxColumns / 3;
|
||||
panelPicture.Height = (int)(matrixControl.deviceMatrix.MaxRows * uiScale);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ namespace GHelper
|
||||
|
||||
BatteryControl.AutoBattery(init);
|
||||
|
||||
settingsForm.matrixControl.SetMatrix(true);
|
||||
settingsForm.matrixControl.SetDevice(true);
|
||||
|
||||
if (AppConfig.IsAlly())
|
||||
{
|
||||
|
||||
@@ -686,7 +686,7 @@ namespace GHelper
|
||||
private void CheckMatrix_CheckedChanged(object? sender, EventArgs e)
|
||||
{
|
||||
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)
|
||||
{
|
||||
AppConfig.Set("matrix_running", comboMatrixRunning.SelectedIndex);
|
||||
matrixControl.SetMatrix();
|
||||
matrixControl.SetDevice();
|
||||
}
|
||||
|
||||
|
||||
private void ComboMatrix_SelectedValueChanged(object? sender, EventArgs e)
|
||||
{
|
||||
AppConfig.Set("matrix_brightness", comboMatrix.SelectedIndex);
|
||||
matrixControl.SetMatrix();
|
||||
matrixControl.SetDevice();
|
||||
}
|
||||
|
||||
|
||||
@@ -896,6 +896,15 @@ namespace GHelper
|
||||
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);
|
||||
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);
|
||||
AppConfig.Set("matrix_brightness", comboMatrix.SelectedIndex);
|
||||
matrixControl.SetMatrix();
|
||||
matrixControl.SetDevice();
|
||||
Program.toast.RunToast(comboMatrix.GetItemText(comboMatrix.SelectedItem), delta > 0 ? ToastIcon.BacklightUp : ToastIcon.BacklightDown);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user