forked from amkovkov/GranuSightSoftware2
feat: GSS2.Test - UI+DI, Vulkan render test
This commit is contained in:
@@ -1,60 +1,26 @@
|
||||
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)
|
||||
public MainWindow()
|
||||
{
|
||||
_cameraService = cameraService;
|
||||
_illuminatorService = illuminatorService;
|
||||
_lightsService = lightsService;
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
PointerPressed += async (_, _) =>
|
||||
{
|
||||
_lightsService.CpuLoad(0.5, 1, System.Drawing.Color.Aqua);
|
||||
var viewModel = DataContext as MainWindowViewModel;
|
||||
if (viewModel is null)
|
||||
return;
|
||||
|
||||
try
|
||||
var result = await viewModel.CaptureImage();
|
||||
if (result is not null)
|
||||
{
|
||||
_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);
|
||||
var (frameBuffer, streamConfiguration) = result.Value;
|
||||
// cameraView.Update(frameBuffer, streamConfiguration);
|
||||
(cameraView.Content as CameraViewModel)?.CallUpdate(frameBuffer, streamConfiguration);
|
||||
}
|
||||
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