1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 17:48:31 +00:00

Added debug-device-provider

This commit is contained in:
Darth Affe 2018-01-17 22:23:20 +01:00
parent 739fbf8733
commit e78525118f
8 changed files with 362 additions and 0 deletions

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>RGB.NET.Devices.Debug</id>
<title>RGB.NET.Devices.Debug</title>
<version>0.0.1</version>
<authors>Darth Affe</authors>
<owners>Darth Affe</owners>
<projectUrl>https://github.com/DarthAffe/RGB.NET</projectUrl>
<licenseUrl>https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE</licenseUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<description>Debug-Device-Implementations of RGB.NET</description>
<releaseNotes></releaseNotes>
<summary>Debug-Device-Implementations of RGB.NET, a C# (.NET) library</summary>
<copyright>Copyright © Wyrez 2017</copyright>
<language>en-US</language>
<dependencies>
<dependency id="RGB.NET.Core" version="0.0.1" />
<dependency id="System.ValueTuple" version="4.4.0" />
</dependencies>
</metadata>
<files>
<file src="..\bin\RGB.NET.Devices.Debug.dll" target="lib\net45\RGB.NET.Devices.Debug.dll" />
<file src="..\bin\RGB.NET.Devices.Debug.pdb" target="lib\net45\RGB.NET.Devices.Debug.pdb" />
<file src="..\bin\RGB.NET.Devices.Debug.xml" target="lib\net45\RGB.NET.Devices.Debug.xml" />
<file src="..\RGB.NET.Devices.Debug\**\*.cs" target="src" exclude="..\RGB.NET.Devices.Debug\obj\**\*.*" />
</files>
</package>

View File

@ -0,0 +1,103 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System;
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.Debug
{
/// <inheritdoc />
/// <summary>
/// Represents a device provider responsible for debug devices.
/// </summary>
public class DebugDeviceProvider : IRGBDeviceProvider
{
#region Properties & Fields
private static DebugDeviceProvider _instance;
/// <summary>
/// Gets the singleton <see cref="DebugDeviceProvider"/> instance.
/// </summary>
public static DebugDeviceProvider Instance => _instance ?? new DebugDeviceProvider();
/// <inheritdoc />
public bool IsInitialized { get; private set; }
/// <inheritdoc />
public IEnumerable<IRGBDevice> Devices { get; private set; }
/// <inheritdoc />
public bool HasExclusiveAccess { get; private set; }
private List<(string layout, string imageLayout, Func<Dictionary<LedId, Color>> syncBackFunc, Action<IEnumerable<Led>> updateLedsAction)> _fakeDeviceDefinitions
= new List<(string layout, string imageLayout, Func<Dictionary<LedId, Color>> syncBackFunc, Action<IEnumerable<Led>> updateLedsAction)>();
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="DebugDeviceProvider"/> class.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public DebugDeviceProvider()
{
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DebugDeviceProvider)}");
_instance = this;
}
#endregion
#region Methods
/// <summary>
/// Adds a new fake device definition.
/// </summary>
/// <param name="layout">The path of the layout file to be used.</param>
/// <param name="imageLayout">The image-layout to load.</param>
/// <param name="syncBackFunc">A function emulating device syncback.</param>
/// <param name="updateLedsAction">A action emulating led-updates.</param>
public void AddFakeDeviceDefinition(string layout, string imageLayout, Func<Dictionary<LedId, Color>> syncBackFunc = null, Action<IEnumerable<Led>> updateLedsAction = null)
=> _fakeDeviceDefinitions.Add((layout, imageLayout, syncBackFunc, updateLedsAction));
/// <summary>
/// Removes all previously added fake device definitions.
/// </summary>
public void ClearFakeDeviceDefinitions() => _fakeDeviceDefinitions.Clear();
/// <inheritdoc />
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.Unknown, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
{
IsInitialized = false;
try
{
HasExclusiveAccess = exclusiveAccessIfPossible;
IsInitialized = true;
List<IRGBDevice> devices = new List<IRGBDevice>();
foreach ((string layout, string imageLayout, Func<Dictionary<LedId, Color>> syncBackFunc, Action<IEnumerable<Led>> updateLedsAction) in _fakeDeviceDefinitions)
{
DebugRGBDevice device = new DebugRGBDevice(layout, syncBackFunc, updateLedsAction);
device.Initialize(layout, imageLayout);
devices.Add(device);
}
Devices = devices;
return true;
}
catch
{
if (throwExceptions) throw;
return false;
}
}
/// <inheritdoc />
public void ResetDevices()
{ }
#endregion
}
}

