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

Device providers - Let's actually include the SDKs!

Core - Enable exceptions during device provider init so that they can be logged
This commit is contained in:
Robert 2020-03-02 23:42:33 +01:00
parent c3b2c981da
commit 16b221d2f8
13 changed files with 89 additions and 24 deletions

View File

@ -33,13 +33,7 @@ namespace Artemis.Core.Services.Interfaces
/// </summary> /// </summary>
/// <param name="deviceProvider"></param> /// <param name="deviceProvider"></param>
void AddDeviceProvider(IRGBDeviceProvider deviceProvider); void AddDeviceProvider(IRGBDeviceProvider deviceProvider);
/// <summary>
/// Removes the given device provider from the <see cref="Surface" /> by recreating it without the device provider
/// </summary>
/// <param name="deviceProvider"></param>
void RemoveDeviceProvider(IRGBDeviceProvider deviceProvider);
void Dispose(); void Dispose();
/// <summary> /// <summary>

View File

@ -18,14 +18,13 @@ namespace Artemis.Core.Services
public class RgbService : IRgbService, IDisposable public class RgbService : IRgbService, IDisposable
{ {
private readonly List<IRGBDevice> _loadedDevices; private readonly List<IRGBDevice> _loadedDevices;
private readonly List<IRGBDeviceProvider> _loadedDeviceProviders;
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly PluginSetting<double> _renderScaleSetting; private readonly PluginSetting<double> _renderScaleSetting;
private readonly PluginSetting<int> _sampleSizeSetting; private readonly PluginSetting<int> _sampleSizeSetting;
private readonly PluginSetting<int> _targetFrameRateSetting; private readonly PluginSetting<int> _targetFrameRateSetting;
private readonly TimerUpdateTrigger _updateTrigger; private readonly TimerUpdateTrigger _updateTrigger;
private ListLedGroup _surfaceLedGroup; private ListLedGroup _surfaceLedGroup;
internal RgbService(ILogger logger, ISettingsService settingsService) internal RgbService(ILogger logger, ISettingsService settingsService)
{ {
_logger = logger; _logger = logger;
@ -40,7 +39,6 @@ namespace Artemis.Core.Services
_renderScaleSetting.SettingChanged += RenderScaleSettingOnSettingChanged; _renderScaleSetting.SettingChanged += RenderScaleSettingOnSettingChanged;
_targetFrameRateSetting.SettingChanged += TargetFrameRateSettingOnSettingChanged; _targetFrameRateSetting.SettingChanged += TargetFrameRateSettingOnSettingChanged;
_loadedDevices = new List<IRGBDevice>(); _loadedDevices = new List<IRGBDevice>();
_loadedDeviceProviders = new List<IRGBDeviceProvider>();
_updateTrigger = new TimerUpdateTrigger {UpdateFrequency = 1.0 / _targetFrameRateSetting.Value}; _updateTrigger = new TimerUpdateTrigger {UpdateFrequency = 1.0 / _targetFrameRateSetting.Value};
Surface.RegisterUpdateTrigger(_updateTrigger); Surface.RegisterUpdateTrigger(_updateTrigger);
} }
@ -56,15 +54,18 @@ namespace Artemis.Core.Services
public void AddDeviceProvider(IRGBDeviceProvider deviceProvider) public void AddDeviceProvider(IRGBDeviceProvider deviceProvider)
{ {
if (_loadedDeviceProviders.Contains(deviceProvider)) try
return; {
Surface.LoadDevices(deviceProvider, RGBDeviceType.All, false, true);
Surface.LoadDevices(deviceProvider); }
_loadedDeviceProviders.Add(deviceProvider); catch (Exception e)
{
_logger.Error(e, "Exception during device loading for device provider {deviceProvider}", deviceProvider.GetType().Name);
}
if (deviceProvider.Devices == null) if (deviceProvider.Devices == null)
{ {
_logger.Warning("RgbDevice provider {deviceProvider} has no devices", deviceProvider.GetType().Name); _logger.Warning("Device provider {deviceProvider} has no devices", deviceProvider.GetType().Name);
return; return;
} }
@ -80,12 +81,6 @@ namespace Artemis.Core.Services
} }
} }
public void RemoveDeviceProvider(IRGBDeviceProvider deviceProvider)
{
if (!_loadedDeviceProviders.Contains(deviceProvider))
return;
}
public void Dispose() public void Dispose()
{ {
Surface.UnregisterUpdateTrigger(_updateTrigger); Surface.UnregisterUpdateTrigger(_updateTrigger);

View File

@ -21,6 +21,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="AvalonEdit" Version="6.0.1" /> <PackageReference Include="AvalonEdit" Version="6.0.1" />
<PackageReference Include="Humanizer.Core" Version="2.7.9" /> <PackageReference Include="Humanizer.Core" Version="2.7.9" />
<PackageReference Include="MaterialDesignExtensions" Version="3.0.0" />
<PackageReference Include="MaterialDesignThemes" Version="3.0.1" /> <PackageReference Include="MaterialDesignThemes" Version="3.0.1" />
<PackageReference Include="Ninject" Version="3.3.4" /> <PackageReference Include="Ninject" Version="3.3.4" />
<PackageReference Include="SkiaSharp" Version="1.68.2-preview.29" /> <PackageReference Include="SkiaSharp" Version="1.68.2-preview.29" />

View File

@ -123,6 +123,7 @@
<PackageReference Include="Hardcodet.NotifyIcon.Wpf.NetCore" Version="1.0.10" /> <PackageReference Include="Hardcodet.NotifyIcon.Wpf.NetCore" Version="1.0.10" />
<PackageReference Include="Humanizer.Core" Version="2.7.9" /> <PackageReference Include="Humanizer.Core" Version="2.7.9" />
<PackageReference Include="MaterialDesignExtensions" Version="3.0.0" /> <PackageReference Include="MaterialDesignExtensions" Version="3.0.0" />
<PackageReference Include="MaterialDesignThemes" Version="3.0.1" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" /> <PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" /> <PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
<PackageReference Include="Ninject" Version="3.3.4" /> <PackageReference Include="Ninject" Version="3.3.4" />

View File

@ -15,6 +15,18 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Remove="x64\CMSDK.dll" />
<None Remove="x86\CMSDK.dll" />
</ItemGroup>
<ItemGroup>
<Content Include="x64\CMSDK.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="x86\CMSDK.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="plugin.json"> <None Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

View File

@ -27,7 +27,6 @@ namespace Artemis.Plugins.Devices.Corsair
public override void DisablePlugin() public override void DisablePlugin()
{ {
_rgbService.RemoveDeviceProvider(RgbDeviceProvider);
} }
public override void Dispose() public override void Dispose()

View File

@ -23,6 +23,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="MaterialDesignThemes" Version="3.0.1" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Artemis.Core\Artemis.Core.csproj"> <ProjectReference Include="..\..\Artemis.Core\Artemis.Core.csproj">
<Private>false</Private> <Private>false</Private>

View File

@ -28,6 +28,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="HidSharp" Version="2.1.0" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Artemis.Core\Artemis.Core.csproj" /> <ProjectReference Include="..\..\Artemis.Core\Artemis.Core.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -1,19 +1,26 @@
using System.IO; using System.IO;
using System.Linq;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models; using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
using HidSharp;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Logitech; using RGB.NET.Devices.Logitech;
using Serilog;
using Serilog.Events;
namespace Artemis.Plugins.Devices.Logitech namespace Artemis.Plugins.Devices.Logitech
{ {
public class LogitechDeviceProvider : DeviceProvider public class LogitechDeviceProvider : DeviceProvider
{ {
private const int VENDOR_ID = 0x046D;
private readonly ILogger _logger;
private readonly IRgbService _rgbService; private readonly IRgbService _rgbService;
public LogitechDeviceProvider(PluginInfo pluginInfo, IRgbService rgbService) : base(pluginInfo, RGB.NET.Devices.Logitech.LogitechDeviceProvider.Instance) public LogitechDeviceProvider(PluginInfo pluginInfo, IRgbService rgbService, ILogger logger) : base(pluginInfo, RGB.NET.Devices.Logitech.LogitechDeviceProvider.Instance)
{ {
_rgbService = rgbService; _rgbService = rgbService;
_logger = logger;
} }
public override void EnablePlugin() public override void EnablePlugin()
@ -22,6 +29,9 @@ namespace Artemis.Plugins.Devices.Logitech
RGB.NET.Devices.Logitech.LogitechDeviceProvider.PossibleX64NativePaths.Add(Path.Combine(PluginInfo.Directory.FullName, "x64", "LogitechLedEnginesWrapper.dll")); RGB.NET.Devices.Logitech.LogitechDeviceProvider.PossibleX64NativePaths.Add(Path.Combine(PluginInfo.Directory.FullName, "x64", "LogitechLedEnginesWrapper.dll"));
RGB.NET.Devices.Logitech.LogitechDeviceProvider.PossibleX86NativePaths.Add(Path.Combine(PluginInfo.Directory.FullName, "x86", "LogitechLedEnginesWrapper.dll")); RGB.NET.Devices.Logitech.LogitechDeviceProvider.PossibleX86NativePaths.Add(Path.Combine(PluginInfo.Directory.FullName, "x86", "LogitechLedEnginesWrapper.dll"));
_rgbService.AddDeviceProvider(RgbDeviceProvider); _rgbService.AddDeviceProvider(RgbDeviceProvider);
if (_logger.IsEnabled(LogEventLevel.Debug))
LogDeviceIds();
} }
public override void DisablePlugin() public override void DisablePlugin()
@ -31,5 +41,13 @@ namespace Artemis.Plugins.Devices.Logitech
public override void Dispose() public override void Dispose()
{ {
} }
private void LogDeviceIds()
{
var devices = DeviceList.Local.GetHidDevices(VENDOR_ID).ToList();
_logger.Debug("Found {count} Logitech device(s)", devices.Count);
foreach (var hidDevice in devices)
_logger.Debug("Found Logitech device {name} with PID {pid}", hidDevice.GetFriendlyName(), hidDevice.ProductID);
}
} }
} }

View File

@ -15,6 +15,18 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Remove="x64\MysticLight_SDK.dll" />
<None Remove="x86\MysticLight_SDK.dll" />
</ItemGroup>
<ItemGroup>
<Content Include="x64\MysticLight_SDK.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="x86\MysticLight_SDK.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="plugin.json"> <None Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

View File

@ -15,6 +15,18 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Remove="x64\RzChromaSDK.dll" />
<None Remove="x86\RzChromaSDK.dll" />
</ItemGroup>
<ItemGroup>
<Content Include="x64\RzChromaSDK.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="x86\RzChromaSDK.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="plugin.json"> <None Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

View File

@ -15,6 +15,18 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<None Remove="x64\RoccatTalkSDKWrapper.dll" />
<None Remove="x86\RoccatTalkSDKWrapper.dll" />
</ItemGroup>
<ItemGroup>
<Content Include="x64\RoccatTalkSDKWrapper.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="x86\RoccatTalkSDKWrapper.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="plugin.json"> <None Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

View File

@ -23,6 +23,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="MaterialDesignThemes" Version="3.0.1" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Artemis.Core\Artemis.Core.csproj"> <ProjectReference Include="..\..\Artemis.Core\Artemis.Core.csproj">
<Private>false</Private> <Private>false</Private>