1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

RGB.NET - Updated for latest development branch

This commit is contained in:
Robert 2021-02-07 22:29:30 +01:00
parent 81b8f5bf48
commit 606c1b80f2
13 changed files with 77 additions and 29 deletions

View File

@ -73,6 +73,9 @@
<Reference Include="RGB.NET.Groups">
<HintPath>..\..\..\RGB.NET\bin\net5.0\RGB.NET.Groups.dll</HintPath>
</Reference>
<Reference Include="RGB.NET.Layout">
<HintPath>..\..\..\RGB.NET\bin\net5.0\RGB.NET.Layout.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<None Update="Resources\intro-profile.json">

View File

@ -16,8 +16,6 @@ namespace Artemis.Core
builder.Append(rgbDevice.DeviceInfo.Model);
builder.Append('-');
builder.Append(rgbDevice.DeviceInfo.DeviceType);
builder.Append('-');
builder.Append(rgbDevice.DeviceInfo.Lighting);
return builder.ToString();
}
}

View File

@ -287,7 +287,7 @@ namespace Artemis.Core
if (!Enabled || Path == null || LayerShape?.Path == null || !General.PropertiesInitialized || !Transform.PropertiesInitialized)
return;
// Ensure the brush is ready
if (LayerBrush?.BaseProperties?.PropertiesInitialized == false || LayerBrush?.BrushType != LayerBrushType.Regular)
if (LayerBrush?.BaseProperties?.PropertiesInitialized == false)
return;
RenderTimeline(Timeline, canvas);
@ -323,6 +323,9 @@ namespace Artemis.Core
ApplyTimeline(timeline);
if (LayerBrush?.BrushType != LayerBrushType.Regular)
return;
try
{
canvas.Save();

View File

@ -232,6 +232,11 @@ namespace Artemis.Core
/// </summary>
public string? LayoutPath { get; internal set; }
/// <summary>
/// Gets the layout of the device expanded with Artemis-specific data
/// </summary>
public ArtemisLayout? Layout { get; internal set; }
internal DeviceEntity DeviceEntity { get; }
/// <inheritdoc />

View File

@ -0,0 +1,10 @@
using System;
namespace Artemis.Core
{
public class ArtemisLayout
{
public ArtemisDevice Device { get; set; }
public Uri Image { get; set; }
}
}

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.Services;
using Ninject;
using RGB.NET.Core;
using RGB.NET.Groups;
using SkiaSharp;
@ -20,7 +21,6 @@ namespace Artemis.Core.LayerBrushes
/// </summary>
protected RgbNetLayerBrush()
{
LedGroup = new ListLedGroup();
BrushType = LayerBrushType.RgbNet;
SupportsTransformation = false;
}
@ -28,7 +28,10 @@ namespace Artemis.Core.LayerBrushes
/// <summary>
/// The LED group this layer effect is applied to
/// </summary>
public ListLedGroup LedGroup { get; internal set; }
public ListLedGroup? LedGroup { get; internal set; }
[Inject]
public IRgbService? RgbService { get; set; }
/// <summary>
/// Called when Artemis needs an instance of the RGB.NET effect you are implementing
@ -38,7 +41,12 @@ namespace Artemis.Core.LayerBrushes
internal void UpdateLedGroup()
{
// TODO: This simply renders it on top of the rest, get a ZIndex based on layer position
if (LedGroup == null)
return;
if (Layer.Parent != null)
LedGroup.ZIndex = Layer.Parent.Children.Count - Layer.Parent.Children.IndexOf(Layer);
else
LedGroup.ZIndex = 1;
List<Led> missingLeds = Layer.Leds.Where(l => !LedGroup.ContainsLed(l.RgbLed)).Select(l => l.RgbLed).ToList();
@ -50,7 +58,10 @@ namespace Artemis.Core.LayerBrushes
internal override void Initialize()
{
LedGroup = new ListLedGroup();
if (RgbService == null)
throw new ArtemisCoreException("Cannot initialize RGB.NET layer brush because RgbService is not set");
LedGroup = new ListLedGroup(RgbService.Surface);
Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated;
InitializeProperties();
@ -64,8 +75,12 @@ namespace Artemis.Core.LayerBrushes
{
if (disposing)
{
if (RgbService == null)
throw new ArtemisCoreException("Cannot dispose RGB.NET layer brush because RgbService is not set");
Layer.RenderPropertiesUpdated -= LayerOnRenderPropertiesUpdated;
LedGroup.Detach();
LedGroup?.Detach(RgbService.Surface);
LedGroup = null;
}
base.Dispose(disposing);

View File

@ -8,6 +8,13 @@ namespace Artemis.Core.Services
{
internal class DeviceService : IDeviceService
{
private readonly IRgbService _rgbService;
public DeviceService(IRgbService rgbService)
{
_rgbService = rgbService;
}
public void IdentifyDevice(ArtemisDevice device)
{
BlinkDevice(device, 0);
@ -16,7 +23,7 @@ namespace Artemis.Core.Services
private void BlinkDevice(ArtemisDevice device, int blinkCount)
{
// Create a LED group way at the top
ListLedGroup ledGroup = new(device.Leds.Select(l => l.RgbLed))
ListLedGroup ledGroup = new(_rgbService.Surface, device.Leds.Select(l => l.RgbLed))
{
Brush = new SolidColorBrush(new Color(255, 255, 255)),
ZIndex = 999
@ -26,7 +33,7 @@ namespace Artemis.Core.Services
Task.Run(async () =>
{
await Task.Delay(200);
ledGroup.Detach();
ledGroup.Detach(_rgbService.Surface);
if (blinkCount < 5)
{

View File

@ -358,7 +358,7 @@ namespace Artemis.Core.Services
}
catch (Exception e)
{
throw new ArtemisPluginException(plugin, "Failed to instantiate feature", e);
_logger.Warning(new ArtemisPluginException(plugin, "Failed to instantiate feature", e), "Failed to instantiate feature", plugin);
}
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Groups;
using RGB.NET.Layout;
using Serilog;
namespace Artemis.Core.Services
@ -26,7 +27,7 @@ namespace Artemis.Core.Services
_targetFrameRateSetting = settingsService.GetSetting("Core.TargetFrameRate", 25);
_sampleSizeSetting = settingsService.GetSetting("Core.SampleSize", 1);
Surface = RGBSurface.Instance;
Surface = new RGBSurface();
// Let's throw these for now
Surface.Exception += SurfaceOnException;
@ -50,7 +51,11 @@ namespace Artemis.Core.Services
{
try
{
Surface.LoadDevices(deviceProvider, RGBDeviceType.All, false, true);
// Device provider may have been attached before..?
Surface.Detach(deviceProvider.Devices);
deviceProvider.Initialize(RGBDeviceType.All, true);
Surface.Attach(deviceProvider.Devices);
}
catch (Exception e)
{
@ -117,19 +122,19 @@ namespace Artemis.Core.Services
{
// Apply the application wide brush and decorator
BitmapBrush = new BitmapBrush(new Scale(_renderScaleSetting.Value), _sampleSizeSetting);
_surfaceLedGroup = new ListLedGroup(artemisSurface.LedMap.Select(l => l.Key)) {Brush = BitmapBrush};
_surfaceLedGroup = new ListLedGroup(Surface, artemisSurface.LedMap.Select(l => l.Key)) {Brush = BitmapBrush};
return;
}
lock (_surfaceLedGroup)
{
// Clean up the old background
_surfaceLedGroup.Detach();
_surfaceLedGroup.Detach(Surface);
// Apply the application wide brush and decorator
BitmapBrush.Scale = new Scale(_renderScaleSetting.Value);
BitmapBrush.Surface = artemisSurface;
_surfaceLedGroup = new ListLedGroup(artemisSurface.LedMap.Select(l => l.Key)) {Brush = BitmapBrush};
_surfaceLedGroup = new ListLedGroup(Surface, artemisSurface.LedMap.Select(l => l.Key)) {Brush = BitmapBrush};
}
}

View File

@ -29,7 +29,7 @@ namespace Artemis.Core.Services
/// <summary>
/// Gets the full URL of the end point
/// </summary>
public string Url => $"{_pluginsModule.ServerUrl.TrimEnd('/')}{_pluginsModule.BaseRoute}{PluginFeature.Plugin.Guid}/{Name}";
public string Url => $"{_pluginsModule.ServerUrl?.TrimEnd('/')}{_pluginsModule.BaseRoute}{PluginFeature.Plugin.Guid}/{Name}";
/// <summary>
/// Gets the plugin the end point is associated with
@ -45,12 +45,12 @@ namespace Artemis.Core.Services
/// <summary>
/// Gets the mime type of the input this end point accepts
/// </summary>
public string Accepts { get; protected set; }
public string? Accepts { get; protected set; }
/// <summary>
/// Gets the mime type of the output this end point returns
/// </summary>
public string Returns { get; protected set; }
public string? Returns { get; protected set; }
/// <summary>
/// Called whenever the end point has to process a request

View File

@ -235,8 +235,8 @@ namespace Artemis.UI.Shared
UpdateTransform();
// Load the device main image
if (Device.RgbDevice.DeviceInfo?.Image?.AbsolutePath != null && File.Exists(Device.RgbDevice.DeviceInfo.Image.AbsolutePath))
_deviceImage = new BitmapImage(Device.RgbDevice.DeviceInfo.Image);
// if (Device.RgbDevice.DeviceInfo?.Image?.AbsolutePath != null && File.Exists(Device.RgbDevice.DeviceInfo.Image.AbsolutePath))
// _deviceImage = new BitmapImage(Device.RgbDevice.DeviceInfo.Image);
// Create all the LEDs
foreach (ArtemisLed artemisLed in Device.Leds)

View File

@ -35,7 +35,7 @@ namespace Artemis.UI.Screens.Settings.Debug
}
}
public bool CanOpenImageDirectory => Device.RgbDevice.DeviceInfo.Image != null;
public bool CanOpenImageDirectory => Device.Layout?.Image != null;
// ReSharper disable UnusedMember.Global
@ -70,7 +70,7 @@ namespace Artemis.UI.Screens.Settings.Debug
try
{
Process.Start(Environment.GetEnvironmentVariable("WINDIR") + @"\explorer.exe", Path.GetDirectoryName(Device.RgbDevice.DeviceInfo.Image.AbsolutePath));
Process.Start(Environment.GetEnvironmentVariable("WINDIR") + @"\explorer.exe", Path.GetDirectoryName(Device.Layout.Image.AbsolutePath));
}
catch (Exception e)
{

View File

@ -14,9 +14,10 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
{
private readonly IInputService _inputService;
private readonly IMessageService _messageService;
private readonly IRgbService _rgbService;
private readonly ListLedGroup _ledGroup;
public SurfaceDeviceDetectInputViewModel(ArtemisDevice device, IInputService inputService, IMessageService messageService)
public SurfaceDeviceDetectInputViewModel(ArtemisDevice device, IInputService inputService, IMessageService messageService, IRgbService rgbService)
{
Device = device;
Title = $"{Device.RgbDevice.DeviceInfo.DeviceName} - Detect input";
@ -24,11 +25,12 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
_inputService = inputService;
_messageService = messageService;
_rgbService = rgbService;
_inputService.IdentifyDevice(Device);
_inputService.DeviceIdentified += InputServiceOnDeviceIdentified;
// Create a LED group way at the top
_ledGroup = new ListLedGroup(Device.Leds.Select(l => l.RgbLed))
_ledGroup = new ListLedGroup(_rgbService.Surface, Device.Leds.Select(l => l.RgbLed))
{
Brush = new SolidColorBrush(new Color(255, 255, 0)),
ZIndex = 999
@ -43,7 +45,7 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
{
base.OnDialogClosed(sender, e);
_inputService.DeviceIdentified -= InputServiceOnDeviceIdentified;
_ledGroup.Detach();
_ledGroup.Detach(_rgbService.Surface);
}
private void InputServiceOnDeviceIdentified(object sender, EventArgs e)