Skip to content

Commit 5a3f015

Browse files
committed
General maintenance cleanup
1 parent a5c621a commit 5a3f015

File tree

7 files changed

+61
-66
lines changed

7 files changed

+61
-66
lines changed

src/DeckSurf.SDK/Core/DeviceManager.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,13 @@ public static IEnumerable<ConnectedDevice> GetDeviceList()
8080

8181
case DeviceModel.MK2:
8282
{
83-
connectedDevices.Add(new StreamDeckMK2(device.VendorID, device.ProductID, device.DevicePath, device.GetFriendlyName(), device.GetSerialNumber()
84-
));
83+
connectedDevices.Add(new StreamDeckMK2(device.VendorID, device.ProductID, device.DevicePath, device.GetFriendlyName(), device.GetSerialNumber()));
8584
break;
8685
}
8786

8887
case DeviceModel.Neo:
8988
{
90-
connectedDevices.Add(new StreamDeckNeo(device.VendorID, device.ProductID, device.DevicePath, device.GetFriendlyName(), device.GetSerialNumber()
91-
));
89+
connectedDevices.Add(new StreamDeckNeo(device.VendorID, device.ProductID, device.DevicePath, device.GetFriendlyName(), device.GetSerialNumber()));
9290
break;
9391
}
9492

src/DeckSurf.SDK/Models/CompatibleWithAttribute.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace DeckSurf.SDK.Models
1616
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
1717
public class CompatibleWithAttribute(DeviceModel model) : Attribute
1818
{
19-
2019
/// <summary>
2120
/// Gets or sets the <see cref="DeviceModel"/> device model type.
2221
/// </summary>

src/DeckSurf.SDK/Models/ConnectedDevice.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,22 +170,6 @@ public ConnectedDevice(int vid, int pid, string path, string name, string serial
170170

171171
internal HidStream UnderlyingInputStream { get; set; }
172172

173-
internal static ButtonKind GetButtonKind(byte[] identifier)
174-
{
175-
if (identifier.Length != 2)
176-
{
177-
return ButtonKind.Unknown;
178-
}
179-
180-
return (identifier[0], identifier[1]) switch
181-
{
182-
(0x01, 0x00) => ButtonKind.Button,
183-
(0x01, 0x02) => ButtonKind.Screen,
184-
(0x01, 0x03) => ButtonKind.Knob,
185-
_ => ButtonKind.Unknown,
186-
};
187-
}
188-
189173
/// <summary>
190174
/// Abstract method to get the device-specific header.
191175
/// </summary>
@@ -288,7 +272,7 @@ public bool SetKey(int keyId, byte[] image)
288272
using var stream = this.Open();
289273
while (remainingBytes > 0)
290274
{
291-
var sliceLength = Math.Min(remainingBytes, (this.PacketSize - this.KeyImageHeaderSize));
275+
var sliceLength = Math.Min(remainingBytes, this.PacketSize - this.KeyImageHeaderSize);
292276
var bytesSent = iteration * (this.PacketSize - this.KeyImageHeaderSize);
293277

294278
// Get the device-specific header
@@ -308,7 +292,6 @@ public bool SetKey(int keyId, byte[] image)
308292
return true;
309293
}
310294

311-
312295
/// <summary>
313296
/// Sets the key color to a specified color.
314297
/// </summary>
@@ -351,6 +334,22 @@ public bool SetKeyColor(int index, Color color)
351334
/// <returns>True if succesful, false if not.</returns>
352335
public abstract bool SetScreen(byte[] image, int offset, int width, int height);
353336

337+
internal static ButtonKind GetButtonKind(byte[] identifier)
338+
{
339+
if (identifier.Length != 2)
340+
{
341+
return ButtonKind.Unknown;
342+
}
343+
344+
return (identifier[0], identifier[1]) switch
345+
{
346+
(0x01, 0x00) => ButtonKind.Button,
347+
(0x01, 0x02) => ButtonKind.Screen,
348+
(0x01, 0x03) => ButtonKind.Knob,
349+
_ => ButtonKind.Unknown,
350+
};
351+
}
352+
354353
/// <summary>
355354
/// Handles the key press. Different devices carry different implementations.
356355
/// </summary>

src/DeckSurf.SDK/Models/Devices/StreamDeckMini.cs

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,18 @@ public class StreamDeckMini(int vid, int pid, string path, string name, string s
6565
/// <inheritdoc/>
6666
public override byte[] GetKeySetupHeader(int keyId, int sliceLength, int iteration, int remainingBytes)
6767
{
68-
byte finalizer = sliceLength == remainingBytes ? (byte)1 : (byte)0;
69-
var binaryLength = DataHelpers.GetLittleEndianBytesFromInt(sliceLength);
68+
byte[] header = new byte[16];
69+
byte finalizer = (byte)(sliceLength == remainingBytes ? 1 : 0);
7070
var binaryIteration = DataHelpers.GetLittleEndianBytesFromInt(iteration);
7171

72-
return
73-
[
74-
0x02,
75-
0x01,
76-
binaryIteration[0],
77-
binaryIteration[1],
78-
finalizer,
79-
(byte)keyId,
80-
0x00,
81-
0x00,
82-
0x00,
83-
0x00,
84-
0x00,
85-
0x00,
86-
0x00,
87-
0x00,
88-
0x00,
89-
0x00,
90-
];
72+
header[0] = 0x02;
73+
header[1] = 0x01;
74+
header[2] = binaryIteration[0];
75+
header[3] = binaryIteration[1];
76+
header[4] = finalizer;
77+
header[5] = (byte)keyId;
78+
79+
return header;
9180
}
9281

9382
/// <inheritdoc/>
@@ -96,23 +85,6 @@ public override bool SetScreen(byte[] image, int offset, int width, int height)
9685
return false;
9786
}
9887

99-
/// <inheritdoc/>
100-
protected override ButtonPressEventArgs HandleKeyPress(IAsyncResult result, byte[] keyPressBuffer)
101-
{
102-
int bytesRead = this.UnderlyingInputStream.EndRead(result);
103-
104-
if (keyPressBuffer[0] != 0x01)
105-
{
106-
return null;
107-
}
108-
109-
var buttonData = new ArraySegment<byte>(keyPressBuffer, 1, 6).ToArray();
110-
int pressedButton = Array.IndexOf(buttonData, (byte)0x01);
111-
var eventKind = pressedButton != -1 ? ButtonEventKind.DOWN : ButtonEventKind.UP;
112-
113-
return new ButtonPressEventArgs(pressedButton, eventKind, ButtonKind.Button, null, null, null);
114-
}
115-
11688
/// <inheritdoc/>
11789
public override void SetBrightness(byte percentage)
11890
{
@@ -129,5 +101,22 @@ public override void SetBrightness(byte percentage)
129101
using var stream = this.Open();
130102
stream.SetFeature(brightnessRequest);
131103
}
104+
105+
/// <inheritdoc/>
106+
protected override ButtonPressEventArgs HandleKeyPress(IAsyncResult result, byte[] keyPressBuffer)
107+
{
108+
int bytesRead = this.UnderlyingInputStream.EndRead(result);
109+
110+
if (keyPressBuffer[0] != 0x01)
111+
{
112+
return null;
113+
}
114+
115+
var buttonData = new ArraySegment<byte>(keyPressBuffer, 1, 6).ToArray();
116+
int pressedButton = Array.IndexOf(buttonData, (byte)0x01);
117+
var eventKind = pressedButton != -1 ? ButtonEventKind.DOWN : ButtonEventKind.UP;
118+
119+
return new ButtonPressEventArgs(pressedButton, eventKind, ButtonKind.Button, null, null, null);
120+
}
132121
}
133122
}

