mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Added active surface-config management code
Added surface-config creation
This commit is contained in:
1 parent
10b2328561
commit
e26516bce0
15 files changed
+268
-140
No files matched your search
@@ -1,12 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.RGB.NET;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage;
|
||||
using Artemis.Storage.Entities;
|
||||
using RGB.NET.Brushes;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Groups;
|
||||
@@ -21,15 +18,12 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
private readonly List<IRGBDevice> _loadedDevices;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISurfaceService _surfaceService;
|
||||
private readonly TimerUpdateTrigger _updateTrigger;
|
||||
|
||||
internal RgbService(ILogger logger, ISurfaceService surfaceService)
|
||||
internal RgbService(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_surfaceService = surfaceService;
|
||||
Surface = RGBSurface.Instance;
|
||||
LoadingDevices = false;
|
||||
|
||||
// Let's throw these for now
|
||||
Surface.Exception += SurfaceOnException;
|
||||
@@ -39,14 +33,22 @@ namespace Artemis.Core.Services
|
||||
Surface.RegisterUpdateTrigger(_updateTrigger);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool LoadingDevices { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public RGBSurface Surface { get; set; }
|
||||
|
||||
public GraphicsDecorator GraphicsDecorator { get; private set; }
|
||||
|
||||
public IReadOnlyCollection<IRGBDevice> LoadedDevices
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_loadedDevices)
|
||||
{
|
||||
return _loadedDevices.AsReadOnly();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddDeviceProvider(IRGBDeviceProvider deviceProvider)
|
||||
{
|
||||
Surface.LoadDevices(deviceProvider);
|
||||
@@ -56,12 +58,7 @@ namespace Artemis.Core.Services
|
||||
_logger.Warning("Device provider {deviceProvider} has no devices", deviceProvider.GetType().Name);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the currently active surface configuration
|
||||
var surface = _surfaceService.GetActiveSurfaceConfiguration();
|
||||
if (surface == null)
|
||||
_logger.Information("No active surface configuration found, not positioning device");
|
||||
|
||||
|
||||
lock (_loadedDevices)
|
||||
{
|
||||
foreach (var surfaceDevice in deviceProvider.Devices)
|
||||
@@ -69,14 +66,10 @@ namespace Artemis.Core.Services
|
||||
if (!_loadedDevices.Contains(surfaceDevice))
|
||||
{
|
||||
_loadedDevices.Add(surfaceDevice);
|
||||
if (surface != null)
|
||||
ApplyDeviceConfiguration(surfaceDevice, surface);
|
||||
OnDeviceLoaded(new DeviceEventArgs(surfaceDevice));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (surface != null)
|
||||
ApplyDeviceConfiguration(surfaceDevice, surface);
|
||||
OnDeviceReloaded(new DeviceEventArgs(surfaceDevice));
|
||||
}
|
||||
}
|
||||
@@ -96,31 +89,6 @@ namespace Artemis.Core.Services
|
||||
Surface.Dispose();
|
||||
}
|
||||
|
||||
public void ApplyDeviceConfiguration(IRGBDevice rgbDevice, SurfaceConfiguration surface)
|
||||
{
|
||||
// Determine the device ID by assuming devices are always added to the loaded devices list in the same order
|
||||
lock (_loadedDevices)
|
||||
{
|
||||
var deviceId = _loadedDevices.Where(d => d.DeviceInfo.DeviceName == rgbDevice.DeviceInfo.DeviceName &&
|
||||
d.DeviceInfo.Model == rgbDevice.DeviceInfo.Model &&
|
||||
d.DeviceInfo.Manufacturer == rgbDevice.DeviceInfo.Manufacturer)
|
||||
.ToList()
|
||||
.IndexOf(rgbDevice) + 1;
|
||||
|
||||
var deviceConfig = surface.DeviceConfigurations.FirstOrDefault(d => d.DeviceName == rgbDevice.DeviceInfo.DeviceName &&
|
||||
d.DeviceModel == rgbDevice.DeviceInfo.Model &&
|
||||
d.DeviceManufacturer == rgbDevice.DeviceInfo.Manufacturer &&
|
||||
d.DeviceId == deviceId);
|
||||
if (deviceConfig == null)
|
||||
{
|
||||
_logger.Information("No surface device config found for {deviceInfo}, device ID: {deviceId}", rgbDevice.DeviceInfo, deviceId);
|
||||
return;
|
||||
}
|
||||
|
||||
rgbDevice.Location = new Point(deviceConfig.X, deviceConfig.Y);
|
||||
}
|
||||
}
|
||||
|
||||
private void SurfaceOnException(ExceptionEventArgs args)
|
||||
{
|
||||
throw args.Exception;
|
||||
|
||||
Reference in new issue
Block a user