Merge pull request #227 from DarthAffe/CodeIssues

Preparing for first major release
This commit is contained in:
DarthAffe authored and GitHub committed 2021-08-07 17:52:20 +02:00
commit 1bae7fd3de
241 files changed
+2168 -794

No files matched your search

@@ -43,7 +43,7 @@ namespace RGB.NET.Devices.Corsair
/// <summary>
/// Gets the last error documented by CUE.
/// </summary>
public CorsairError LastError => _CUESDK.CorsairGetLastError();
public static CorsairError LastError => _CUESDK.CorsairGetLastError();
#endregion
@@ -63,6 +63,7 @@ namespace RGB.NET.Devices.Corsair
#region Methods
/// <inheritdoc />
protected override void InitializeSDK()
{
_CUESDK.Reload();
@@ -80,7 +81,7 @@ namespace RGB.NET.Devices.Corsair
// DarthAffe 02.02.2021: 127 is iCUE
if (!_CUESDK.CorsairSetLayerPriority(128))
Throw(new CUEException(LastError), false);
Throw(new CUEException(LastError));
}
/// <inheritdoc />
@@ -193,6 +194,7 @@ namespace RGB.NET.Devices.Corsair
};
}
/// <inheritdoc />
protected override void Reset()
{
ProtocolDetails = null;
@@ -207,6 +209,8 @@ namespace RGB.NET.Devices.Corsair
try { _CUESDK.UnloadCUESDK(); }
catch { /* at least we tried */ }
GC.SuppressFinalize(this);
}
#endregion
@@ -21,6 +21,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairCustomRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the custom-device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairCustomRGBDevice(CorsairCustomRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, new LedMapping<CorsairLedId>(), updateQueue)
{ }
@@ -17,8 +17,19 @@ namespace RGB.NET.Devices.Corsair
{
#region Properties & Fields
/// <summary>
/// Gets the corsair-id of the first LED of this device.
/// </summary>
public CorsairLedId ReferenceCorsairLed { get; }
/// <summary>
/// Gets the amount of LEDs this device contains.
/// </summary>
public int LedCount { get; }
/// <summary>
/// Gets the offset used to access the LEDs of this device.
/// </summary>
internal int LedOffset { get; }
#endregion
@@ -33,7 +44,8 @@ namespace RGB.NET.Devices.Corsair
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair._CorsairChannelDeviceInfo" />.</param>
/// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
/// <param name="channelDeviceInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairChannelDeviceInfo"/> representing this device.</param>
/// <param name="referenceCorsairLed">The id of the first led of this device.</param>
/// <param name="referenceCorsairLed">The id of the first LED of this device.</param>
/// <param name="ledOffset">The offset used to find the LEDs of this device.</param>
internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo, CorsairLedId referenceCorsairLed, int ledOffset)
: base(deviceIndex, GetDeviceType(channelDeviceInfo.type), nativeInfo,
GetModelName(nativeInfo.model == IntPtr.Zero ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase), channelDeviceInfo))
@@ -49,32 +61,21 @@ namespace RGB.NET.Devices.Corsair
#region Methods
private static RGBDeviceType GetDeviceType(CorsairChannelDeviceType deviceType)
{
switch (deviceType)
=> deviceType switch
{
case CorsairChannelDeviceType.Invalid:
return RGBDeviceType.Unknown;
case CorsairChannelDeviceType.FanHD:
case CorsairChannelDeviceType.FanSP:
case CorsairChannelDeviceType.FanLL:
case CorsairChannelDeviceType.FanML:
case CorsairChannelDeviceType.DAP:
case CorsairChannelDeviceType.FanQL:
case CorsairChannelDeviceType.FanSPPRO:
return RGBDeviceType.Fan;
case CorsairChannelDeviceType.Strip:
return RGBDeviceType.LedStripe;
case CorsairChannelDeviceType.Pump:
case CorsairChannelDeviceType.WaterBlock:
return RGBDeviceType.Cooler;
default:
throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null);
}
}
CorsairChannelDeviceType.Invalid => RGBDeviceType.Unknown,
CorsairChannelDeviceType.FanHD => RGBDeviceType.Fan,
CorsairChannelDeviceType.FanSP => RGBDeviceType.Fan,
CorsairChannelDeviceType.FanLL => RGBDeviceType.Fan,
CorsairChannelDeviceType.FanML => RGBDeviceType.Fan,
CorsairChannelDeviceType.DAP => RGBDeviceType.Fan,
CorsairChannelDeviceType.FanQL => RGBDeviceType.Fan,
CorsairChannelDeviceType.FanSPPRO => RGBDeviceType.Fan,
CorsairChannelDeviceType.Strip => RGBDeviceType.LedStripe,
CorsairChannelDeviceType.Pump => RGBDeviceType.Cooler,
CorsairChannelDeviceType.WaterBlock => RGBDeviceType.Cooler,
_ => throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null)
};
private static string GetModelName(string model, _CorsairChannelDeviceInfo channelDeviceInfo)
{
@@ -126,7 +127,9 @@ namespace RGB.NET.Devices.Corsair
return "Pump";
default:
throw new ArgumentOutOfRangeException(nameof(channelDeviceInfo.type), channelDeviceInfo.type, null);
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
throw new ArgumentOutOfRangeException($"{nameof(channelDeviceInfo)}.{nameof(channelDeviceInfo.type)}", channelDeviceInfo.type, null);
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
}
}
@@ -6,7 +6,7 @@
namespace RGB.NET.Devices.Corsair
{
/// <summary>
/// Contains list of available SDK access modes.
/// Represents an SDK access mode.
/// </summary>
public enum CorsairAccessMode
{
@@ -7,7 +7,7 @@
namespace RGB.NET.Devices.Corsair
{
/// <summary>
/// Contains list of available corsair channel device types.
/// Contains a list of available corsair channel device types.
/// </summary>
public enum CorsairChannelDeviceType
{
@@ -6,7 +6,7 @@ using System;
namespace RGB.NET.Devices.Corsair
{
/// <summary>
/// Contains list of corsair device capabilities.
/// Contains a list of corsair device capabilities.
/// </summary>
[Flags]
public enum CorsairDeviceCaps
@@ -7,7 +7,7 @@
namespace RGB.NET.Devices.Corsair
{
/// <summary>
/// Contains list of available corsair device types.
/// Contains a list of available corsair device types.
/// </summary>
public enum CorsairDeviceType
{
+3 -3
View File
@@ -1,11 +1,11 @@
// ReSharper disable InconsistentNaming
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
// ReSharper disable UnusedMember.Global
#pragma warning disable 1591
namespace RGB.NET.Devices.Corsair
{
/// <summary>
/// Contains list of all LEDs available for all corsair devices.
/// Contains a list of all LEDs available for all corsair devices.
/// </summary>
public enum CorsairLedId
{
@@ -1,12 +1,11 @@
// ReSharper disable InconsistentNaming
// ReSharper disable UnusedMember.Global
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
#pragma warning disable 1591
namespace RGB.NET.Devices.Corsair
{
/// <summary>
/// Contains list of available logical layouts for corsair keyboards.
/// Contains a list of available logical layouts for corsair keyboards.
/// </summary>
public enum CorsairLogicalKeyboardLayout
{
@@ -4,7 +4,7 @@
namespace RGB.NET.Devices.Corsair
{
/// <summary>
/// Contains list of available physical layouts for corsair keyboards.
/// Contains a list of available physical layouts for corsair keyboards.
/// </summary>
public enum CorsairPhysicalKeyboardLayout
{
@@ -1,7 +1,7 @@
namespace RGB.NET.Devices.Corsair
{
/// <summary>
/// Contains list of available physical layouts for mice.
/// Contains a list of available physical layouts for mice.
/// </summary>
public enum CorsairPhysicalMouseLayout
{
@@ -14,6 +14,9 @@ namespace RGB.NET.Devices.Corsair
{
#region Properties & Fields
/// <summary>
/// Gets the mapping of <see cref="LedId"/> to <see cref="CorsairLedId"/> used to update the LEDs of this device.
/// </summary>
protected LedMapping<CorsairLedId> Mapping { get; }
#endregion
@@ -24,6 +27,8 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="CorsairRGBDevice{TDeviceInfo}"/> class.
/// </summary>
/// <param name="info">The generic information provided by CUE for the device.</param>
/// <param name="mapping">The mapping <see cref="LedId"/> to <see cref="CorsairLedId"/> used to update the LEDs of this device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
protected CorsairRGBDevice(TDeviceInfo info, LedMapping<CorsairLedId> mapping, CorsairDeviceUpdateQueue updateQueue)
: base(info, updateQueue)
{
@@ -35,7 +40,10 @@ namespace RGB.NET.Devices.Corsair
#region Methods
void ICorsairRGBDevice.Initialize() => InitializeLayout();
/// <summary>
/// Initializes the LEDs of the device based on the data provided by the SDK.
/// </summary>
protected virtual void InitializeLayout()
{
_CorsairLedPositions? nativeLedPositions = (_CorsairLedPositions?)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositionsByDeviceIndex(DeviceInfo.CorsairDeviceIndex), typeof(_CorsairLedPositions));
+39 -8
View File
@@ -2,6 +2,9 @@
namespace RGB.NET.Devices.Corsair
{
/// <summary>
/// Contains mappings for <see cref="LedId"/> to <see cref="CorsairLedId"/>.
/// </summary>
public static class LedMappings
{
static LedMappings()
@@ -28,19 +31,44 @@ namespace RGB.NET.Devices.Corsair
Keyboard.Add(LedId.Custom101 + i, CorsairLedId.OemLed101 + i);
}
public static LedMapping<CorsairLedId> GraphicsCard = new();
public static LedMapping<CorsairLedId> HeadsetStand = new();
public static LedMapping<CorsairLedId> Mainboard = new();
public static LedMapping<CorsairLedId> Memory = new();
public static LedMapping<CorsairLedId> Mousepad = new();
/// <summary>
/// Gets the mapping for graphics cards.
/// </summary>
public static LedMapping<CorsairLedId> GraphicsCard { get; } = new();
public static LedMapping<CorsairLedId> Headset = new()
/// <summary>
/// Gets the mapping for headsets.
/// </summary>
public static LedMapping<CorsairLedId> HeadsetStand { get; } = new();
/// <summary>
/// Gets the mapping for mainboards.
/// </summary>
public static LedMapping<CorsairLedId> Mainboard { get; } = new();
/// <summary>
/// Gets the mapping for memory.
/// </summary>
public static LedMapping<CorsairLedId> Memory { get; } = new();
/// <summary>
/// Gets the mapping for mousepads.
/// </summary>
public static LedMapping<CorsairLedId> Mousepad { get; } = new();
/// <summary>
/// Gets the mapping for headsets.
/// </summary>
public static LedMapping<CorsairLedId> Headset { get; } = new()
{
{ LedId.Headset1, CorsairLedId.LeftLogo },
{ LedId.Headset2, CorsairLedId.RightLogo },
};
public static LedMapping<CorsairLedId> Mouse = new()
/// <summary>
/// Gets the mapping for mice.
/// </summary>
public static LedMapping<CorsairLedId> Mouse { get; } = new()
{
{ LedId.Mouse1, CorsairLedId.B1 },
{ LedId.Mouse2, CorsairLedId.B2 },
@@ -64,7 +92,10 @@ namespace RGB.NET.Devices.Corsair
{ LedId.Mouse20, CorsairLedId.B20 },
};
public static LedMapping<CorsairLedId> Keyboard = new()
/// <summary>
/// Gets the mapping for keyboards.
/// </summary>
public static LedMapping<CorsairLedId> Keyboard { get; } = new()
{
{ LedId.Invalid, CorsairLedId.Invalid },
{ LedId.Logo, CorsairLedId.Logo },
@@ -18,6 +18,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairGraphicsCardRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the graphics card.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairGraphicsCardRGBDevice(CorsairGraphicsCardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.GraphicsCard, updateQueue)
{ }
@@ -18,6 +18,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairHeadsetRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the headset</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairHeadsetRGBDevice(CorsairHeadsetRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.Headset, updateQueue)
{ }
@@ -18,6 +18,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairHeadsetStandRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the headset stand</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairHeadsetStandRGBDevice(CorsairHeadsetStandRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.HeadsetStand, updateQueue)
{ }
@@ -23,7 +23,8 @@ namespace RGB.NET.Devices.Corsair
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairKeyboardRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the keyboard</param>
/// <param name="info">The specific information provided by CUE for the keyboard.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairKeyboardRGBDevice(CorsairKeyboardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.Keyboard, updateQueue)
{ }
@@ -18,6 +18,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairMainboardRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the memory.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairMainboardRGBDevice(CorsairMainboardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.Mainboard, updateQueue)
{ }
@@ -18,6 +18,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairMemoryRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the memory.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairMemoryRGBDevice(CorsairMemoryRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.Memory, updateQueue)
{ }
@@ -18,6 +18,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairMouseRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the mouse</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairMouseRGBDevice(CorsairMouseRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.Mouse, updateQueue)
{ }
@@ -18,6 +18,7 @@ namespace RGB.NET.Devices.Corsair
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairMousepadRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the mousepad</param>
/// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairMousepadRGBDevice(CorsairMousepadRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.Mousepad, updateQueue)
{ }
+4 -3
View File
@@ -1,4 +1,5 @@
// ReSharper disable UnusedMethodReturnValue.Global
#pragma warning disable IDE1006 // Naming Styles
// ReSharper disable UnusedMethodReturnValue.Global
// ReSharper disable UnusedMember.Global
using System;
@@ -61,13 +62,13 @@ namespace RGB.NET.Devices.Corsair.Native
_dllHandle = IntPtr.Zero;
}
[DllImport("kernel32.dll")]
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll")]
private static extern bool FreeLibrary(IntPtr dllHandle);
[DllImport("kernel32.dll")]
[DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name);
#endregion
@@ -1,6 +1,7 @@
#pragma warning disable 169 // Field 'x' is never used
#pragma warning disable 414 // Field 'x' is assigned but its value never used
#pragma warning disable 649 // Field 'x' is never assigned
#pragma warning disable IDE1006 // Naming Styles
using System.Runtime.InteropServices;
@@ -11,6 +12,7 @@ namespace RGB.NET.Devices.Corsair.Native
/// CUE-SDK: contains information about separate LED-device connected to the channel controlled by the DIY-device.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal class _CorsairChannelDeviceInfo
{
/// <summary>
@@ -1,6 +1,7 @@
#pragma warning disable 169 // Field 'x' is never used
#pragma warning disable 414 // Field 'x' is assigned but its value never used
#pragma warning disable 649 // Field 'x' is never assigned
#pragma warning disable IDE1006 // Naming Styles
using System;
using System.Runtime.InteropServices;
@@ -1,6 +1,7 @@
#pragma warning disable 169 // Field 'x' is never used
#pragma warning disable 414 // Field 'x' is assigned but its value never used
#pragma warning disable 649 // Field 'x' is never assigned
#pragma warning disable IDE1006 // Naming Styles
using System;
using System.Runtime.InteropServices;
@@ -1,6 +1,7 @@
#pragma warning disable 169 // Field 'x' is never used
#pragma warning disable 414 // Field 'x' is assigned but its value never used
#pragma warning disable 649 // Field 'x' is never assigned
#pragma warning disable IDE1006 // Naming Styles
using System;
using System.Runtime.InteropServices;
@@ -1,6 +1,8 @@
#pragma warning disable 169 // Field 'x' is never used
#pragma warning disable 414 // Field 'x' is assigned but its value never used
#pragma warning disable 649 // Field 'x' is never assigned
#pragma warning disable IDE1006 // Naming Styles
// ReSharper disable NotAccessedField.Global
using System.Runtime.InteropServices;
@@ -1,6 +1,7 @@
#pragma warning disable 169 // Field 'x' is never used
#pragma warning disable 414 // Field 'x' is assigned but its value never used
#pragma warning disable 649 // Field 'x' is never assigned
#pragma warning disable IDE1006 // Naming Styles
using System.Runtime.InteropServices;
@@ -15,11 +15,10 @@
<RootNamespace>RGB.NET.Devices.Corsair</RootNamespace>
<Description>Corsair-Device-Implementations of RGB.NET</Description>
<Summary>Corsair-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals</Summary>
<Copyright>Copyright © Darth Affe 2020</Copyright>
<PackageCopyright>Copyright © Darth Affe 2020</PackageCopyright>
<PackageIconUrl>http://lib.arge.be/icon.png</PackageIconUrl>
<Copyright>Copyright © Darth Affe 2021</Copyright>
<Icon>icon.png</Icon>
<PackageProjectUrl>https://github.com/DarthAffe/RGB.NET</PackageProjectUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE</PackageLicenseUrl>
<License>LGPL-2.1-only</License>
<RepositoryType>Github</RepositoryType>
<RepositoryUrl>https://github.com/DarthAffe/RGB.NET</RepositoryUrl>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
@@ -34,22 +33,26 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IncludeSource>True</IncludeSource>
<IncludeSymbols>True</IncludeSymbols>
<DebugType>portable</DebugType>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<DefineConstants>$(DefineConstants);TRACE;DEBUG</DefineConstants>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<NoWarn>$(NoWarn);CS1591;CS1572;CS1573</NoWarn>
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Content Include="..\Resources\icon.png" Link="icon.png" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj" />
</ItemGroup>
@@ -17,4 +17,5 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=exceptions/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enum/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=specialparts/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=targets/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=targets/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>