mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Added SpecialDeviceParts and implemented CorsairLightbar
This commit is contained in:
parent
073c4b153d
commit
3630e0f66f
@ -1,6 +1,7 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -48,6 +49,11 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
protected Dictionary<ILedId, Led> LedMapping { get; } = new Dictionary<ILedId, Led>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a dictionary containing all <see cref="IRGBDeviceSpecialPart"/> associated with this <see cref="IRGBDevice"/>.
|
||||
/// </summary>
|
||||
protected Dictionary<Type, IRGBDeviceSpecialPart> SpecialDeviceParts { get; } = new Dictionary<Type, IRGBDeviceSpecialPart>();
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -90,6 +96,7 @@ namespace RGB.NET.Core
|
||||
/// <inheritdoc />
|
||||
public virtual void Dispose()
|
||||
{
|
||||
SpecialDeviceParts.Clear();
|
||||
LedMapping.Clear();
|
||||
}
|
||||
|
||||
@ -119,6 +126,16 @@ namespace RGB.NET.Core
|
||||
return led;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void AddSpecialDevicePart<T>(T specialDevicePart)
|
||||
where T : class, IRGBDeviceSpecialPart
|
||||
=> SpecialDeviceParts[typeof(T)] = specialDevicePart;
|
||||
|
||||
/// <inheritdoc />
|
||||
public T GetSpecialDevicePart<T>()
|
||||
where T : class, IRGBDeviceSpecialPart
|
||||
=> SpecialDeviceParts.TryGetValue(typeof(T), out IRGBDeviceSpecialPart devicePart) ? (T)devicePart : default(T);
|
||||
|
||||
#region Enumerator
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -61,6 +61,21 @@ namespace RGB.NET.Core
|
||||
/// <param name="flushLeds">Specifies whether all <see cref="Led"/> (including clean ones) should be updated.</param>
|
||||
void Update(bool flushLeds = false);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given <see cref="IRGBDeviceSpecialPart"/> to the device.
|
||||
/// This will override existing <see cref="IRGBDeviceSpecialPart"/> of the same type.
|
||||
/// </summary>
|
||||
/// <param name="specialDevicePart">The <see cref="IRGBDeviceSpecialPart"/> to add.</param>
|
||||
/// <typeparam name="T">The generic typeof of the <see cref="IRGBDeviceSpecialPart"/> to add.</typeparam>
|
||||
void AddSpecialDevicePart<T>(T specialDevicePart) where T : class, IRGBDeviceSpecialPart;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the requested <see cref="IRGBDeviceSpecialPart"/> if available on this <see cref="IRGBDevice"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The generic type of the requested <see cref="IRGBDeviceSpecialPart"/>.</typeparam>
|
||||
/// <returns>The requested <see cref="IRGBDeviceSpecialPart"/> or null if not available in this <see cref="IRGBDevice"/>.</returns>
|
||||
T GetSpecialDevicePart<T>() where T : class, IRGBDeviceSpecialPart;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
10
RGB.NET.Core/Devices/IRGBDeviceSpecialPart.cs
Normal file
10
RGB.NET.Core/Devices/IRGBDeviceSpecialPart.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a special part of a <see cref="IRGBDevice"/>.
|
||||
/// </summary>
|
||||
public interface IRGBDeviceSpecialPart : IEnumerable<Led>
|
||||
{ }
|
||||
}
|
||||
@ -51,6 +51,7 @@
|
||||
<Compile Include="Brushes\IBrush.cs" />
|
||||
<Compile Include="ColorCorrection\IColorCorrection.cs" />
|
||||
<Compile Include="Devices\AbstractRGBDevice.cs" />
|
||||
<Compile Include="Devices\IRGBDeviceSpecialPart.cs" />
|
||||
<Compile Include="Devices\Layout\LedImage.cs" />
|
||||
<Compile Include="Devices\Layout\LedImageLayout.cs" />
|
||||
<Compile Include="Devices\RGBDeviceLighting.cs" />
|
||||
|
||||
@ -8,6 +8,7 @@ using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Core.Exceptions;
|
||||
using RGB.NET.Devices.Corsair.Native;
|
||||
using RGB.NET.Devices.Corsair.SpecialParts;
|
||||
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
@ -154,6 +155,8 @@ namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
case CorsairDeviceType.Keyboard:
|
||||
device = new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
if (device.DeviceInfo.Model.Equals("K95 RGB Platinum", StringComparison.OrdinalIgnoreCase))
|
||||
device.AddSpecialDevicePart(new LightbarSpecialPart(device));
|
||||
break;
|
||||
case CorsairDeviceType.Mouse:
|
||||
device = new CorsairMouseRGBDevice(new CorsairMouseRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
|
||||
@ -74,6 +74,7 @@
|
||||
<Compile Include="Native\_CorsairProtocolDetails.cs" />
|
||||
<Compile Include="Native\_CUESDK.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SpecialParts\LightbarSpecialPart.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Layouts\DeviceLayout.xsd">
|
||||
|
||||
76
RGB.NET.Devices.Corsair/SpecialParts/LightbarSpecialPart.cs
Normal file
76
RGB.NET.Devices.Corsair/SpecialParts/LightbarSpecialPart.cs
Normal file
@ -0,0 +1,76 @@
|
||||
// ReSharper disable UnusedMember.Global
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.Corsair.SpecialParts
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a lightbar attached to a <see cref="IRGBDevice"/>
|
||||
/// </summary>
|
||||
public class LightbarSpecialPart : IRGBDeviceSpecialPart
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private List<Led> _leds;
|
||||
/// <summary>
|
||||
/// Gets a readonly collection of all <see cref="Led"/> of this <see cref="LightbarSpecialPart"/>.
|
||||
/// </summary>
|
||||
public IEnumerable<Led> Leds => new ReadOnlyCollection<Led>(_leds);
|
||||
|
||||
private List<Led> _left;
|
||||
/// <summary>
|
||||
/// Gets a readonly collection of all <see cref="Led"/> in the left half of this <see cref="LightbarSpecialPart"/>.
|
||||
/// </summary>
|
||||
public IEnumerable<Led> Left => new ReadOnlyCollection<Led>(_left);
|
||||
|
||||
private List<Led> _right;
|
||||
/// <summary>
|
||||
/// Gets a readonly collection of all <see cref="Led"/> in the right half of this <see cref="LightbarSpecialPart"/>.
|
||||
/// </summary>
|
||||
public IEnumerable<Led> Right => new ReadOnlyCollection<Led>(_right);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Center <see cref="Led"/> of this <see cref="LightbarSpecialPart"/>.
|
||||
/// </summary>
|
||||
public Led Center { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LightbarSpecialPart"/> class.
|
||||
/// </summary>
|
||||
/// <param name="device">The device associated with this <see cref="IRGBDeviceSpecialPart"/>.</param>
|
||||
public LightbarSpecialPart(IRGBDevice device)
|
||||
{
|
||||
_leds = device.Where(led => (((CorsairLedId)led.Id).LedId >= CorsairLedIds.Lightbar1) && (((CorsairLedId)led.Id).LedId <= CorsairLedIds.Lightbar19)).ToList();
|
||||
_left = _leds.Where(led => ((CorsairLedId)led.Id).LedId < CorsairLedIds.Lightbar10).ToList();
|
||||
_right = _leds.Where(led => ((CorsairLedId)led.Id).LedId > CorsairLedIds.Lightbar10).ToList();
|
||||
Center = _leds.FirstOrDefault(led => ((CorsairLedId)led.Id).LedId == CorsairLedIds.Lightbar10);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates over all <see cref="Led"/> of the <see cref="IRGBDeviceSpecialPart"/>.
|
||||
/// </summary>
|
||||
/// <returns>An enumerator for all <see cref="Led"/> of the <see cref="IRGBDeviceSpecialPart"/>.</returns>
|
||||
public IEnumerator<Led> GetEnumerator() => _leds.GetEnumerator();
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates over all <see cref="Led"/> of the <see cref="IRGBDeviceSpecialPart"/>.
|
||||
/// </summary>
|
||||
/// <returns>An enumerator for all <see cref="Led"/> of the <see cref="IRGBDeviceSpecialPart"/>.</returns>
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user