Added stub-novation-library for launchpad support

This commit is contained in:
DarthAffe committed 2017-08-15 21:09:16 +02:00
1 parent 568a0e9b02
commit f654f825f7
15 files changed
+770 -1

No files matched your search

@@ -0,0 +1,107 @@
using System.Diagnostics;
using RGB.NET.Core;
namespace RGB.NET.Devices.Novation
{
/// <summary>
/// Represents a Id of a <see cref="Led"/> on a <see cref="NovationRGBDevice"/>.
/// </summary>
[DebuggerDisplay("{" + nameof(LedId) + "}")]
public class NovationLedId : ILedId
{
#region Properties & Fields
internal readonly NovationLedIds LedId;
/// <inheritdoc />
public IRGBDevice Device { get; }
/// <inheritdoc />
public bool IsValid => LedId != NovationLedIds.Invalid;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="NovationLedId"/> class.
/// </summary>
/// <param name="device">The <see cref="IRGBDevice"/> the <see cref="ILedId"/> belongs to.</param>
/// <param name="ledId">The <see cref="NovationLedId"/> of the represented <see cref="Led"/>.</param>
public NovationLedId(IRGBDevice device, NovationLedIds ledId)
{
this.Device = device;
this.LedId = ledId;
}
#endregion
#region Methods
/// <summary>
/// Converts the Id of this <see cref="NovationLedId"/> to a human-readable string.
/// </summary>
/// <returns>A string that contains the Id of this <see cref="NovationLedId"/>. For example "Enter".</returns>
public override string ToString()
{
return LedId.ToString();
}
/// <summary>
/// Tests whether the specified object is a <see cref="NovationLedId" /> and is equivalent to this <see cref="NovationLedId" />.
/// </summary>
/// <param name="obj">The object to test.</param>
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="NovationLedId" /> equivalent to this <see cref="NovationLedId" />; otherwise, <c>false</c>.</returns>
public override bool Equals(object obj)
{
NovationLedId compareLedId = obj as NovationLedId;
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="NovationLedId" />.
/// </summary>
/// <returns>An integer value that specifies the hash code for this <see cref="NovationLedId" />.</returns>
public override int GetHashCode()
{
return LedId.GetHashCode();
}
#endregion
#region Operators
/// <summary>
/// Returns a value that indicates whether two specified <see cref="NovationLedId" /> are equal.
/// </summary>
/// <param name="ledId1">The first <see cref="NovationLedId" /> to compare.</param>
/// <param name="ledId2">The second <see cref="NovationLedId" /> 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 ==(NovationLedId ledId1, NovationLedId ledId2)
{
return ReferenceEquals(ledId1, null) ? ReferenceEquals(ledId2, null) : ledId1.Equals(ledId2);
}
/// <summary>
/// Returns a value that indicates whether two specified <see cref="NovationLedId" /> are equal.
/// </summary>
/// <param name="ledId1">The first <see cref="NovationLedId" /> to compare.</param>
/// <param name="ledId2">The second <see cref="NovationLedId" /> 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 !=(NovationLedId ledId1, NovationLedId ledId2)
{
return !(ledId1 == ledId2);
}
#endregion
}
}
@@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Core.Layout;
namespace RGB.NET.Devices.Novation
{
/// <summary>
/// Represents a generic Novation-device. (keyboard, mouse, headset, mousepad).
/// </summary>
public abstract class NovationRGBDevice : AbstractRGBDevice
{
#region Properties & Fields
/// <summary>
/// Gets information about the <see cref="NovationRGBDevice"/>.
/// </summary>
public override IRGBDeviceInfo DeviceInfo { get; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="NovationRGBDevice"/> class.
/// </summary>
/// <param name="info">The generic information provided by Novation for the device.</param>
protected NovationRGBDevice(IRGBDeviceInfo info)
{
this.DeviceInfo = info;
}
#endregion
#region Methods
/// <summary>
/// Initializes the device.
/// </summary>
internal void Initialize()
{
InitializeLayout();
if (InternalSize == null)
{
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
InternalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
}
/// <summary>
/// Initializes the <see cref="Led"/> and <see cref="Size"/> of the device.
/// </summary>
protected abstract void InitializeLayout();
/// <summary>
/// Applies the given layout.
/// </summary>
/// <param name="layoutPath">The file containing the layout.</param>
/// <param name="imageLayout">The name of the layout used to get the images of the leds.</param>
/// <param name="imageBasePath">The path images for this device are collected in.</param>
protected void ApplyLayoutFromFile(string layoutPath, string imageLayout, string imageBasePath)
{
DeviceLayout layout = DeviceLayout.Load(layoutPath);
if (layout != null)
{
LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase));
InternalSize = new Size(layout.Width, layout.Height);
if (layout.Leds != null)
foreach (LedLayout layoutLed in layout.Leds)
{
NovationLedIds ledId;
if (Enum.TryParse(layoutLed.Id, true, out ledId))
{
Led led;
if (LedMapping.TryGetValue(new NovationLedId(this, ledId), out led))
{
led.LedRectangle.Location.X = layoutLed.X;
led.LedRectangle.Location.Y = layoutLed.Y;
led.LedRectangle.Size.Width = layoutLed.Width;
led.LedRectangle.Size.Height = layoutLed.Height;
led.Shape = layoutLed.Shape;
led.ShapeData = layoutLed.ShapeData;
LedImage image = ledImageLayout?.LedImages.FirstOrDefault(x => x.Id == layoutLed.Id);
led.Image = (!string.IsNullOrEmpty(image?.Image))
? new Uri(Path.Combine(imageBasePath, image.Image), UriKind.Absolute)
: new Uri(Path.Combine(imageBasePath, "Missing.png"), UriKind.Absolute);
}
}
}
}
}
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
{
List<Led> leds = ledsToUpdate.Where(x => x.Color.A > 0).ToList();
if (leds.Count > 0)
{
//TODO DarthAffe 15.08.2017: Update Leds
}
}
/// <inheritdoc />
public override void Dispose()
{
//TODO DarthAffe 15.08.2017: Dispose
base.Dispose();
}
#endregion
}
}
@@ -0,0 +1,45 @@
using System;
using RGB.NET.Core;
namespace RGB.NET.Devices.Novation
{
/// <summary>
/// Represents a generic information for a Corsair-<see cref="IRGBDevice"/>.
/// </summary>
public class NovationRGBDeviceInfo : IRGBDeviceInfo
{
#region Properties & Fields
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string Manufacturer => "Novation";
/// <inheritdoc />
public string Model { get; }
/// <inheritdoc />
public Uri Image { get; protected set; }
/// <inheritdoc />
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
#endregion
#region Constructors
/// <summary>
/// Internal constructor of managed <see cref="NovationRGBDeviceInfo"/>.
/// </summary>
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
/// <param name="model">The represented device model.</param>
internal NovationRGBDeviceInfo(RGBDeviceType deviceType, string model)
{
this.DeviceType = deviceType;
this.Model = model;
}
#endregion
}
}