View File

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Core.Layout;
namespace RGB.NET.Devices.Debug
{
/// <inheritdoc />
/// <summary>
/// Represents a debug device.
/// </summary>
public class DebugRGBDevice : AbstractRGBDevice<DebugRGBDeviceInfo>
{
#region Properties & Fields
/// <inheritdoc />
public override DebugRGBDeviceInfo DeviceInfo { get; }
private Func<Dictionary<LedId, Color>> _syncBackFunc;
private Action<IEnumerable<Led>> _updateLedsAction;
#endregion
#region Constructors
/// <summary>
/// Internal constructor of <see cref="DebugRGBDeviceInfo"/>.
/// </summary>
internal DebugRGBDevice(string layoutPath, Func<Dictionary<LedId, Color>> syncBackFunc = null, Action<IEnumerable<Led>> updateLedsAction = null)
{
this._syncBackFunc = syncBackFunc;
this._updateLedsAction = updateLedsAction;
DeviceLayout layout = DeviceLayout.Load(layoutPath);
DeviceInfo = new DebugRGBDeviceInfo(layout.Type, layout.Vendor, layout.Model, layout.Lighting, syncBackFunc != null);
}
#endregion
#region Methods
internal void Initialize(string layoutPath, string imageLayout) => ApplyLayoutFromFile(layoutPath, imageLayout, true);
/// <inheritdoc />
public override void SyncBack()
{
try
{
Dictionary<LedId, Color> syncBackValues = _syncBackFunc?.Invoke();
if (syncBackValues == null) return;
foreach (KeyValuePair<LedId, Color> value in syncBackValues)
{
Led led = ((IRGBDevice)this)[value.Key];
if (led != null)
led.Color = value.Value;
}
}
catch {/* ics that's not my fault ... */}
}
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => _updateLedsAction?.Invoke(ledsToUpdate);
#endregion
}
}

View File

@ -0,0 +1,55 @@
using System;
using RGB.NET.Core;
namespace RGB.NET.Devices.Debug
{
/// <inheritdoc />
/// <summary>
/// Represents device information for a <see cref="DebugRGBDevice"/> />.
/// </summary>
public class DebugRGBDeviceInfo : IRGBDeviceInfo
{
#region Properties & Fields
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string Manufacturer { get; }
/// <inheritdoc />
public string Model { get; }
/// <inheritdoc />
public RGBDeviceLighting Lighting { get; }
/// <inheritdoc />
public bool SupportsSyncBack { get; }
/// <inheritdoc />
public Uri Image { get; set; }
#endregion
#region Constructors
/// <summary>
/// Internal constructor of <see cref="DebugRGBDeviceInfo"/>.
/// </summary>
/// <param name="deviceType">The <see cref="RGBDeviceType"/> of the device.</param>
/// <param name="manufacturer">The manufacturer of the device.</param>
/// <param name="model">The model of the device.</param>
/// <param name="lighting">The <see cref="RGBDeviceLighting"/> of the device.</param>
/// <param name="supportsSyncBack">True if the device supports syncback; false if not.</param>
internal DebugRGBDeviceInfo(RGBDeviceType deviceType, string manufacturer, string model, RGBDeviceLighting lighting, bool supportsSyncBack)
{
this.DeviceType = deviceType;
this.Manufacturer = manufacturer;
this.Model = model;
this.Lighting = lighting;
this.SupportsSyncBack = supportsSyncBack;
}
#endregion
}
}

