mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Made devices aware of the plugin that loaded them
Fixed Corsair LL Fans layout Expanded render events Added identify option to device settings, must move this to be reusable though
This commit is contained in:
1 parent
af2612f294
commit
6ebceacd13
23 files changed
+400
-229
No files matched your search
@@ -29,7 +29,7 @@ namespace Artemis.Core.Services
|
||||
_rgbService = rgbService;
|
||||
_surfaceService = surfaceService;
|
||||
_rgbService.Surface.Updating += SurfaceOnUpdating;
|
||||
|
||||
_rgbService.Surface.Updated += SurfaceOnUpdated;
|
||||
Task.Run(Initialize);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace Artemis.Core.Services
|
||||
module.Render(args.DeltaTime, _surfaceService.ActiveSurface, g);
|
||||
}
|
||||
|
||||
OnFrameRendered(new FrameEventArgs(modules, _rgbService.GraphicsDecorator.GetBitmap(), args.DeltaTime, _rgbService.Surface));
|
||||
OnFrameRendering(new FrameRenderingEventArgs(modules, _rgbService.GraphicsDecorator.GetBitmap(), args.DeltaTime, _rgbService.Surface));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -95,10 +95,16 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
private void SurfaceOnUpdated(UpdatedEventArgs args)
|
||||
{
|
||||
OnFrameRendered(new FrameRenderedEventArgs(_rgbService.GraphicsDecorator.GetBitmap(), _rgbService.Surface));
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler Initialized;
|
||||
public event EventHandler<FrameEventArgs> FrameRendered;
|
||||
public event EventHandler<FrameRenderingEventArgs> FrameRendering;
|
||||
public event EventHandler<FrameRenderedEventArgs> FrameRendered;
|
||||
|
||||
private void OnInitialized()
|
||||
{
|
||||
@@ -108,7 +114,12 @@ namespace Artemis.Core.Services
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void OnFrameRendered(FrameEventArgs e)
|
||||
protected virtual void OnFrameRendering(FrameRenderingEventArgs e)
|
||||
{
|
||||
FrameRendering?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnFrameRendered(FrameRenderedEventArgs e)
|
||||
{
|
||||
FrameRendered?.Invoke(this, e);
|
||||
}
|
||||
|
||||
@@ -16,8 +16,13 @@ namespace Artemis.Core.Services.Interfaces
|
||||
event EventHandler Initialized;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs whenever a frame has finished rendering
|
||||
/// Occurs whenever a frame is rendering, after modules have rendered
|
||||
/// </summary>
|
||||
event EventHandler<FrameEventArgs> FrameRendered;
|
||||
event EventHandler<FrameRenderingEventArgs> FrameRendering;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs whenever a frame is finished rendering and processed by RGB.NET
|
||||
/// </summary>
|
||||
event EventHandler<FrameRenderedEventArgs> FrameRendered;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Services.Interfaces
|
||||
{
|
||||
@@ -91,5 +92,7 @@ namespace Artemis.Core.Services.Interfaces
|
||||
event EventHandler<PluginEventArgs> PluginDisabled;
|
||||
|
||||
#endregion
|
||||
|
||||
Plugin GetDevicePlugin(IRGBDevice device);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ using Newtonsoft.Json;
|
||||
using Ninject;
|
||||
using Ninject.Extensions.ChildKernel;
|
||||
using Ninject.Parameters;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
@@ -102,7 +103,7 @@ namespace Artemis.Core.Services
|
||||
|
||||
// Create a child kernel and app domain that will only contain the plugins
|
||||
_childKernel = new ChildKernel(_kernel);
|
||||
|
||||
|
||||
// Load the plugin assemblies into the plugin context
|
||||
var pluginDirectory = new DirectoryInfo(Path.Combine(Constants.DataFolder, "plugins"));
|
||||
foreach (var subDirectory in pluginDirectory.EnumerateDirectories())
|
||||
@@ -282,6 +283,11 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
public Plugin GetDevicePlugin(IRGBDevice rgbDevice)
|
||||
{
|
||||
return GetPluginsOfType<Device>().First(d => d.DeviceProvider.Devices.Contains(rgbDevice));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
UnloadPlugins();
|
||||
|
||||
@@ -18,15 +18,17 @@ namespace Artemis.Core.Services.Storage
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly IPluginService _pluginService;
|
||||
private readonly List<Surface> _surfaceConfigurations;
|
||||
private readonly ISurfaceRepository _surfaceRepository;
|
||||
private readonly PluginSetting<double> _renderScaleSetting;
|
||||
|
||||
internal SurfaceService(ILogger logger, ISurfaceRepository surfaceRepository, IRgbService rgbService, ISettingsService settingsService)
|
||||
internal SurfaceService(ILogger logger, ISurfaceRepository surfaceRepository, IRgbService rgbService, IPluginService pluginService, ISettingsService settingsService)
|
||||
{
|
||||
_logger = logger;
|
||||
_surfaceRepository = surfaceRepository;
|
||||
_rgbService = rgbService;
|
||||
_pluginService = pluginService;
|
||||
_surfaceConfigurations = new List<Surface>();
|
||||
_renderScaleSetting = settingsService.GetSetting("RenderScale", 1.0);
|
||||
|
||||
@@ -36,8 +38,6 @@ namespace Artemis.Core.Services.Storage
|
||||
_renderScaleSetting.SettingChanged += RenderScaleSettingOnSettingChanged;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Surface ActiveSurface { get; private set; }
|
||||
public ReadOnlyCollection<Surface> SurfaceConfigurations => _surfaceConfigurations.AsReadOnly();
|
||||
|
||||
@@ -47,8 +47,11 @@ namespace Artemis.Core.Services.Storage
|
||||
var configuration = new Surface(_rgbService.Surface, name, _renderScaleSetting.Value);
|
||||
|
||||
// Add all current devices
|
||||
foreach (var rgbDevice in _rgbService.LoadedDevices)
|
||||
configuration.Devices.Add(new Device(rgbDevice, configuration));
|
||||
foreach (var rgbDevice in _rgbService.LoadedDevices)
|
||||
{
|
||||
var plugin = _pluginService.GetDevicePlugin(rgbDevice);
|
||||
configuration.Devices.Add(new Device(rgbDevice, plugin, configuration));
|
||||
}
|
||||
|
||||
lock (_surfaceConfigurations)
|
||||
{
|
||||
@@ -140,9 +143,8 @@ namespace Artemis.Core.Services.Storage
|
||||
|
||||
private void RenderScaleSettingOnSettingChanged(object sender, EventArgs e)
|
||||
{
|
||||
foreach (var surfaceConfiguration in SurfaceConfigurations)
|
||||
foreach (var surfaceConfiguration in SurfaceConfigurations)
|
||||
surfaceConfiguration.UpdateScale(_renderScaleSetting.Value);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -156,6 +158,15 @@ namespace Artemis.Core.Services.Storage
|
||||
{
|
||||
// Create the surface entity
|
||||
var surfaceConfiguration = new Surface(_rgbService.Surface, surfaceEntity, _renderScaleSetting.Value);
|
||||
foreach (var position in surfaceEntity.DeviceEntities)
|
||||
{
|
||||
var device = _rgbService.Surface.Devices.FirstOrDefault(d => d.GetDeviceHashCode() == position.DeviceHashCode);
|
||||
if (device != null)
|
||||
{
|
||||
var plugin = _pluginService.GetDevicePlugin(device);
|
||||
surfaceConfiguration.Devices.Add(new Device(device, plugin, surfaceConfiguration, position));
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, add the surface config to the collection
|
||||
lock (_surfaceConfigurations)
|
||||
@@ -189,11 +200,14 @@ namespace Artemis.Core.Services.Storage
|
||||
|
||||
if (device != null)
|
||||
return;
|
||||
|
||||
|
||||
// Find an existing device config and use that
|
||||
var existingDeviceConfig = surface.SurfaceEntity.DeviceEntities.FirstOrDefault(d => d.DeviceHashCode == deviceHashCode);
|
||||
if (existingDeviceConfig != null)
|
||||
device = new Device(rgbDevice,surface, existingDeviceConfig);
|
||||
if (existingDeviceConfig != null)
|
||||
{
|
||||
var plugin = _pluginService.GetDevicePlugin(rgbDevice);
|
||||
device = new Device(rgbDevice, plugin, surface, existingDeviceConfig);
|
||||
}
|
||||
// Fall back on creating a new device
|
||||
else
|
||||
{
|
||||
@@ -202,7 +216,8 @@ namespace Artemis.Core.Services.Storage
|
||||
rgbDevice.DeviceInfo,
|
||||
deviceHashCode
|
||||
);
|
||||
device = new Device(rgbDevice, surface);
|
||||
var plugin = _pluginService.GetDevicePlugin(rgbDevice);
|
||||
device = new Device(rgbDevice, plugin, surface);
|
||||
}
|
||||
|
||||
surface.Devices.Add(device);
|
||||
|
||||
Reference in new issue
Block a user