1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 01:42:02 +00:00

Devices - Added option to disable devices

This commit is contained in:
SpoinkyNL 2021-02-01 19:54:28 +01:00
parent 25dcb16964
commit bd6c93b292
14 changed files with 118 additions and 52 deletions

View File

@ -570,7 +570,7 @@ namespace Artemis.Core
List<ArtemisLed> leds = new(); List<ArtemisLed> leds = new();
// Get the surface LEDs for this layer // Get the surface LEDs for this layer
List<ArtemisLed> availableLeds = surface.Devices.SelectMany(d => d.Leds).ToList(); List<ArtemisLed> availableLeds = surface.Devices.Where(d => d.IsEnabled).SelectMany(d => d.Leds).ToList();
foreach (LedEntity ledEntity in LayerEntity.Leds) foreach (LedEntity ledEntity in LayerEntity.Leds)
{ {
ArtemisLed? match = availableLeds.FirstOrDefault(a => a.Device.RgbDevice.GetDeviceIdentifier() == ledEntity.DeviceIdentifier && ArtemisLed? match = availableLeds.FirstOrDefault(a => a.Device.RgbDevice.GetDeviceIdentifier() == ledEntity.DeviceIdentifier &&

View File

@ -30,6 +30,7 @@ namespace Artemis.Core
RedScale = 1; RedScale = 1;
GreenScale = 1; GreenScale = 1;
BlueScale = 1; BlueScale = 1;
IsEnabled = true;
deviceProvider.DeviceLayoutPaths.TryGetValue(rgbDevice, out string? layoutPath); deviceProvider.DeviceLayoutPaths.TryGetValue(rgbDevice, out string? layoutPath);
LayoutPath = layoutPath; LayoutPath = layoutPath;
@ -213,6 +214,19 @@ namespace Artemis.Core
} }
} }
/// <summary>
/// Gets or sets a boolean indicating whether this devices is enabled or not
/// </summary>
public bool IsEnabled
{
get => DeviceEntity.IsEnabled;
set
{
DeviceEntity.IsEnabled = value;
OnPropertyChanged(nameof(IsEnabled));
}
}
/// <summary> /// <summary>
/// Gets the path to where the layout of the device was (attempted to be) loaded from /// Gets the path to where the layout of the device was (attempted to be) loaded from
/// </summary> /// </summary>

View File

@ -98,7 +98,7 @@ namespace Artemis.Core
internal void UpdateLedMap() internal void UpdateLedMap()
{ {
LedMap = new ReadOnlyDictionary<Led, ArtemisLed>( LedMap = new ReadOnlyDictionary<Led, ArtemisLed>(
_devices.SelectMany(d => d.Leds.Select(al => new KeyValuePair<Led, ArtemisLed>(al.RgbLed, al))).ToDictionary(kvp => kvp.Key, kvp => kvp.Value) _devices.Where(d => d.IsEnabled).SelectMany(d => d.Leds.Select(al => new KeyValuePair<Led, ArtemisLed>(al.RgbLed, al))).ToDictionary(kvp => kvp.Key, kvp => kvp.Value)
); );
} }

View File

@ -117,7 +117,7 @@ namespace Artemis.Core.Services
{ {
// Apply the application wide brush and decorator // Apply the application wide brush and decorator
BitmapBrush = new BitmapBrush(new Scale(_renderScaleSetting.Value), _sampleSizeSetting); BitmapBrush = new BitmapBrush(new Scale(_renderScaleSetting.Value), _sampleSizeSetting);
_surfaceLedGroup = new ListLedGroup(Surface.Leds) {Brush = BitmapBrush}; _surfaceLedGroup = new ListLedGroup(artemisSurface.LedMap.Select(l => l.Key)) {Brush = BitmapBrush};
return; return;
} }
@ -129,7 +129,7 @@ namespace Artemis.Core.Services
// Apply the application wide brush and decorator // Apply the application wide brush and decorator
BitmapBrush.Scale = new Scale(_renderScaleSetting.Value); BitmapBrush.Scale = new Scale(_renderScaleSetting.Value);
BitmapBrush.Surface = artemisSurface; BitmapBrush.Surface = artemisSurface;
_surfaceLedGroup = new ListLedGroup(Surface.Leds) {Brush = BitmapBrush}; _surfaceLedGroup = new ListLedGroup(artemisSurface.LedMap.Select(l => l.Key)) {Brush = BitmapBrush};
} }
} }

