Started on RGB.NET implementation

This commit is contained in:
SpoinkyNL committed 2018-01-09 00:09:22 +01:00
1 parent e43d632adb
commit 7d4c5dbae6
6 files changed
+153 -12

No files matched your search

+2
View File
@@ -185,11 +185,13 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Constants.cs" />
<Compile Include="Events\DeviceEventArgs.cs" />
<Compile Include="Exceptions\ArtemisCoreException.cs" />
<Compile Include="Exceptions\ArtemisPluginException.cs" />
<Compile Include="Ninject\CoreModule.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\CoreService.cs" />
<Compile Include="Services\DeviceService.cs" />
<Compile Include="Services\Interfaces\IArtemisService.cs" />
<Compile Include="Services\Interfaces\ICoreService.cs" />
<Compile Include="Services\Interfaces\IPluginService.cs" />
@@ -0,0 +1,19 @@
using System;
using RGB.NET.Core;
namespace Artemis.Core.Events
{
public class DeviceEventArgs : EventArgs
{
public DeviceEventArgs()
{
}
public DeviceEventArgs(IRGBDevice device)
{
Device = device;
}
public IRGBDevice Device { get; }
}
}
+10 -1
View File
@@ -5,6 +5,15 @@ namespace Artemis.Core.Events
{
public class PluginEventArgs : EventArgs
{
public IPlugin Plugin { get; set; }
public PluginEventArgs()
{
}
public PluginEventArgs(IPlugin plugin)
{
Plugin = plugin;
}
public IPlugin Plugin { get; }
}
}
+4 -2
View File
@@ -6,10 +6,12 @@ namespace Artemis.Core.Services
public class CoreService : ICoreService
{
private readonly IPluginService _pluginService;
private readonly IDeviceService _deviceService;
public CoreService(IPluginService pluginService)
public CoreService(IPluginService pluginService, IDeviceService deviceService)
{
_pluginService = pluginService;
_deviceService = deviceService;
Task.Run(Initialize);
}
@@ -23,7 +25,7 @@ namespace Artemis.Core.Services
private async Task Initialize()
{
await _pluginService.LoadPlugins();
await _deviceService.LoadDevices();
IsInitialized = true;
}
}
+117
View File
@@ -0,0 +1,117 @@
using System;
using System.Threading.Tasks;
using Artemis.Core.Events;
using Artemis.Core.Services.Interfaces;
using RGB.NET.Brushes;
using RGB.NET.Core;
using RGB.NET.Devices.CoolerMaster;
using RGB.NET.Devices.Corsair;
using RGB.NET.Devices.Logitech;
using RGB.NET.Groups;
namespace Artemis.Core.Services
{
public class DeviceService : IDeviceService, IDisposable
{
public DeviceService()
{
Surface = RGBSurface.Instance;
LoadingDevices = false;
// Let's throw these for now
Surface.Exception += SurfaceOnException;
}
public bool LoadingDevices { get; private set; }
public RGBSurface Surface { get; set; }
public async Task LoadDevices()
{
OnStartedLoadingDevices();
await Task.Run(() =>
{
// TODO SpoinkyNL 8-1-18: Keep settings into account
// Surface.LoadDevices(AsusDeviceProvider.Instance);
Surface.LoadDevices(CorsairDeviceProvider.Instance);
Surface.LoadDevices(LogitechDeviceProvider.Instance);
Surface.LoadDevices(CoolerMasterDeviceProvider.Instance);
// Surface.LoadDevices(NovationDeviceProvider.Instance);
// TODO SpoinkyNL 8-1-18: Load alignment
Surface.AlignDevies();
// Do some testing, why does this work, how does it know I want to target the surface? Check source!
var ledGroup = new RectangleLedGroup(Surface.SurfaceRectangle)
{
Brush = new SolidColorBrush(new Color(255, 0, 0)) {BrushCalculationMode = BrushCalculationMode.Absolute}
};
Surface.UpdateMode = UpdateMode.Continuous;
});
OnFinishedLoadedDevices();
}
public void Dispose()
{
Surface.Dispose();
}
private void SurfaceOnException(ExceptionEventArgs args)
{
throw args.Exception;
}
#region Events
/// <summary>
/// Occurs when a single device has loaded
/// </summary>
public event EventHandler<DeviceEventArgs> DeviceLoaded;
/// <summary>
/// Occurs when a single device has reloaded
/// </summary>
public event EventHandler<DeviceEventArgs> DeviceReloaded;
/// <summary>
/// Occurs when loading all devices has started
/// </summary>
public event EventHandler StartedLoadingDevices;
/// <summary>
/// Occurs when loading all devices has finished
/// </summary>
public event EventHandler FinishedLoadedDevices;
private void OnDeviceLoaded(DeviceEventArgs e)
{
DeviceLoaded?.Invoke(this, e);
}
private void OnDeviceReloaded(DeviceEventArgs e)
{
DeviceReloaded?.Invoke(this, e);
}
private void OnStartedLoadingDevices()
{
LoadingDevices = true;
StartedLoadingDevices?.Invoke(this, EventArgs.Empty);
}
private void OnFinishedLoadedDevices()
{
LoadingDevices = false;
FinishedLoadedDevices?.Invoke(this, EventArgs.Empty);
}
#endregion
}
public interface IDeviceService : IArtemisService
{
Task LoadDevices();
}
}