diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs index 4491ba4..c131a3a 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -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 /// protected Dictionary LedMapping { get; } = new Dictionary(); + /// + /// Gets a dictionary containing all associated with this . + /// + protected Dictionary SpecialDeviceParts { get; } = new Dictionary(); + #region Indexer /// @@ -90,6 +96,7 @@ namespace RGB.NET.Core /// public virtual void Dispose() { + SpecialDeviceParts.Clear(); LedMapping.Clear(); } @@ -119,6 +126,16 @@ namespace RGB.NET.Core return led; } + /// + public void AddSpecialDevicePart(T specialDevicePart) + where T : class, IRGBDeviceSpecialPart + => SpecialDeviceParts[typeof(T)] = specialDevicePart; + + /// + public T GetSpecialDevicePart() + where T : class, IRGBDeviceSpecialPart + => SpecialDeviceParts.TryGetValue(typeof(T), out IRGBDeviceSpecialPart devicePart) ? (T)devicePart : default(T); + #region Enumerator /// diff --git a/RGB.NET.Core/Devices/IRGBDevice.cs b/RGB.NET.Core/Devices/IRGBDevice.cs index f80b1d7..57dcc3b 100644 --- a/RGB.NET.Core/Devices/IRGBDevice.cs +++ b/RGB.NET.Core/Devices/IRGBDevice.cs @@ -61,6 +61,21 @@ namespace RGB.NET.Core /// Specifies whether all (including clean ones) should be updated. void Update(bool flushLeds = false); + /// + /// Adds the given to the device. + /// This will override existing of the same type. + /// + /// The to add. + /// The generic typeof of the to add. + void AddSpecialDevicePart(T specialDevicePart) where T : class, IRGBDeviceSpecialPart; + + /// + /// Gets the requested if available on this . + /// + /// The generic type of the requested . + /// The requested or null if not available in this . + T GetSpecialDevicePart() where T : class, IRGBDeviceSpecialPart; + #endregion } } diff --git a/RGB.NET.Core/Devices/IRGBDeviceSpecialPart.cs b/RGB.NET.Core/Devices/IRGBDeviceSpecialPart.cs new file mode 100644 index 0000000..755b46a --- /dev/null +++ b/RGB.NET.Core/Devices/IRGBDeviceSpecialPart.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace RGB.NET.Core +{ + /// + /// Represents a special part of a . + /// + public interface IRGBDeviceSpecialPart : IEnumerable + { } +} diff --git a/RGB.NET.Core/RGB.NET.Core.csproj b/RGB.NET.Core/RGB.NET.Core.csproj index f4cb0ae..5e3a047 100644 --- a/RGB.NET.Core/RGB.NET.Core.csproj +++ b/RGB.NET.Core/RGB.NET.Core.csproj @@ -51,6 +51,7 @@ + diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index a29af8d..d6ded4e 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.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)); diff --git a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj index d7a53f8..558c4a5 100644 --- a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj +++ b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj @@ -74,6 +74,7 @@ + diff --git a/RGB.NET.Devices.Corsair/SpecialParts/LightbarSpecialPart.cs b/RGB.NET.Devices.Corsair/SpecialParts/LightbarSpecialPart.cs new file mode 100644 index 0000000..57a96a9 --- /dev/null +++ b/RGB.NET.Devices.Corsair/SpecialParts/LightbarSpecialPart.cs @@ -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 +{ + /// + /// Represents a lightbar attached to a + /// + public class LightbarSpecialPart : IRGBDeviceSpecialPart + { + #region Properties & Fields + + private List _leds; + /// + /// Gets a readonly collection of all of this . + /// + public IEnumerable Leds => new ReadOnlyCollection(_leds); + + private List _left; + /// + /// Gets a readonly collection of all in the left half of this . + /// + public IEnumerable Left => new ReadOnlyCollection(_left); + + private List _right; + /// + /// Gets a readonly collection of all in the right half of this . + /// + public IEnumerable Right => new ReadOnlyCollection(_right); + + /// + /// Gets the Center of this . + /// + public Led Center { get; } + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The device associated with this . + 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 + + /// + /// Returns an enumerator that iterates over all of the . + /// + /// An enumerator for all of the . + public IEnumerator GetEnumerator() => _leds.GetEnumerator(); + + /// + /// Returns an enumerator that iterates over all of the . + /// + /// An enumerator for all of the . + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + #endregion + } +}