View File

@ -18,6 +18,7 @@ namespace Artemis.Storage.Entities.Surface
public double RedScale { get; set; } public double RedScale { get; set; }
public double GreenScale { get; set; } public double GreenScale { get; set; }
public double BlueScale { get; set; } public double BlueScale { get; set; }
public bool IsEnabled { get; set; }
public List<DeviceInputIdentifierEntity> InputIdentifiers { get; set; } public List<DeviceInputIdentifierEntity> InputIdentifiers { get; set; }
} }

View File

@ -207,7 +207,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
private void ApplySurfaceConfiguration(ArtemisSurface surface) private void ApplySurfaceConfiguration(ArtemisSurface surface)
{ {
Devices.Clear(); Devices.Clear();
Devices.AddRange(surface.Devices.OrderBy(d => d.ZIndex)); Devices.AddRange(surface.Devices.Where(d => d.IsEnabled).OrderBy(d => d.ZIndex));
} }
private void UpdateLedsDimStatus() private void UpdateLedsDimStatus()

View File

@ -5,43 +5,51 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Settings.Tabs.About" xmlns:local="clr-namespace:Artemis.UI.Screens.Settings.Tabs.About"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DesignHeight="450" d:DesignWidth="800"
d:DataContext="{d:DesignInstance local:AboutTabViewModel}"> d:DataContext="{d:DesignInstance local:AboutTabViewModel}">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled"> <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
<StackPanel Margin="15" MaxWidth="800"> <StackPanel Margin="15" MaxWidth="800">
<TextBlock Style="{StaticResource MaterialDesignHeadline2TextBlock}"> <StackPanel Orientation="Horizontal">
Artemis 2 <shared:ArtemisIcon SvgSource="/Resources/Images/Logo/bow.svg" Width="60" Height="80" Margin="0 0 20 0" />
</TextBlock> <TextBlock Style="{StaticResource MaterialDesignHeadline2TextBlock}">
Artemis 2
</TextBlock>
</StackPanel>
<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}" Foreground="{DynamicResource MaterialDesignBodyLight}" Text="{Binding Version}" /> <TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}" Foreground="{DynamicResource MaterialDesignBodyLight}" Text="{Binding Version}" />
<materialDesign:Card Margin="0 25 0 0"> <materialDesign:Card Margin="0 25 0 0">
<StackPanel Margin="15"> <StackPanel Margin="15">
<TextBlock Style="{StaticResource MaterialDesignHeadline4TextBlock}"> <StackPanel Orientation="Horizontal">
Lead developer <materialDesign:PackIcon Kind="Account" Width="60" Height="40" />
</TextBlock> <TextBlock Style="{StaticResource MaterialDesignHeadline4TextBlock}">
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}"> Lead developer
Spoinky (Robert Beekman) </TextBlock>
</StackPanel>
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Margin="10 0 0 0">
- Spoinky (Robert Beekman)
</TextBlock> </TextBlock>
<TextBlock Style="{StaticResource MaterialDesignHeadline4TextBlock}" Margin="0 25 0 0"> <StackPanel Orientation="Horizontal" Margin="0 25 0 0">
Main contributors <materialDesign:PackIcon Kind="AccountGroup" Width="60" Height="40" />
<TextBlock Style="{StaticResource MaterialDesignHeadline4TextBlock}">
Main contributors
</TextBlock>
</StackPanel>
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" LineHeight="25" Margin="10 0 0 0">
- DarthAffe <LineBreak />
- DrMeteor (Diogo Trindade)
</TextBlock> </TextBlock>
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}"> <StackPanel Orientation="Horizontal" Margin="0 25 0 0">
DarthAffe <materialDesign:PackIcon Kind="AccountHeart" Width="60" Height="40" />
</TextBlock> <TextBlock Style="{StaticResource MaterialDesignHeadline4TextBlock}">
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}"> Special thanks
DrMeteor (Diogo Trindade) </TextBlock>
</TextBlock> </StackPanel>
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" LineHeight="25" Margin="10 0 0 0">
<TextBlock Style="{StaticResource MaterialDesignHeadline4TextBlock}" Margin="0 25 0 0"> - All the people on Discord providing feedback and testing<LineBreak />
Special thanks - Aureshion - Default device images
</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}">
All the people on Discord provinding feedback and testing
</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}">
Aureshion - Default device images
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
</materialDesign:Card> </materialDesign:Card>

