forked from amkovkov/GranuSightSoftware2
feat: GSS2.Test - UI+DI, Vulkan render test
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using Avalonia.Input;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
using GSS2.Core.Hardware;
|
||||
|
||||
namespace GSS2.Test;
|
||||
|
||||
public partial class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
private readonly CameraService _cameraService;
|
||||
private readonly IlluminatorService _illuminatorService;
|
||||
private readonly LightsService _lightsService;
|
||||
private readonly ILogger<MainWindowViewModel> _logger;
|
||||
[ObservableProperty] private CameraViewModel _cameraViewModel;
|
||||
|
||||
public MainWindowViewModel(
|
||||
CameraService cameraService,
|
||||
IlluminatorService illuminatorService,
|
||||
LightsService lightsService,
|
||||
ILogger<MainWindowViewModel> logger,
|
||||
CameraViewModel cameraViewModel
|
||||
)
|
||||
{
|
||||
_cameraService = cameraService;
|
||||
_illuminatorService = illuminatorService;
|
||||
_lightsService = lightsService;
|
||||
_logger = logger;
|
||||
CameraViewModel = cameraViewModel;
|
||||
_logger.LogInformation("Initialized");
|
||||
}
|
||||
|
||||
public async Task<(LibCameraSharp.FrameBuffer, LibCameraSharp.StreamConfiguration)?> CaptureImage()
|
||||
{
|
||||
_logger.LogInformation("Capture image");
|
||||
_lightsService.CpuLoad(0.5, 1, System.Drawing.Color.Aqua);
|
||||
|
||||
(LibCameraSharp.FrameBuffer, LibCameraSharp.StreamConfiguration)? result = null;
|
||||
try
|
||||
{
|
||||
_illuminatorService.SetIntensity(0.01, 0, 0);
|
||||
_illuminatorService.TurnOn();
|
||||
result = await _cameraService.CaptureViewFinderBuffer(CancellationToken.None);
|
||||
_lightsService.Flash(0.5, 2, System.Drawing.Color.Green);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Error while image capture");
|
||||
_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();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user