forked from amkovkov/GranuSightSoftware2
feat: IlluminatorController
This commit is contained in:
@@ -15,5 +15,7 @@ public static class DependencyInjectionHelper
|
|||||||
.AddSingleton<ResourcesView>()
|
.AddSingleton<ResourcesView>()
|
||||||
.AddSingleton<ResourcesViewModel>()
|
.AddSingleton<ResourcesViewModel>()
|
||||||
.AddSingleton<CameraView>()
|
.AddSingleton<CameraView>()
|
||||||
.AddSingleton<CameraViewModel>();
|
.AddSingleton<CameraViewModel>()
|
||||||
|
.AddSingleton<IlluminatorControllerView>()
|
||||||
|
.AddSingleton<IlluminatorControllerViewModel>();
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,7 @@ public partial class MainViewModel : ViewModelBase
|
|||||||
private readonly IlluminatorService _illuminatorService;
|
private readonly IlluminatorService _illuminatorService;
|
||||||
[ObservableProperty] private CameraViewModel _cameraViewModel;
|
[ObservableProperty] private CameraViewModel _cameraViewModel;
|
||||||
[ObservableProperty] private ResourcesViewModel _resourcesViewModel;
|
[ObservableProperty] private ResourcesViewModel _resourcesViewModel;
|
||||||
|
[ObservableProperty] private IlluminatorControllerViewModel _illuminatorControllerViewModel;
|
||||||
[ObservableProperty] private OpenCvSharp.Mat? _image1;
|
[ObservableProperty] private OpenCvSharp.Mat? _image1;
|
||||||
[ObservableProperty] private OpenCvSharp.Mat? _image2;
|
[ObservableProperty] private OpenCvSharp.Mat? _image2;
|
||||||
[ObservableProperty] private OpenCvSharp.Mat? _image3;
|
[ObservableProperty] private OpenCvSharp.Mat? _image3;
|
||||||
@@ -24,13 +25,14 @@ public partial class MainViewModel : ViewModelBase
|
|||||||
[ObservableProperty] private bool _canScrollForward;
|
[ObservableProperty] private bool _canScrollForward;
|
||||||
[ObservableProperty] private bool _canScrollBackward;
|
[ObservableProperty] private bool _canScrollBackward;
|
||||||
|
|
||||||
public MainViewModel(ILogger<MainViewModel> logger, CameraViewModel cameraViewModel, ResourcesViewModel resourcesViewModel, CameraService cameraService, IlluminatorService illuminatorService)
|
public MainViewModel(ILogger<MainViewModel> logger, CameraViewModel cameraViewModel, ResourcesViewModel resourcesViewModel, IlluminatorControllerViewModel illuminatorControllerViewModel, CameraService cameraService, IlluminatorService illuminatorService)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_cameraService = cameraService;
|
_cameraService = cameraService;
|
||||||
_illuminatorService = illuminatorService;
|
_illuminatorService = illuminatorService;
|
||||||
CameraViewModel = cameraViewModel;
|
CameraViewModel = cameraViewModel;
|
||||||
ResourcesViewModel = resourcesViewModel;
|
ResourcesViewModel = resourcesViewModel;
|
||||||
|
IlluminatorControllerViewModel = illuminatorControllerViewModel;
|
||||||
ButtonCaptureClick = new RelayCommand(() =>
|
ButtonCaptureClick = new RelayCommand(() =>
|
||||||
{
|
{
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
|
|||||||
@@ -9,7 +9,12 @@
|
|||||||
<Grid ColumnDefinitions="*,100" RowDefinitions="*,*">
|
<Grid ColumnDefinitions="*,100" RowDefinitions="*,*">
|
||||||
<Button Grid.Row="0" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" IsEnabled="{Binding CanScrollBackward}" Command="{Binding ButtonUpClick}"/>
|
<Button Grid.Row="0" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" IsEnabled="{Binding CanScrollBackward}" Command="{Binding ButtonUpClick}"/>
|
||||||
<Button Grid.Row="1" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" IsEnabled="{Binding CanScrollForward}" Command="{Binding ButtonDownClick}"/>
|
<Button Grid.Row="1" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" IsEnabled="{Binding CanScrollForward}" Command="{Binding ButtonDownClick}"/>
|
||||||
|
|
||||||
<core:SectionPanel Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" ClipToBounds="True" CanScrollForward="{Binding CanScrollForward}" CanScrollBackward="{Binding CanScrollBackward}" CurrentIndex="{Binding CurrentIndex}">
|
<core:SectionPanel Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" ClipToBounds="True" CanScrollForward="{Binding CanScrollForward}" CanScrollBackward="{Binding CanScrollBackward}" CurrentIndex="{Binding CurrentIndex}">
|
||||||
|
<Grid ColumnDefinitions="300,*">
|
||||||
|
<ContentControl Grid.Column="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Content="{Binding IlluminatorControllerViewModel}" />
|
||||||
|
<ContentControl Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Content="{Binding CameraViewModel}" />
|
||||||
|
</Grid>
|
||||||
<Grid ColumnDefinitions="100,*">
|
<Grid ColumnDefinitions="100,*">
|
||||||
<Button Grid.Column="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Command="{Binding ButtonCaptureClick}"/>
|
<Button Grid.Column="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Command="{Binding ButtonCaptureClick}"/>
|
||||||
<Grid Grid.Column="1" ColumnDefinitions="*,*" RowDefinitions="*,*" >
|
<Grid Grid.Column="1" ColumnDefinitions="*,*" RowDefinitions="*,*" >
|
||||||
@@ -20,7 +25,6 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<ContentControl VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Content="{Binding ResourcesViewModel}" />
|
<ContentControl VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Content="{Binding ResourcesViewModel}" />
|
||||||
<!-- <ContentControl VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Content="{Binding CameraViewModel}" /> -->
|
|
||||||
</core:SectionPanel>
|
</core:SectionPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
using Avalonia.Data;
|
||||||
|
using Avalonia.Data.Converters;
|
||||||
|
using Avalonia.Layout;
|
||||||
|
|
||||||
|
namespace GSS2.UI.Core.Converters;
|
||||||
|
|
||||||
|
public static class OrientationToBoolConverter
|
||||||
|
{
|
||||||
|
public static readonly FuncValueConverter<Orientation, bool> IsVertical = new ((orientation) => orientation == Orientation.Vertical);
|
||||||
|
public static readonly FuncValueConverter<Orientation, bool> IsHorizontal = new ((orientation) => orientation == Orientation.Horizontal);
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
using GSS2.Core.Hardware;
|
||||||
|
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
|
using Avalonia.Layout;
|
||||||
|
|
||||||
|
namespace GSS2.UI.Core.ViewModels;
|
||||||
|
|
||||||
|
public partial class IlluminatorControllerViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
private readonly IlluminatorService _illuminatorService;
|
||||||
|
private readonly ILogger<IlluminatorControllerViewModel> _logger;
|
||||||
|
|
||||||
|
private bool _whiteIntencityChanging = false;
|
||||||
|
private bool _uv365IntencityChanging = false;
|
||||||
|
private bool _uv254IntencityChanging = false;
|
||||||
|
|
||||||
|
[ObservableProperty] private double _whiteIntencity;
|
||||||
|
[ObservableProperty] private double _uv365Intencity;
|
||||||
|
[ObservableProperty] private double _uv254Intencity;
|
||||||
|
[ObservableProperty] private bool _enabled;
|
||||||
|
[ObservableProperty] Orientation _orientation;
|
||||||
|
|
||||||
|
public IlluminatorControllerViewModel(IlluminatorService illuminatorService, ILogger<IlluminatorControllerViewModel> logger)
|
||||||
|
{
|
||||||
|
_illuminatorService = illuminatorService;
|
||||||
|
_logger = logger;
|
||||||
|
|
||||||
|
WhiteIntencity = 0;
|
||||||
|
Uv365Intencity = 0;
|
||||||
|
Uv254Intencity = 0;
|
||||||
|
Orientation = Orientation.Horizontal;
|
||||||
|
Enabled = false;
|
||||||
|
_logger.LogInformation("Initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnWhiteIntencityChanged(double value)
|
||||||
|
{
|
||||||
|
if (_whiteIntencityChanging)
|
||||||
|
return;
|
||||||
|
_whiteIntencityChanging = true;
|
||||||
|
_illuminatorService.SetIntensity(white: value);
|
||||||
|
_whiteIntencityChanging = false;
|
||||||
|
}
|
||||||
|
partial void OnUv365IntencityChanged(double value)
|
||||||
|
{
|
||||||
|
if (_uv365IntencityChanging)
|
||||||
|
return;
|
||||||
|
_uv365IntencityChanging = true;
|
||||||
|
_illuminatorService.SetIntensity(uv365: value);
|
||||||
|
_uv365IntencityChanging = false;
|
||||||
|
}
|
||||||
|
partial void OnUv254IntencityChanged(double value)
|
||||||
|
{
|
||||||
|
if (_uv254IntencityChanging)
|
||||||
|
return;
|
||||||
|
_uv254IntencityChanging = true;
|
||||||
|
_illuminatorService.SetIntensity(uv254: value);
|
||||||
|
_uv254IntencityChanging = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnEnabledChanged(bool value)
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
_illuminatorService.TurnOn();
|
||||||
|
else
|
||||||
|
_illuminatorService.TurnOff();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:layout="using:Avalonia.Layout"
|
||||||
|
xmlns:local="using:GSS2.UI.Core.Views"
|
||||||
|
xmlns:vm="using:GSS2.UI.Core.ViewModels"
|
||||||
|
xmlns:behaviors="using:GSS2.UI.Core.Behaviors"
|
||||||
|
xmlns:converters="using:GSS2.UI.Core.Converters"
|
||||||
|
xmlns:lvc="using:LiveChartsCore.SkiaSharpView.Avalonia"
|
||||||
|
x:Class="GSS2.UI.Core.Views.IlluminatorControllerView"
|
||||||
|
x:DataType="vm:IlluminatorControllerViewModel">
|
||||||
|
<Grid>
|
||||||
|
<Grid x:Name="HorizontalLayout" IsVisible="{Binding Orientation, Converter={x:Static converters:OrientationToBoolConverter.IsHorizontal}}">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<StackPanel Orientation="Horizontal"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Spacing="20">
|
||||||
|
<Slider Orientation="Vertical"
|
||||||
|
Minimum="0" Maximum="1"
|
||||||
|
Value="{Binding WhiteIntencity}"
|
||||||
|
VerticalAlignment="Stretch"/>
|
||||||
|
<Slider Orientation="Vertical"
|
||||||
|
Minimum="0" Maximum="1"
|
||||||
|
Value="{Binding Uv365Intencity}"
|
||||||
|
VerticalAlignment="Stretch"/>
|
||||||
|
<Slider Orientation="Vertical"
|
||||||
|
Minimum="0" Maximum="1"
|
||||||
|
Value="{Binding Uv254Intencity}"
|
||||||
|
VerticalAlignment="Stretch"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<ToggleButton Grid.Row="1"
|
||||||
|
Content="Включить"
|
||||||
|
IsChecked="{Binding Enabled}"
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
HorizontalContentAlignment="Center"
|
||||||
|
Margin="0,10,0,0"/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
|
||||||
|
<Grid x:Name="VerticalLayout" IsVisible="{Binding Orientation, Converter={x:Static converters:OrientationToBoolConverter.IsVertical}}">
|
||||||
|
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
<StackPanel Grid.Column="0"
|
||||||
|
Orientation="Vertical"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Spacing="20">
|
||||||
|
|
||||||
|
<Slider Orientation="Horizontal"
|
||||||
|
Minimum="0" Maximum="1"
|
||||||
|
Value="{Binding WhiteIntencity}"
|
||||||
|
HorizontalAlignment="Stretch"/>
|
||||||
|
|
||||||
|
<Slider Orientation="Horizontal"
|
||||||
|
Minimum="0" Maximum="1"
|
||||||
|
Value="{Binding Uv365Intencity}"
|
||||||
|
HorizontalAlignment="Stretch"/>
|
||||||
|
|
||||||
|
<Slider Orientation="Horizontal"
|
||||||
|
Minimum="0" Maximum="1"
|
||||||
|
Value="{Binding Uv254Intencity}"
|
||||||
|
HorizontalAlignment="Stretch"/>
|
||||||
|
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<ToggleButton Grid.Column="1"
|
||||||
|
Content="Включить"
|
||||||
|
IsChecked="{Binding Enabled}"
|
||||||
|
VerticalAlignment="Stretch"
|
||||||
|
HorizontalContentAlignment="Center"
|
||||||
|
Margin="0,0,10,0"/>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
|
||||||
|
namespace GSS2.UI.Core.Views;
|
||||||
|
|
||||||
|
public partial class IlluminatorControllerView : UserControl
|
||||||
|
{
|
||||||
|
public IlluminatorControllerView()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user