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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user