Moved current Asus-Implementation (v2-SDK) to a legacy-project

This commit is contained in:
DarthAffe committed 2019-06-16 12:19:45 +02:00
1 parent 4ee6d3c70a
commit b7099aa7e2
26 files changed
+16 -5

No files matched your search

@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using RGB.NET.Core;
namespace RGB.NET.Devices.Asus
{
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}" />
/// <inheritdoc cref="IAsusRGBDevice" />
/// <summary>
/// Represents a generic Asus-device. (keyboard, mouse, headset, mousepad).
/// </summary>
public abstract class AsusRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, IAsusRGBDevice
where TDeviceInfo : AsusRGBDeviceInfo
{
#region Properties & Fields
/// <inheritdoc />
/// <summary>
/// Gets information about the <see cref="T:RGB.NET.Devices.Asus.AsusRGBDevice" />.
/// </summary>
public override TDeviceInfo DeviceInfo { get; }
/// <summary>
/// Gets or sets the update queue performing updates for this device.
/// </summary>
// ReSharper disable once MemberCanBePrivate.Global
protected AsusUpdateQueue UpdateQueue { get; set; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="AsusRGBDevice{TDeviceInfo}"/> class.
/// </summary>
/// <param name="info">The generic information provided by Asus for the device.</param>
protected AsusRGBDevice(TDeviceInfo info)
{
this.DeviceInfo = info;
}
#endregion
#region Methods
/// <summary>
/// Initializes the device.
/// </summary>
public void Initialize(IDeviceUpdateTrigger updateTrigger)
{
InitializeLayout();
if (Size == Size.Invalid)
{
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
UpdateQueue = new AsusUpdateQueue(updateTrigger);
UpdateQueue.Initialize(GetUpdateColorAction(), DeviceInfo.Handle, LedMapping.Count);
}
/// <summary>
/// Initializes the <see cref="Led"/> and <see cref="Size"/> of the device.
/// </summary>
protected abstract void InitializeLayout();
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
/// <summary>
/// Gets a action to update the physical device.
/// </summary>
/// <returns></returns>
protected abstract Action<IntPtr, byte[]> GetUpdateColorAction();
/// <inheritdoc cref="IDisposable.Dispose" />
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}.Dispose" />
public override void Dispose()
{
if ((DeviceInfo is AsusRGBDeviceInfo deviceInfo) && (deviceInfo.Handle != IntPtr.Zero))
Marshal.FreeHGlobal(deviceInfo.Handle);
base.Dispose();
}
#endregion
}
}
@@ -0,0 +1,63 @@
using System;
using RGB.NET.Core;
namespace RGB.NET.Devices.Asus
{
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a Corsair-<see cref="T:RGB.NET.Core.IRGBDevice" />.
/// </summary>
public abstract class AsusRGBDeviceInfo : IRGBDeviceInfo
{
#region Properties & Fields
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer { get; }
/// <inheritdoc />
public string Model { get; }
/// <inheritdoc />
public Uri Image { get; set; }
/// <inheritdoc />
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
/// <inheritdoc />
public abstract bool SupportsSyncBack { get; }
/// <summary>
/// Gets the index of the <see cref="AsusRGBDevice{TDeviceInfo}"/>.
/// </summary>
internal IntPtr Handle { get; }
#endregion
#region Constructors
/// <summary>
/// Internal constructor of managed <see cref="AsusRGBDeviceInfo"/>.
/// </summary>
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
/// <param name="handle">The handle of the <see cref="IRGBDevice"/>.</param>
/// <param name="manufacturer">The manufacturer-name of the <see cref="IRGBDevice"/>.</param>
/// <param name="model">The model-name of the <see cref="IRGBDevice"/>.</param>
internal AsusRGBDeviceInfo(RGBDeviceType deviceType, IntPtr handle, string model = "Generic Asus-Device", string manufacturer = "Asus")
{
this.DeviceType = deviceType;
this.Handle = handle;
this.Model = model;
this.Manufacturer = manufacturer;
DeviceName = $"{Manufacturer} {Model}";
}
#endregion
}
}
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.Asus
{
/// <inheritdoc />
/// <summary>
/// Represents the update-queue performing updates for asus devices.
/// </summary>
public class AsusUpdateQueue : UpdateQueue
{
#region Properties & Fields
/// <summary>
/// Gets or sets the internal color-data cache.
/// </summary>
// ReSharper disable once MemberCanBePrivate.Global
protected byte[] ColorData { get; private set; }
private Action<IntPtr, byte[]> _updateAction;
private IntPtr _handle;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="AsusUpdateQueue"/> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used by this queue.</param>
public AsusUpdateQueue(IDeviceUpdateTrigger updateTrigger)
: base(updateTrigger)
{ }
#endregion
#region Methods
/// <summary>
/// Initializes the queue.
/// </summary>
/// <param name="updateAction">The update-action called by the queue to perform updates.</param>
/// <param name="handle">The handle of the device this queue performs updates for.</param>
/// <param name="ledCount">The amount of leds of the device this queue performs updates for.</param>
public void Initialize(Action<IntPtr, byte[]> updateAction, IntPtr handle, int ledCount)
{
_updateAction = updateAction;
_handle = handle;
ColorData = new byte[ledCount * 3];
}
/// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet)
{
foreach (KeyValuePair<object, Color> data in dataSet)
{
int index = ((int)data.Key) * 3;
ColorData[index] = data.Value.GetR();
ColorData[index + 1] = data.Value.GetB();
ColorData[index + 2] = data.Value.GetG();
}
_updateAction(_handle, ColorData);
}
#endregion
}
}
@@ -0,0 +1,12 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.Asus
{
/// <summary>
/// Represents a asus RGB-device.
/// </summary>
internal interface IAsusRGBDevice : IRGBDevice
{
void Initialize(IDeviceUpdateTrigger updateTrigger);
}
}