forked from amkovkov/GranuSightSoftware2
feat: AvaloniaUi GSS2.Test
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media.Imaging;
|
||||
|
||||
using GSS2.Core.Hardware;
|
||||
|
||||
namespace GSS2.Test;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private readonly CameraService _cameraService;
|
||||
private readonly IlluminatorService _illuminatorService;
|
||||
private readonly LightsService _lightsService;
|
||||
|
||||
public MainWindow(CameraService cameraService, IlluminatorService illuminatorService, LightsService lightsService)
|
||||
{
|
||||
_cameraService = cameraService;
|
||||
_illuminatorService = illuminatorService;
|
||||
_lightsService = lightsService;
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
PointerPressed += async (_, _) =>
|
||||
{
|
||||
_lightsService.CpuLoad(0.5, 1, System.Drawing.Color.Aqua);
|
||||
|
||||
try
|
||||
{
|
||||
_illuminatorService.SetIntensity(0.01, 0, 0);
|
||||
_illuminatorService.TurnOn();
|
||||
using var img = await _cameraService.CaptureImage(CancellationToken.None, 5);
|
||||
|
||||
if (img is not null)
|
||||
{
|
||||
var bytes = img.ToBytes(".png");
|
||||
using var stream = new MemoryStream(bytes);
|
||||
image.Source = new Bitmap(stream);
|
||||
}
|
||||
|
||||
_lightsService.Flash(0.5, 2, System.Drawing.Color.Green);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_lightsService.Flash(0.5, 2, System.Drawing.Color.Red);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_illuminatorService.TurnOff();
|
||||
}
|
||||
|
||||
var snowfallTimer = new System.Timers.Timer(3000);
|
||||
snowfallTimer.Elapsed += (_, _) =>
|
||||
{
|
||||
lightsService.Snowfall(0.3, 1, System.Drawing.Color.Aqua);
|
||||
snowfallTimer.Dispose();
|
||||
};
|
||||
snowfallTimer.Start();
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user