View File

@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RGB.NET.Devices.Debug")]
[assembly: AssemblyDescription("Debug-Device-Implementations of RGB.NET")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Wyrez")]
[assembly: AssemblyProduct("RGB.NET.Devices.Debug")]
[assembly: AssemblyCopyright("Copyright © Wyrez 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d013040e-1931-4f0d-9cca-0f4ae74a507e")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D013040E-1931-4F0D-9CCA-0F4AE74A507E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RGB.NET.Devices.Debug</RootNamespace>
<AssemblyName>RGB.NET.Devices.Debug</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>..\bin\RGB.NET.Devices.Debug.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>..\bin\RGB.NET.Devices.Debug.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DebugDeviceProvider.cs" />
<Compile Include="DebugRGBDevice.cs" />
<Compile Include="DebugRGBDeviceInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj">
<Project>{5a4f9a75-75fe-47cd-90e5-914d5b20d232}</Project>
<Name>RGB.NET.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.ValueTuple" version="4.4.0" targetFramework="net45" />
</packages>

View File

@ -31,6 +31,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{06416566
NuGet\RGB.NET.Devices.Asus.nuspec = NuGet\RGB.NET.Devices.Asus.nuspec
NuGet\RGB.NET.Devices.CoolerMaster.nuspec = NuGet\RGB.NET.Devices.CoolerMaster.nuspec
NuGet\RGB.NET.Devices.Corsair.nuspec = NuGet\RGB.NET.Devices.Corsair.nuspec
NuGet\RGB.NET.Devices.Debug.nuspec = NuGet\RGB.NET.Devices.Debug.nuspec
NuGet\RGB.NET.Devices.Logitech.nuspec = NuGet\RGB.NET.Devices.Logitech.nuspec
NuGet\RGB.NET.Devices.Msi.nuspec = NuGet\RGB.NET.Devices.Msi.nuspec
NuGet\RGB.NET.Devices.Novation.nuspec = NuGet\RGB.NET.Devices.Novation.nuspec
@ -65,6 +66,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Metapackages", "Metapackage
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RGB.NET.Devices.Razer", "RGB.NET.Devices.Razer\RGB.NET.Devices.Razer.csproj", "{24FF4ACB-D679-4B2D-86D4-50AB6C02D816}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RGB.NET.Devices.Debug", "RGB.NET.Devices.Debug\RGB.NET.Devices.Debug.csproj", "{D013040E-1931-4F0D-9CCA-0F4AE74A507E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -123,6 +126,10 @@ Global
{24FF4ACB-D679-4B2D-86D4-50AB6C02D816}.Debug|Any CPU.Build.0 = Debug|Any CPU
{24FF4ACB-D679-4B2D-86D4-50AB6C02D816}.Release|Any CPU.ActiveCfg = Release|Any CPU
{24FF4ACB-D679-4B2D-86D4-50AB6C02D816}.Release|Any CPU.Build.0 = Release|Any CPU
{D013040E-1931-4F0D-9CCA-0F4AE74A507E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D013040E-1931-4F0D-9CCA-0F4AE74A507E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D013040E-1931-4F0D-9CCA-0F4AE74A507E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D013040E-1931-4F0D-9CCA-0F4AE74A507E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -141,6 +148,7 @@ Global
{4EFD77C7-FDB4-4C6B-970C-0EF66D24BE09} = {33D5E279-1C4E-4AB6-9D1E-6D18109A6C25}
{C191D5BE-E1B2-47E4-AB39-D954B277188C} = {06416566-481F-4571-80EE-7BB05B1E0299}
{24FF4ACB-D679-4B2D-86D4-50AB6C02D816} = {33D5E279-1C4E-4AB6-9D1E-6D18109A6C25}
{D013040E-1931-4F0D-9CCA-0F4AE74A507E} = {33D5E279-1C4E-4AB6-9D1E-6D18109A6C25}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CDECA6C7-8D18-4AF3-94F7-C70A69B8571B}