View File

@ -10,7 +10,14 @@
d:DataContext="{d:DesignInstance local:DeviceSettingsTabViewModel}"> d:DataContext="{d:DesignInstance local:DeviceSettingsTabViewModel}">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Margin="0 12 0 0"> <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Margin="0 12 0 0">
<DockPanel Margin="15" MaxWidth="1230" HorizontalAlignment="Center"> <DockPanel Margin="15" MaxWidth="1230" HorizontalAlignment="Center">
<TextBlock DockPanel.Dock="Top">Below you view and manage the devices that were detected by Artemis</TextBlock> <StackPanel DockPanel.Dock="Top">
<TextBlock Style="{StaticResource MaterialDesignHeadline5TextBlock}">Device management</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">
Below you view and manage the devices that were detected by Artemis. <LineBreak/>
Disabling a device will cause it to stop updating. Some SDKs will even go back to using manufacturer lighting (Artemis restart may be required).
</TextBlock>
</StackPanel>
<ItemsControl ItemsSource="{Binding Items}"> <ItemsControl ItemsSource="{Binding Items}">
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>

View File

@ -3,6 +3,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Artemis.Core.Services; using Artemis.Core.Services;
using Artemis.UI.Ninject.Factories; using Artemis.UI.Ninject.Factories;
using Artemis.UI.Shared.Services;
using Stylet; using Stylet;
namespace Artemis.UI.Screens.Settings.Tabs.Devices namespace Artemis.UI.Screens.Settings.Tabs.Devices
@ -11,19 +12,22 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices
{ {
private readonly ISettingsVmFactory _settingsVmFactory; private readonly ISettingsVmFactory _settingsVmFactory;
private readonly ISurfaceService _surfaceService; private readonly ISurfaceService _surfaceService;
private readonly IDialogService _dialogService;
private bool _confirmedDisable;
public DeviceSettingsTabViewModel(ISurfaceService surfaceService, ISettingsVmFactory settingsVmFactory) public DeviceSettingsTabViewModel(ISurfaceService surfaceService, IDialogService dialogService, ISettingsVmFactory settingsVmFactory)
{ {
DisplayName = "DEVICES"; DisplayName = "DEVICES";
_surfaceService = surfaceService; _surfaceService = surfaceService;
_dialogService = dialogService;
_settingsVmFactory = settingsVmFactory; _settingsVmFactory = settingsVmFactory;
} }
protected override void OnActivate() protected override void OnActivate()
{ {
// Take it off the UI thread to avoid freezing on tab change // Take it off the UI thread to avoid freezing on tab change
Task.Run(async () => Task.Run(async () =>
{ {
Items.Clear(); Items.Clear();
await Task.Delay(200); await Task.Delay(200);
@ -35,5 +39,21 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices
base.OnActivate(); base.OnActivate();
} }
public async Task<bool> ShowDeviceDisableDialog()
{
if (_confirmedDisable)
return true;
bool confirmed = await _dialogService.ShowConfirmDialog(
"Disabling device",
"Disabling a device will cause it to stop updating. " +
"\r\nSome SDKs will even go back to using manufacturer lighting (Artemis restart may be required)."
);
if (confirmed)
_confirmedDisable = true;
return confirmed;
}
} }
} }

View File

@ -29,7 +29,7 @@
<RowDefinition Height="*" /> <RowDefinition Height="*" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Rectangle Grid.Row="0" Height="140" Width="196" Fill="{DynamicResource MaterialDesignPaper}" /> <Rectangle Grid.Row="0" Fill="{DynamicResource MaterialDesignPaper}" />
<shared:DeviceVisualizer Device="{Binding Device}" RenderOptions.BitmapScalingMode="HighQuality" Grid.Row="0" Height="130" Width="190" /> <shared:DeviceVisualizer Device="{Binding Device}" RenderOptions.BitmapScalingMode="HighQuality" Grid.Row="0" Height="130" Width="190" />
<Button Grid.Row="0" <Button Grid.Row="0"
Style="{StaticResource MaterialDesignFloatingActionMiniButton}" Style="{StaticResource MaterialDesignFloatingActionMiniButton}"
@ -56,26 +56,26 @@
<StackPanel> <StackPanel>
<Button Command="{s:Action ShowDeviceDebugger}"> <Button Command="{s:Action ShowDeviceDebugger}">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Tools" Margin="0 0 10 0 " VerticalAlignment="Center"/> <materialDesign:PackIcon Kind="Tools" Margin="0 0 10 0 " VerticalAlignment="Center" />
<TextBlock VerticalAlignment="Center">Show device debugger</TextBlock> <TextBlock VerticalAlignment="Center">Show device debugger</TextBlock>
</StackPanel> </StackPanel>
</Button> </Button>
<Button Command="{s:Action OpenPluginDirectory}"> <Button Command="{s:Action OpenPluginDirectory}">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="FolderOpen" Margin="0 0 10 0 " VerticalAlignment="Center"/> <materialDesign:PackIcon Kind="FolderOpen" Margin="0 0 10 0 " VerticalAlignment="Center" />
<TextBlock VerticalAlignment="Center">Open plugin directory</TextBlock> <TextBlock VerticalAlignment="Center">Open plugin directory</TextBlock>
</StackPanel> </StackPanel>
</Button> </Button>
<Separator/> <Separator />
<Button Command="{s:Action DetectInput}" ToolTip="Teach Artemis which keypresses and/or button presses belong to this device"> <Button Command="{s:Action DetectInput}" ToolTip="Teach Artemis which keypresses and/or button presses belong to this device">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="GestureDoubleTap" Margin="0 0 10 0 " VerticalAlignment="Center"/> <materialDesign:PackIcon Kind="GestureDoubleTap" Margin="0 0 10 0 " VerticalAlignment="Center" />
<TextBlock VerticalAlignment="Center">Identify input</TextBlock> <TextBlock VerticalAlignment="Center">Identify input</TextBlock>
</StackPanel> </StackPanel>
</Button> </Button>
<Button Command="{s:Action ViewProperties}"> <Button Command="{s:Action ViewProperties}">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Gear" Margin="0 0 10 0 " VerticalAlignment="Center"/> <materialDesign:PackIcon Kind="Gear" Margin="0 0 10 0 " VerticalAlignment="Center" />
<TextBlock VerticalAlignment="Center">View surface properties</TextBlock> <TextBlock VerticalAlignment="Center">View surface properties</TextBlock>
</StackPanel> </StackPanel>
</Button> </Button>

View File

@ -14,14 +14,13 @@ using Stylet;
namespace Artemis.UI.Screens.Settings.Tabs.Devices namespace Artemis.UI.Screens.Settings.Tabs.Devices
{ {
public class DeviceSettingsViewModel : PropertyChangedBase public class DeviceSettingsViewModel : Screen
{ {
private readonly IDeviceDebugVmFactory _deviceDebugVmFactory; private readonly IDeviceDebugVmFactory _deviceDebugVmFactory;
private readonly ISurfaceService _surfaceService; private readonly ISurfaceService _surfaceService;
private readonly IDeviceService _deviceService; private readonly IDeviceService _deviceService;
private readonly IDialogService _dialogService; private readonly IDialogService _dialogService;
private readonly IWindowManager _windowManager; private readonly IWindowManager _windowManager;
private bool _isDeviceEnabled;
public DeviceSettingsViewModel(ArtemisDevice device, public DeviceSettingsViewModel(ArtemisDevice device,
IDeviceService deviceService, IDeviceService deviceService,
@ -40,9 +39,6 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices
Type = Device.RgbDevice.DeviceInfo.DeviceType.ToString().Humanize(); Type = Device.RgbDevice.DeviceInfo.DeviceType.ToString().Humanize();
Name = Device.RgbDevice.DeviceInfo.Model; Name = Device.RgbDevice.DeviceInfo.Model;
Manufacturer = Device.RgbDevice.DeviceInfo.Manufacturer; Manufacturer = Device.RgbDevice.DeviceInfo.Manufacturer;
// TODO: Implement this bad boy
IsDeviceEnabled = true;
} }
public ArtemisDevice Device { get; } public ArtemisDevice Device { get; }
@ -56,8 +52,27 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices
public bool IsDeviceEnabled public bool IsDeviceEnabled
{ {
get => _isDeviceEnabled; get => Device.IsEnabled;
set => SetAndNotify(ref _isDeviceEnabled, value); set
{
Task.Run(() => UpdateIsDeviceEnabled(value));
}
}
private async Task UpdateIsDeviceEnabled(bool value)
{
if (!value)
value = !await ((DeviceSettingsTabViewModel)Parent).ShowDeviceDisableDialog();
Device.IsEnabled = value;
NotifyOfPropertyChange(nameof(IsDeviceEnabled));
SaveDevice();
}
private void SaveDevice()
{
_surfaceService.UpdateSurfaceConfiguration(_surfaceService.ActiveSurface, true);
} }
public void IdentifyDevice() public void IdentifyDevice()
@ -85,10 +100,10 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices
public async Task DetectInput() public async Task DetectInput()
{ {
object madeChanges = await _dialogService.ShowDialog<SurfaceDeviceDetectInputViewModel>( object madeChanges = await _dialogService.ShowDialog<SurfaceDeviceDetectInputViewModel>(
new Dictionary<string, object> { { "device", Device } } new Dictionary<string, object> {{"device", Device}}
); );
if ((bool)madeChanges) if ((bool) madeChanges)
_surfaceService.UpdateSurfaceConfiguration(_surfaceService.ActiveSurface, true); _surfaceService.UpdateSurfaceConfiguration(_surfaceService.ActiveSurface, true);
} }

View File

@ -19,6 +19,7 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel> <StackPanel>
<TextBlock Style="{StaticResource MaterialDesignHeadline5TextBlock}" Margin="0 15 0 0">Module priority</TextBlock>
<TextBlock TextWrapping="Wrap" Style="{StaticResource MaterialDesignTextBlock}"> <TextBlock TextWrapping="Wrap" Style="{StaticResource MaterialDesignTextBlock}">
Drag and drop the modules below to change their rendering priority. <LineBreak /><LineBreak /> Drag and drop the modules below to change their rendering priority. <LineBreak /><LineBreak />
- Like in the profile editor, the modules at the top render over modules at the bottom <LineBreak /> - Like in the profile editor, the modules at the top render over modules at the bottom <LineBreak />

View File

@ -176,7 +176,7 @@ namespace Artemis.UI.Screens.SurfaceEditor
List<SurfaceDeviceViewModel> deviceViewModels = new(); List<SurfaceDeviceViewModel> deviceViewModels = new();
// Add missing/update existing // Add missing/update existing
foreach (ArtemisDevice surfaceDeviceConfiguration in SelectedSurface.Devices.OrderBy(d => d.ZIndex).ToList()) foreach (ArtemisDevice surfaceDeviceConfiguration in SelectedSurface.Devices.Where(d => d.IsEnabled).OrderBy(d => d.ZIndex).ToList())
{ {
// Create VMs for missing devices // Create VMs for missing devices
SurfaceDeviceViewModel viewModel = existing.FirstOrDefault(vm => vm.Device.RgbDevice == surfaceDeviceConfiguration.RgbDevice); SurfaceDeviceViewModel viewModel = existing.FirstOrDefault(vm => vm.Device.RgbDevice == surfaceDeviceConfiguration.RgbDevice);

View File

@ -116,7 +116,7 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization
.Select(l => SKRect.Create(l.Rectangle.Left + x, l.Rectangle.Top + y, l.Rectangle.Width, l.Rectangle.Height)) .Select(l => SKRect.Create(l.Rectangle.Left + x, l.Rectangle.Top + y, l.Rectangle.Width, l.Rectangle.Height))
.ToList(); .ToList();
List<SKRect> others = Device.Surface.Devices List<SKRect> others = Device.Surface.Devices
.Where(d => d != Device) .Where(d => d != Device && d.IsEnabled)
.SelectMany(d => d.Leds) .SelectMany(d => d.Leds)
.Select(l => SKRect.Create(l.Rectangle.Left + (float) l.Device.X, l.Rectangle.Top + (float) l.Device.Y, l.Rectangle.Width, l.Rectangle.Height)) .Select(l => SKRect.Create(l.Rectangle.Left + (float) l.Device.X, l.Rectangle.Top + (float) l.Device.Y, l.Rectangle.Width, l.Rectangle.Height))
.ToList(); .ToList();