mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-13 00:58:31 +00:00
Introduced "KeyGroups"
This commit is contained in:
parent
fc66ac0ceb
commit
0167828a19
@ -67,6 +67,9 @@
|
|||||||
<Compile Include="Devices\Headset\Enums\CorsairHeadsetLedId.cs" />
|
<Compile Include="Devices\Headset\Enums\CorsairHeadsetLedId.cs" />
|
||||||
<Compile Include="Devices\Keyboard\Enums\CorsairKeyboardKeyId.cs" />
|
<Compile Include="Devices\Keyboard\Enums\CorsairKeyboardKeyId.cs" />
|
||||||
<Compile Include="Devices\Keyboard\Enums\CorsairPhysicalKeyboardLayout.cs" />
|
<Compile Include="Devices\Keyboard\Enums\CorsairPhysicalKeyboardLayout.cs" />
|
||||||
|
<Compile Include="Devices\Keyboard\Keys\BaseKeyGroup.cs" />
|
||||||
|
<Compile Include="Devices\Keyboard\Keys\IKeyGroup.cs" />
|
||||||
|
<Compile Include="Devices\Keyboard\Keys\SimpleKeyGroup.cs" />
|
||||||
<Compile Include="Devices\Mouse\Enums\CorsairMouseButtonId.cs" />
|
<Compile Include="Devices\Mouse\Enums\CorsairMouseButtonId.cs" />
|
||||||
<Compile Include="Devices\Mouse\Enums\CorsairPhysicalMouseLayout.cs" />
|
<Compile Include="Devices\Mouse\Enums\CorsairPhysicalMouseLayout.cs" />
|
||||||
<Compile Include="Exceptions\CUEException.cs" />
|
<Compile Include="Exceptions\CUEException.cs" />
|
||||||
@ -77,7 +80,7 @@
|
|||||||
<Compile Include="Devices\Headset\CorsairHeadset.cs" />
|
<Compile Include="Devices\Headset\CorsairHeadset.cs" />
|
||||||
<Compile Include="Devices\Headset\CorsairHeadsetDeviceInfo.cs" />
|
<Compile Include="Devices\Headset\CorsairHeadsetDeviceInfo.cs" />
|
||||||
<Compile Include="Devices\IDeviceInfo.cs" />
|
<Compile Include="Devices\IDeviceInfo.cs" />
|
||||||
<Compile Include="Devices\Keyboard\CorsairKey.cs" />
|
<Compile Include="Devices\Keyboard\Keys\CorsairKey.cs" />
|
||||||
<Compile Include="Devices\Keyboard\CorsairKeyboard.cs" />
|
<Compile Include="Devices\Keyboard\CorsairKeyboard.cs" />
|
||||||
<Compile Include="Devices\Mouse\CorsairMouseDeviceInfo.cs" />
|
<Compile Include="Devices\Mouse\CorsairMouseDeviceInfo.cs" />
|
||||||
<Compile Include="Devices\Mouse\CorsairMouse.cs" />
|
<Compile Include="Devices\Mouse\CorsairMouse.cs" />
|
||||||
|
|||||||
@ -29,15 +29,15 @@ namespace CUE.NET.Devices.Generic
|
|||||||
|
|
||||||
protected CorsairLed GetLed(int ledId)
|
protected CorsairLed GetLed(int ledId)
|
||||||
{
|
{
|
||||||
if (!this.Leds.ContainsKey(ledId))
|
if (!Leds.ContainsKey(ledId))
|
||||||
this.Leds.Add(ledId, new CorsairLed());
|
Leds.Add(ledId, new CorsairLed());
|
||||||
|
|
||||||
return this.Leds[ledId];
|
return Leds[ledId];
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void UpdateLeds(bool fullUpdate = false)
|
public virtual void UpdateLeds(bool fullUpdate = false)
|
||||||
{
|
{
|
||||||
IList<KeyValuePair<int, CorsairLed>> ledsToUpdate = (fullUpdate ? this.Leds : this.Leds.Where(x => x.Value.IsDirty)).ToList();
|
IList<KeyValuePair<int, CorsairLed>> ledsToUpdate = (fullUpdate ? Leds : Leds.Where(x => x.Value.IsDirty)).ToList();
|
||||||
|
|
||||||
if (!ledsToUpdate.Any())
|
if (!ledsToUpdate.Any())
|
||||||
return; // CUE seems to crash if 'CorsairSetLedsColors' is called with a zero length array
|
return; // CUE seems to crash if 'CorsairSetLedsColors' is called with a zero length array
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using CUE.NET.Devices.Generic;
|
using CUE.NET.Devices.Generic;
|
||||||
using CUE.NET.Devices.Keyboard.Enums;
|
using CUE.NET.Devices.Keyboard.Enums;
|
||||||
|
using CUE.NET.Devices.Keyboard.Keys;
|
||||||
|
|
||||||
namespace CUE.NET.Devices.Keyboard
|
namespace CUE.NET.Devices.Keyboard
|
||||||
{
|
{
|
||||||
@ -14,7 +15,11 @@ namespace CUE.NET.Devices.Keyboard
|
|||||||
private Dictionary<CorsairKeyboardKeyId, CorsairKey> _keys = new Dictionary<CorsairKeyboardKeyId, CorsairKey>();
|
private Dictionary<CorsairKeyboardKeyId, CorsairKey> _keys = new Dictionary<CorsairKeyboardKeyId, CorsairKey>();
|
||||||
public CorsairKey this[CorsairKeyboardKeyId keyId]
|
public CorsairKey this[CorsairKeyboardKeyId keyId]
|
||||||
{
|
{
|
||||||
get { return this._keys[keyId]; }
|
get
|
||||||
|
{
|
||||||
|
CorsairKey key;
|
||||||
|
return _keys.TryGetValue(keyId, out key) ? key : null;
|
||||||
|
}
|
||||||
private set { throw new NotSupportedException(); }
|
private set { throw new NotSupportedException(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +32,7 @@ namespace CUE.NET.Devices.Keyboard
|
|||||||
{
|
{
|
||||||
this.KeyboardDeviceInfo = info;
|
this.KeyboardDeviceInfo = info;
|
||||||
|
|
||||||
this.InitializeKeys();
|
InitializeKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -37,7 +42,7 @@ namespace CUE.NET.Devices.Keyboard
|
|||||||
private void InitializeKeys()
|
private void InitializeKeys()
|
||||||
{
|
{
|
||||||
foreach (CorsairKeyboardKeyId keyId in Enum.GetValues(typeof(CorsairKeyboardKeyId)))
|
foreach (CorsairKeyboardKeyId keyId in Enum.GetValues(typeof(CorsairKeyboardKeyId)))
|
||||||
this._keys.Add(keyId, new CorsairKey(keyId, this.GetLed((int)keyId)));
|
_keys.Add(keyId, new CorsairKey(keyId, GetLed((int)keyId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
42
Devices/Keyboard/Keys/BaseKeyGroup.cs
Normal file
42
Devices/Keyboard/Keys/BaseKeyGroup.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace CUE.NET.Devices.Keyboard.Keys
|
||||||
|
{
|
||||||
|
public class BaseKeyGroup : IKeyGroup
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
protected CorsairKeyboard Keyboard { get; }
|
||||||
|
|
||||||
|
public IList<CorsairKey> Keys { get; } = new List<CorsairKey>();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
protected BaseKeyGroup(CorsairKeyboard keyboard)
|
||||||
|
{
|
||||||
|
this.Keyboard = keyboard;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
public virtual void SetColor(Color color)
|
||||||
|
{
|
||||||
|
foreach (CorsairKey key in Keys)
|
||||||
|
key.Led.Color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MergeKeys(IKeyGroup groupToMerge)
|
||||||
|
{
|
||||||
|
foreach (CorsairKey key in groupToMerge.Keys)
|
||||||
|
if (!Keys.Contains(key))
|
||||||
|
Keys.Add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
using CUE.NET.Devices.Generic;
|
using CUE.NET.Devices.Generic;
|
||||||
using CUE.NET.Devices.Keyboard.Enums;
|
using CUE.NET.Devices.Keyboard.Enums;
|
||||||
|
|
||||||
namespace CUE.NET.Devices.Keyboard
|
namespace CUE.NET.Devices.Keyboard.Keys
|
||||||
{
|
{
|
||||||
public class CorsairKey
|
public class CorsairKey
|
||||||
{
|
{
|
||||||
15
Devices/Keyboard/Keys/IKeyGroup.cs
Normal file
15
Devices/Keyboard/Keys/IKeyGroup.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace CUE.NET.Devices.Keyboard.Keys
|
||||||
|
{
|
||||||
|
public interface IKeyGroup
|
||||||
|
{
|
||||||
|
//TODO DarthAffe 19.09.2015: This might be not needed/bad
|
||||||
|
IList<CorsairKey> Keys { get; }
|
||||||
|
|
||||||
|
void SetColor(Color color);
|
||||||
|
|
||||||
|
void MergeKeys(IKeyGroup groupToMerge);
|
||||||
|
}
|
||||||
|
}
|
||||||
72
Devices/Keyboard/Keys/SimpleKeyGroup.cs
Normal file
72
Devices/Keyboard/Keys/SimpleKeyGroup.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using CUE.NET.Devices.Keyboard.Enums;
|
||||||
|
|
||||||
|
namespace CUE.NET.Devices.Keyboard.Keys
|
||||||
|
{
|
||||||
|
public class SimpleKeyGroup : BaseKeyGroup
|
||||||
|
{
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public SimpleKeyGroup(CorsairKeyboard keyboard)
|
||||||
|
: base(keyboard)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public SimpleKeyGroup(CorsairKeyboard keyboard, params CorsairKey[] keys)
|
||||||
|
: base(keyboard)
|
||||||
|
{
|
||||||
|
AddKey(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleKeyGroup(CorsairKeyboard keyboard, params CorsairKeyboardKeyId[] keys)
|
||||||
|
: base(keyboard)
|
||||||
|
{
|
||||||
|
AddKey(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
public void AddKey(params CorsairKey[] keys)
|
||||||
|
{
|
||||||
|
if (keys != null)
|
||||||
|
foreach (CorsairKey key in keys)
|
||||||
|
if (key != null && !ContainsKey(key))
|
||||||
|
Keys.Add(key);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddKey(params CorsairKeyboardKeyId[] keyIds)
|
||||||
|
{
|
||||||
|
if (keyIds != null)
|
||||||
|
foreach (CorsairKeyboardKeyId keyId in keyIds)
|
||||||
|
AddKey(Keyboard[keyId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveKey(params CorsairKey[] keys)
|
||||||
|
{
|
||||||
|
if (keys != null)
|
||||||
|
foreach (CorsairKey key in keys)
|
||||||
|
if (key != null)
|
||||||
|
Keys.Remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveKey(params CorsairKeyboardKeyId[] keyIds)
|
||||||
|
{
|
||||||
|
if (keyIds != null)
|
||||||
|
foreach (CorsairKeyboardKeyId keyId in keyIds)
|
||||||
|
RemoveKey(Keyboard[keyId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ContainsKey(CorsairKey key)
|
||||||
|
{
|
||||||
|
return key != null && Keys.Contains(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ContainsKey(CorsairKeyboardKeyId keyId)
|
||||||
|
{
|
||||||
|
return ContainsKey(Keyboard[keyId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,6 +4,7 @@ using CUE.NET;
|
|||||||
using CUE.NET.Devices.Generic.Enums;
|
using CUE.NET.Devices.Generic.Enums;
|
||||||
using CUE.NET.Devices.Keyboard;
|
using CUE.NET.Devices.Keyboard;
|
||||||
using CUE.NET.Devices.Keyboard.Enums;
|
using CUE.NET.Devices.Keyboard.Enums;
|
||||||
|
using CUE.NET.Devices.Keyboard.Keys;
|
||||||
using CUE.NET.Exceptions;
|
using CUE.NET.Exceptions;
|
||||||
|
|
||||||
namespace SimpleDevTest
|
namespace SimpleDevTest
|
||||||
@ -24,11 +25,8 @@ namespace SimpleDevTest
|
|||||||
keyboard[CorsairKeyboardKeyId.G].Led.Color = Color.Green;
|
keyboard[CorsairKeyboardKeyId.G].Led.Color = Color.Green;
|
||||||
keyboard[CorsairKeyboardKeyId.B].Led.Color = Color.Blue;
|
keyboard[CorsairKeyboardKeyId.B].Led.Color = Color.Blue;
|
||||||
|
|
||||||
keyboard[CorsairKeyboardKeyId.W].Led.Color = Color.White;
|
SimpleKeyGroup whiteGroup = new SimpleKeyGroup(keyboard, CorsairKeyboardKeyId.W, CorsairKeyboardKeyId.H, CorsairKeyboardKeyId.I, CorsairKeyboardKeyId.T, CorsairKeyboardKeyId.E);
|
||||||
keyboard[CorsairKeyboardKeyId.H].Led.Color = Color.White;
|
whiteGroup.SetColor(Color.White);
|
||||||
keyboard[CorsairKeyboardKeyId.I].Led.Color = Color.White;
|
|
||||||
keyboard[CorsairKeyboardKeyId.T].Led.Color = Color.White;
|
|
||||||
keyboard[CorsairKeyboardKeyId.E].Led.Color = Color.White;
|
|
||||||
|
|
||||||
keyboard.UpdateLeds();
|
keyboard.UpdateLeds();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user