mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Redid some of the surface editor and started working on layout saving
This commit is contained in:
1 parent
81294eef8f
commit
71f53c0833
48 files changed
+1012
-107
No files matched your search
@@ -4,6 +4,7 @@ using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using RGB.NET.Core;
|
||||
using Serilog;
|
||||
using Color = System.Drawing.Color;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
@@ -13,11 +14,13 @@ namespace Artemis.Core.Services
|
||||
/// </summary>
|
||||
public class CoreService : ICoreService
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IPluginService _pluginService;
|
||||
private readonly IRgbService _rgbService;
|
||||
|
||||
internal CoreService(IPluginService pluginService, IRgbService rgbService)
|
||||
internal CoreService(ILogger logger, IPluginService pluginService, IRgbService rgbService)
|
||||
{
|
||||
_logger = logger;
|
||||
_pluginService = pluginService;
|
||||
_rgbService = rgbService;
|
||||
_rgbService.Surface.Updating += SurfaceOnUpdating;
|
||||
@@ -38,6 +41,8 @@ namespace Artemis.Core.Services
|
||||
if (IsInitialized)
|
||||
throw new ArtemisCoreException("Cannot initialize the core as it is already initialized.");
|
||||
|
||||
_logger.Information("Initializing Artemis Core version {version}", typeof(CoreService).Assembly.GetName().Version);
|
||||
|
||||
// Initialize the services
|
||||
await Task.Run(() => _pluginService.CopyBuiltInPlugins());
|
||||
await Task.Run(() => _pluginService.LoadPlugins());
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
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;
|
||||
using Serilog;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
@@ -17,10 +20,14 @@ namespace Artemis.Core.Services
|
||||
public class RgbService : IRgbService, IDisposable
|
||||
{
|
||||
private readonly List<IRGBDevice> _loadedDevices;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISurfaceService _surfaceService;
|
||||
private readonly TimerUpdateTrigger _updateTrigger;
|
||||
|
||||
internal RgbService()
|
||||
internal RgbService(ILogger logger, ISurfaceService surfaceService)
|
||||
{
|
||||
_logger = logger;
|
||||
_surfaceService = surfaceService;
|
||||
Surface = RGBSurface.Instance;
|
||||
LoadingDevices = false;
|
||||
|
||||
@@ -33,7 +40,7 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool LoadingDevices { get; private set; }
|
||||
public bool LoadingDevices { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public RGBSurface Surface { get; set; }
|
||||
@@ -43,9 +50,17 @@ namespace Artemis.Core.Services
|
||||
public void AddDeviceProvider(IRGBDeviceProvider deviceProvider)
|
||||
{
|
||||
Surface.LoadDevices(deviceProvider);
|
||||
|
||||
|
||||
if (deviceProvider.Devices == null)
|
||||
{
|
||||
_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)
|
||||
{
|
||||
@@ -54,10 +69,16 @@ 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +96,31 @@ 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;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
|
||||
namespace Artemis.Core.Services.Storage
|
||||
{
|
||||
public class SurfaceService : ISurfaceService
|
||||
{
|
||||
private readonly ISurfaceRepository _surfaceRepository;
|
||||
|
||||
public SurfaceService(ISurfaceRepository surfaceRepository)
|
||||
{
|
||||
_surfaceRepository = surfaceRepository;
|
||||
}
|
||||
|
||||
public async Task<List<SurfaceConfiguration>> GetSurfaceConfigurations()
|
||||
{
|
||||
var surfaceEntities = await _surfaceRepository.GetAllAsync();
|
||||
var configs = new List<SurfaceConfiguration>();
|
||||
foreach (var surfaceEntity in surfaceEntities)
|
||||
configs.Add(new SurfaceConfiguration(surfaceEntity));
|
||||
|
||||
return configs;
|
||||
}
|
||||
|
||||
public SurfaceConfiguration GetActiveSurfaceConfiguration()
|
||||
{
|
||||
var entity = _surfaceRepository.GetAll().FirstOrDefault(d => d.IsActive);
|
||||
return entity != null ? new SurfaceConfiguration(entity) : null;
|
||||
}
|
||||
}
|
||||
|
||||
public interface ISurfaceService : IArtemisService
|
||||
{
|
||||
Task<List<SurfaceConfiguration>> GetSurfaceConfigurations();
|
||||
SurfaceConfiguration GetActiveSurfaceConfiguration();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.ProfileElements;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Repositories;
|
||||
|
||||
|
||||
Reference in new issue
Block a user