From 57ad0f30e2cd6f7c2135014a96e8f760c7c81ec1 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Thu, 15 Oct 2015 21:31:45 +0200 Subject: [PATCH] Added support for mouse and headset devices. This *should* work out of the box but needs to be tested. --- Devices/Generic/AbstractCueDevice.cs | 5 +- Devices/Headset/CorsairHeadset.cs | 55 +++++++++++++++++--- Devices/Mouse/CorsairMouse.cs | 76 +++++++++++++++++++++++++--- 3 files changed, 122 insertions(+), 14 deletions(-) diff --git a/Devices/Generic/AbstractCueDevice.cs b/Devices/Generic/AbstractCueDevice.cs index d7ec4e9..4c6177d 100644 --- a/Devices/Generic/AbstractCueDevice.cs +++ b/Devices/Generic/AbstractCueDevice.cs @@ -40,7 +40,10 @@ namespace CUE.NET.Devices.Generic /// public float UpdateFrequency { get; set; } = 1f / 30f; - private Dictionary Leds { get; } = new Dictionary(); + /// + /// Gets a dictionary containing all LEDs of the device. + /// + protected Dictionary Leds { get; } = new Dictionary(); /// /// Indicates if the device has an active effect to deal with. diff --git a/Devices/Headset/CorsairHeadset.cs b/Devices/Headset/CorsairHeadset.cs index d27a728..017bd3a 100644 --- a/Devices/Headset/CorsairHeadset.cs +++ b/Devices/Headset/CorsairHeadset.cs @@ -1,29 +1,70 @@ -using CUE.NET.Devices.Generic; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using CUE.NET.Devices.Generic; +using CUE.NET.Devices.Headset.Enums; namespace CUE.NET.Devices.Headset { - //TODO DarthAffe 20.09.2015: Find someone to test this - /// - /// Stub for planned headset-support. - /// - public class CorsairHeadset : AbstractCueDevice + public class CorsairHeadset : AbstractCueDevice, IEnumerable { #region Properties & Fields + #region Indexer + + public CorsairLed this[CorsairHeadsetLedId ledId] + { + get + { + CorsairLed led; + return base.Leds.TryGetValue((int)ledId, out led) ? led : null; + } + } + + #endregion + + public CorsairHeadsetDeviceInfo HeadsetDeviceInfo { get; } + protected override bool HasEffect => false; + public new IEnumerable Leds => new ReadOnlyCollection(base.Leds.Values.ToList()); + #endregion #region Constructors internal CorsairHeadset(CorsairHeadsetDeviceInfo info) : base(info) - { } + { + this.HeadsetDeviceInfo = info; + InitializeLeds(); + } #endregion #region Methods + private void InitializeLeds() + { + GetLed((int)CorsairHeadsetLedId.LeftLogo); + GetLed((int)CorsairHeadsetLedId.RightLogo); + } + + #region IEnumerable + + public IEnumerator GetEnumerator() + { + return Leds.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + #endregion + #endregion } } diff --git a/Devices/Mouse/CorsairMouse.cs b/Devices/Mouse/CorsairMouse.cs index 012c7cb..96d09a5 100644 --- a/Devices/Mouse/CorsairMouse.cs +++ b/Devices/Mouse/CorsairMouse.cs @@ -1,19 +1,40 @@ -using CUE.NET.Devices.Generic; +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global +// ReSharper disable UnusedMember.Global + +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using CUE.NET.Devices.Generic; +using CUE.NET.Devices.Mouse.Enums; +using CUE.NET.Exceptions; namespace CUE.NET.Devices.Mouse { - //TODO DarthAffe 20.09.2015: Find someone to test this - /// - /// Stub for planned headset-support. - /// - public class CorsairMouse : AbstractCueDevice + public class CorsairMouse : AbstractCueDevice, IEnumerable { #region Properties & Fields + #region Indexer + + public CorsairLed this[CorsairMouseLedId ledId] + { + get + { + CorsairLed led; + return base.Leds.TryGetValue((int)ledId, out led) ? led : null; + } + } + + #endregion + public CorsairMouseDeviceInfo MouseDeviceInfo { get; } protected override bool HasEffect => false; + public new IEnumerable Leds => new ReadOnlyCollection(base.Leds.Values.ToList()); + #endregion #region Constructors @@ -22,12 +43,55 @@ namespace CUE.NET.Devices.Mouse : base(info) { this.MouseDeviceInfo = info; + + InitializeLeds(); } #endregion #region Methods + private void InitializeLeds() + { + switch (MouseDeviceInfo.PhysicalLayout) + { + case CorsairPhysicalMouseLayout.Zones1: + GetLed((int)CorsairMouseLedId.B1); + break; + case CorsairPhysicalMouseLayout.Zones2: + GetLed((int)CorsairMouseLedId.B1); + GetLed((int)CorsairMouseLedId.B2); + break; + case CorsairPhysicalMouseLayout.Zones3: + GetLed((int)CorsairMouseLedId.B1); + GetLed((int)CorsairMouseLedId.B2); + GetLed((int)CorsairMouseLedId.B3); + break; + case CorsairPhysicalMouseLayout.Zones4: + GetLed((int)CorsairMouseLedId.B1); + GetLed((int)CorsairMouseLedId.B2); + GetLed((int)CorsairMouseLedId.B3); + GetLed((int)CorsairMouseLedId.B4); + break; + default: + throw new WrapperException($"Can't initial mouse with layout '{MouseDeviceInfo.PhysicalLayout}'"); + } + } + + #region IEnumerable + + public IEnumerator GetEnumerator() + { + return Leds.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + #endregion + #endregion } }