forked from amkovkov/GranuSightSoftware2
feat: IlluminatorController
This commit is contained in:
@@ -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