Implemented corsair devices

This commit is contained in:
DarthAffe committed 2017-01-22 15:31:30 +01:00
1 parent 89194c4cb4
commit f3128a3dd0
31 files changed
+1731

No files matched your search

@@ -0,0 +1,102 @@
using System.Diagnostics;
using RGB.NET.Core;
namespace RGB.NET.Devices.Corsair
{
/// <summary>
/// Represents a Id of a <see cref="Led"/> on a <see cref="CorsairRGBDevice"/>.
/// </summary>
[DebuggerDisplay("{_ledId}")]
public class CorsairLedId : ILedId
{
#region Properties & Fields
private readonly CorsairLedIds _ledId;
/// <inheritdoc />
public bool IsValid => _ledId != CorsairLedIds.Invalid;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="CorsairLedId"/> class.
/// </summary>
/// <param name="ledId">The corsair-id of the represented <see cref="Led"/>.</param>
public CorsairLedId(CorsairLedIds ledId)
{
this._ledId = ledId;
}
#endregion
#region Methods
/// <summary>
/// Converts the Id of this <see cref="CorsairLedId"/> to a human-readable string.
/// </summary>
/// <returns>A string that contains the Id of this <see cref="CorsairLedId"/>. For example "Enter".</returns>
public override string ToString()
{
return _ledId.ToString();
}
/// <summary>
/// Tests whether the specified object is a <see cref="CorsairLedId" /> and is equivalent to this <see cref="CorsairLedId" />.
/// </summary>
/// <param name="obj">The object to test.</param>
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="CorsairLedId" /> equivalent to this <see cref="CorsairLedId" />; otherwise, <c>false</c>.</returns>
public override bool Equals(object obj)
{
CorsairLedId compareLedId = obj as CorsairLedId;
if (ReferenceEquals(compareLedId, null))
return false;
if (ReferenceEquals(this, compareLedId))
return true;
if (GetType() != compareLedId.GetType())
return false;
return compareLedId._ledId == _ledId;
}
/// <summary>
/// Returns a hash code for this <see cref="CorsairLedId" />.
/// </summary>
/// <returns>An integer value that specifies the hash code for this <see cref="CorsairLedId" />.</returns>
public override int GetHashCode()
{
return _ledId.GetHashCode();
}
#endregion
#region Operators
/// <summary>
/// Returns a value that indicates whether two specified <see cref="CorsairLedId" /> are equal.
/// </summary>
/// <param name="ledId1">The first <see cref="CorsairLedId" /> to compare.</param>
/// <param name="ledId2">The second <see cref="CorsairLedId" /> to compare.</param>
/// <returns><c>true</c> if <paramref name="ledId1" /> and <paramref name="ledId2" /> are equal; otherwise, <c>false</c>.</returns>
public static bool operator ==(CorsairLedId ledId1, CorsairLedId ledId2)
{
return ReferenceEquals(ledId1, null) ? ReferenceEquals(ledId2, null) : ledId1.Equals(ledId2);
}
/// <summary>
/// Returns a value that indicates whether two specified <see cref="CorsairLedId" /> are equal.
/// </summary>
/// <param name="ledId1">The first <see cref="CorsairLedId" /> to compare.</param>
/// <param name="ledId2">The second <see cref="CorsairLedId" /> to compare.</param>
/// <returns><c>true</c> if <paramref name="ledId1" /> and <paramref name="ledId2" /> are not equal; otherwise, <c>false</c>.</returns>
public static bool operator !=(CorsairLedId ledId1, CorsairLedId ledId2)
{
return !(ledId1 == ledId2);
}
#endregion
}
}
@@ -0,0 +1,66 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
using System;
using System.Runtime.InteropServices;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair
{
/// <summary>
/// Managed wrapper for CorsairProtocolDetails.
/// </summary>
public class CorsairProtocolDetails
{
#region Properties & Fields
/// <summary>
/// String containing version of SDK(like "1.0.0.1").
/// Always contains valid value even if there was no CUE found.
/// </summary>
public string SdkVersion { get; }
/// <summary>
/// String containing version of CUE(like "1.0.0.1") or NULL if CUE was not found.
/// </summary>
public string ServerVersion { get; }
/// <summary>
/// Integer that specifies version of protocol that is implemented by current SDK.
/// Numbering starts from 1.
/// Always contains valid value even if there was no CUE found.
/// </summary>
public int SdkProtocolVersion { get; }
/// <summary>
/// Integer that specifies version of protocol that is implemented by CUE.
/// Numbering starts from 1.
/// If CUE was not found then this value will be 0.
/// </summary>
public int ServerProtocolVersion { get; }
/// <summary>
/// Boolean that specifies if there were breaking changes between version of protocol implemented by server and client.
/// </summary>
public bool BreakingChanges { get; }
#endregion
#region Constructors
/// <summary>
/// Internal constructor of managed CorsairProtocolDetails.
/// </summary>
/// <param name="nativeDetails">The native CorsairProtocolDetails-struct</param>
internal CorsairProtocolDetails(_CorsairProtocolDetails nativeDetails)
{
this.SdkVersion = nativeDetails.sdkVersion == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeDetails.sdkVersion);
this.ServerVersion = nativeDetails.serverVersion == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeDetails.serverVersion);
this.SdkProtocolVersion = nativeDetails.sdkProtocolVersion;
this.ServerProtocolVersion = nativeDetails.serverProtocolVersion;
this.BreakingChanges = nativeDetails.breakingChanges != 0;
}
#endregion
}
}
@@ -0,0 +1,56 @@
using System.Linq;
using RGB.NET.Core;
namespace RGB.NET.Devices.Corsair
{
/// <summary>
/// Represents a generic CUE-device. (keyboard, mouse, headset, mousmat).
/// </summary>
public abstract class CorsairRGBDevice : AbstractRGBDevice
{
#region Properties & Fields
/// <summary>
/// Gets information about the <see cref="CorsairRGBDevice"/>.
/// </summary>
public override IRGBDeviceInfo DeviceInfo { get; }
private Rectangle _deviceRectangle;
/// <inheritdoc />
public override Rectangle DeviceRectangle => _deviceRectangle;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="CorsairRGBDevice"/> class.
/// </summary>
/// <param name="info">The generic information provided by CUE for the device.</param>
protected CorsairRGBDevice(IRGBDeviceInfo info)
{
this.DeviceInfo = info;
}
#endregion
#region Methods
/// <summary>
/// Initializes the device.
/// </summary>
internal void Initialize()
{
InitializeLeds();
_deviceRectangle = new Rectangle(this.Select(x => x.LedRectangle));
}
/// <summary>
/// Initializes the <see cref="Led"/> of the device.
/// </summary>
protected abstract void InitializeLeds();
#endregion
}
}
@@ -0,0 +1,60 @@
using System;
using System.Runtime.InteropServices;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair
{
/// <summary>
/// Represents a generic information for a Corsair-<see cref="IRGBDevice"/>.
/// </summary>
public class CorsairRGBDeviceInfo : IRGBDeviceInfo
{
#region Properties & Fields
/// <summary>
/// Gets the corsair specific device type.
/// </summary>
public CorsairDeviceType CorsairDeviceType { get; }
/// <summary>
/// Gets the index of the <see cref="CorsairRGBDevice"/>.
/// </summary>
public int CorsairDeviceIndex { get; }
/// <inheritdoc />
public DeviceType DeviceType { get; }
/// <inheritdoc />
public string Manufacturer => "Corsair";
/// <inheritdoc />
public string Model { get; }
/// <summary>
/// Gets a flag that describes device capabilities. (<see cref="CorsairDeviceCaps" />)
/// </summary>
public CorsairDeviceCaps CapsMask { get; }
#endregion
#region Constructors
/// <summary>
/// Internal constructor of managed <see cref="CorsairRGBDeviceInfo"/>.
/// </summary>
/// <param name="deviceIndex">The index of the <see cref="CorsairRGBDevice"/>.</param>
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
/// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
internal CorsairRGBDeviceInfo(int deviceIndex, DeviceType deviceType, _CorsairDeviceInfo nativeInfo)
{
this.CorsairDeviceIndex = deviceIndex;
this.DeviceType = deviceType;
this.CorsairDeviceType = nativeInfo.type;
this.Model = nativeInfo.model == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeInfo.model);
this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask;
}
#endregion
}
}