src/DeckSurf.SDK/Models/Devices/StreamDeckNeo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public override bool SetScreen(byte[] image, int offset, int width, int height)
9696
using var stream = this.Open();
9797
while (remainingBytes > 0)
9898
{
99-
var sliceLength = Math.Min(remainingBytes, (this.PacketSize - this.ScreenImageHeaderSize));
99+
var sliceLength = Math.Min(remainingBytes, this.PacketSize - this.ScreenImageHeaderSize);
100100
var bytesSent = iteration * (this.PacketSize - this.ScreenImageHeaderSize);
101101

102102
byte isLastChunk = sliceLength == remainingBytes ? (byte)1 : (byte)0;

src/DeckSurf.SDK/Models/Devices/StreamDeckPlus.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public override bool SetScreen(byte[] image, int offset, int width, int height)
9696
using var stream = this.Open();
9797
while (remainingBytes > 0)
9898
{
99-
var sliceLength = Math.Min(remainingBytes, (this.PacketSize - this.ScreenImageHeaderSize));
99+
var sliceLength = Math.Min(remainingBytes, this.PacketSize - this.ScreenImageHeaderSize);
100100
var bytesSent = iteration * (this.PacketSize - this.ScreenImageHeaderSize);
101101

102102
byte isLastChunk = sliceLength == remainingBytes ? (byte)1 : (byte)0;

src/DeckSurf.SDK/Models/NativeStructures.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using System;
1+
// Copyright (c) Den Delimarsky
2+
// Den Delimarsky licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
26
using System.Runtime.InteropServices;
37

48
namespace DeckSurf.SDK.Models
@@ -143,9 +147,15 @@ internal struct SIZE
143147
private int cx;
144148
private int cy;
145149

146-
public int Width { set { this.cx = value; } }
150+
public int Width
151+
{
152+
set { this.cx = value; }
153+
}
147154

148-
public int Height { set { this.cy = value; } }
155+
public int Height
156+
{
157+
set { this.cy = value; }
158+
}
149159
}
150160

151161
/// <summary>

0 commit comments

Comments
 (0)