1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 01:58:30 +00:00

Merge pull request #140 from DarthAffe/SDK/SteelSeries

Lisp-handler rewrite
This commit is contained in:
DarthAffe 2020-07-11 21:17:34 +02:00 committed by GitHub
commit 8b0c7ea75b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 18 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Text;
@ -16,16 +17,21 @@ namespace RGB.NET.Devices.SteelSeries.API
private const string GAME_NAME = "RGBNET";
private const string GAME_DISPLAYNAME = "RGB.NET";
private const string EVENT_NAME = "UPDATELEDS";
private static readonly string HANDLER = $@"(handler ""{EVENT_NAME}""
private static readonly string HANDLER = $@"(define (getZone x)
(case x
{string.Join(Environment.NewLine, Enum.GetValues(typeof(SteelSeriesLedId))
.Cast<SteelSeriesLedId>()
.Select(x => x.GetAPIName())
.Select(ledId => $" ((\"{ledId}\") {ledId}:)"))}
))
(handler ""{EVENT_NAME}""
(lambda (data)
(let* ((device (value: data))
(zoneData (frame: data))
(zones (frame-keys zoneData)))
(do ((zoneDo zones (cdr zoneDo)))
((nil? zoneDo))
(let* ((zone (car zoneDo))
(color (get-slot zoneData zone)))
(on-device device show-on-zone: color zone))))))
(zones (zones: data))
(colors (colors: data)))
(on-device device show-on-zones: colors (map (lambda (x) (getZone x)) zones)))))
(add-event-per-key-zone-use ""{EVENT_NAME}"" ""all"")
(add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-1-zone"")
(add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-2-zone"")
@ -87,7 +93,8 @@ namespace RGB.NET.Devices.SteelSeries.API
{
_event.Data.Clear();
_event.Data.Add("value", device);
_event.Data.Add("frame", data);
_event.Data.Add("colors", data.Values.ToList());
_event.Data.Add("zones", data.Keys.ToList());
TriggerEvent(_event);
}

View File

@ -15,7 +15,6 @@ namespace RGB.NET.Devices.SteelSeries
#region Properties & Fields
private string _deviceType;
private Dictionary<object, Color> _lastDataSet;
#endregion
@ -39,20 +38,14 @@ namespace RGB.NET.Devices.SteelSeries
protected override void OnUpdate(object sender, CustomUpdateData customData)
{
if ((customData != null) && (customData["refresh"] as bool? ?? false))
{
if ((_lastDataSet != null) && (_lastDataSet.Count != 0))
Update(_lastDataSet);
}
SteelSeriesSDK.SendHeartbeat();
else
base.OnUpdate(sender, customData);
}
/// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet)
{
_lastDataSet = dataSet;
SteelSeriesSDK.UpdateLeds(_deviceType, dataSet.ToDictionary(x => ((SteelSeriesLedId)x.Key).GetAPIName(), x => x.Value.ToIntArray()));
}
=> SteelSeriesSDK.UpdateLeds(_deviceType, dataSet.ToDictionary(x => ((SteelSeriesLedId)x.Key).GetAPIName(), x => x.Value.ToIntArray()));
#endregion
}