Skip to content

Commit 0622f5f

Browse files
committed
SD+ Support
1 parent f579d49 commit 0622f5f

19 files changed

Lines changed: 1207 additions & 334 deletions

barraider-sdtools/Backend/SDConnection.cs

Lines changed: 101 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using BarRaider.SdTools.Payloads;
1010
using BarRaider.SdTools.Communication;
1111
using BarRaider.SdTools.Communication.SDEvents;
12+
using System.Collections.Generic;
1213

1314
namespace BarRaider.SdTools
1415
{
@@ -79,7 +80,95 @@ public class SDConnection : ISDConnection
7980

8081
#endregion
8182

82-
#region Public Implementations
83+
#region Public Properties
84+
85+
86+
/// <summary>
87+
/// An opaque value identifying the plugin. This value is received during the Registration procedure
88+
/// </summary>
89+
[JsonIgnore]
90+
public String ContextId { get; private set; }
91+
92+
/// <summary>
93+
/// An opaque value identifying the device the plugin is launched on.
94+
/// </summary>
95+
[JsonIgnore]
96+
public String DeviceId { get; private set; }
97+
98+
/// <summary>
99+
/// StreamDeckConnection object, initialized based on the args received when launching the program
100+
/// </summary>
101+
[JsonIgnore]
102+
public StreamDeckConnection StreamDeckConnection { get; private set; }
103+
104+
#endregion
105+
106+
/// <summary>
107+
/// Public constructor, a StreamDeckConnection object is required along with the current action and context IDs
108+
/// These will be used to correctly communicate with the StreamDeck App
109+
/// </summary>
110+
/// <param name="connection"></param>
111+
/// <param name="pluginUUID"></param>
112+
/// <param name="deviceInfo"></param>
113+
/// <param name="actionId"></param>
114+
/// <param name="contextId"></param>
115+
/// /// <param name="deviceId"></param>
116+
public SDConnection(StreamDeckConnection connection, string pluginUUID, StreamDeckInfo deviceInfo, string actionId, string contextId, string deviceId)
117+
{
118+
StreamDeckConnection = connection;
119+
this.pluginUUID = pluginUUID;
120+
this.deviceInfo = deviceInfo;
121+
this.actionId = actionId;
122+
this.ContextId = contextId;
123+
this.DeviceId = deviceId;
124+
125+
StreamDeckConnection.OnSendToPlugin += Connection_OnSendToPlugin;
126+
StreamDeckConnection.OnTitleParametersDidChange += Connection_OnTitleParametersDidChange;
127+
StreamDeckConnection.OnApplicationDidTerminate += Connection_OnApplicationDidTerminate;
128+
StreamDeckConnection.OnApplicationDidLaunch += Connection_OnApplicationDidLaunch;
129+
StreamDeckConnection.OnDeviceDidDisconnect += Connection_OnDeviceDidDisconnect;
130+
StreamDeckConnection.OnDeviceDidConnect += Connection_OnDeviceDidConnect;
131+
StreamDeckConnection.OnPropertyInspectorDidAppear += Connection_OnPropertyInspectorDidAppear;
132+
StreamDeckConnection.OnPropertyInspectorDidDisappear += Connection_OnPropertyInspectorDidDisappear;
133+
StreamDeckConnection.OnSystemDidWakeUp += StreamDeckConnection_OnSystemDidWakeUp;
134+
}
135+
136+
#region Public Methods
137+
138+
/// <summary>
139+
/// Dispose (Destructor) function
140+
/// </summary>
141+
public void Dispose()
142+
{
143+
StreamDeckConnection.OnSendToPlugin -= Connection_OnSendToPlugin;
144+
StreamDeckConnection.OnTitleParametersDidChange -= Connection_OnTitleParametersDidChange;
145+
StreamDeckConnection.OnApplicationDidTerminate -= Connection_OnApplicationDidTerminate;
146+
StreamDeckConnection.OnApplicationDidLaunch -= Connection_OnApplicationDidLaunch;
147+
StreamDeckConnection.OnDeviceDidDisconnect -= Connection_OnDeviceDidDisconnect;
148+
StreamDeckConnection.OnDeviceDidConnect -= Connection_OnDeviceDidConnect;
149+
StreamDeckConnection.OnPropertyInspectorDidAppear -= Connection_OnPropertyInspectorDidAppear;
150+
StreamDeckConnection.OnPropertyInspectorDidDisappear -= Connection_OnPropertyInspectorDidDisappear;
151+
StreamDeckConnection.OnSystemDidWakeUp -= StreamDeckConnection_OnSystemDidWakeUp;
152+
}
153+
154+
/// <summary>
155+
/// Gets the Stream Deck device's info
156+
/// </summary>
157+
/// <returns></returns>
158+
public StreamDeckDeviceInfo DeviceInfo()
159+
{
160+
if (deviceInfo == null || string.IsNullOrEmpty(DeviceId))
161+
{
162+
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Could not get DeviceInfo for DeviceId: {DeviceId} Devices: {deviceInfo?.Devices?.Length}");
163+
return null;
164+
}
165+
166+
return deviceInfo.Devices.Where(d => d.Id == DeviceId).FirstOrDefault();
167+
}
168+
169+
#endregion
170+
171+
#region Public Requests
83172

84173
/// <summary>
85174
/// Send settings to the PropertyInspector
@@ -241,21 +330,6 @@ public async Task LogSDMessage(string message)
241330
await StreamDeckConnection.LogMessageAsync(message);
242331
}
243332

244-
/// <summary>
245-
/// Gets the Stream Deck device's info
246-
/// </summary>
247-
/// <returns></returns>
248-
public StreamDeckDeviceInfo DeviceInfo()
249-
{
250-
if (deviceInfo == null || string.IsNullOrEmpty(DeviceId))
251-
{
252-
Logger.Instance.LogMessage(TracingLevel.ERROR, $"Could not get DeviceInfo for DeviceId: {DeviceId} Devices: {deviceInfo?.Devices?.Length}");
253-
return null;
254-
}
255-
256-
return deviceInfo.Devices.Where(d => d.Id == DeviceId).FirstOrDefault();
257-
}
258-
259333
/// <summary>
260334
/// Tells Stream Deck to return the current plugin settings via the ReceivedSettings function
261335
/// </summary>
@@ -295,72 +369,27 @@ public async Task SetStateAsync(uint state)
295369
await StreamDeckConnection.SetStateAsync(state, ContextId);
296370
}
297371

298-
#endregion
299-
300-
/// <summary>
301-
/// An opaque value identifying the plugin. This value is received during the Registration procedure
302-
/// </summary>
303-
[JsonIgnore]
304-
public String ContextId { get; private set; }
305-
306-
/// <summary>
307-
/// An opaque value identifying the device the plugin is launched on.
308-
/// </summary>
309-
[JsonIgnore]
310-
public String DeviceId { get; private set; }
311-
312-
/// <summary>
313-
/// StreamDeckConnection object, initialized based on the args received when launching the program
314-
/// </summary>
315-
[JsonIgnore]
316-
public StreamDeckConnection StreamDeckConnection { get; private set; }
317-
318372
/// <summary>
319-
/// Public constructor, a StreamDeckConnection object is required along with the current action and context IDs
320-
/// These will be used to correctly communicate with the StreamDeck App
373+
/// Sets the values of touchpad layouts items
321374
/// </summary>
322-
/// <param name="connection"></param>
323-
/// <param name="pluginUUID"></param>
324-
/// <param name="deviceInfo"></param>
325-
/// <param name="actionId"></param>
326-
/// <param name="contextId"></param>
327-
/// /// <param name="deviceId"></param>
328-
public SDConnection(StreamDeckConnection connection, string pluginUUID, StreamDeckInfo deviceInfo, string actionId, string contextId, string deviceId)
375+
/// <param name="dictKeyValues"></param>
376+
/// <returns></returns>
377+
public async Task SetFeedbackAsync(Dictionary<string, string> dictKeyValues)
329378
{
330-
StreamDeckConnection = connection;
331-
this.pluginUUID = pluginUUID;
332-
this.deviceInfo = deviceInfo;
333-
this.actionId = actionId;
334-
this.ContextId = contextId;
335-
this.DeviceId = deviceId;
336-
337-
StreamDeckConnection.OnSendToPlugin += Connection_OnSendToPlugin;
338-
StreamDeckConnection.OnTitleParametersDidChange += Connection_OnTitleParametersDidChange;
339-
StreamDeckConnection.OnApplicationDidTerminate += Connection_OnApplicationDidTerminate;
340-
StreamDeckConnection.OnApplicationDidLaunch += Connection_OnApplicationDidLaunch;
341-
StreamDeckConnection.OnDeviceDidDisconnect += Connection_OnDeviceDidDisconnect;
342-
StreamDeckConnection.OnDeviceDidConnect += Connection_OnDeviceDidConnect;
343-
StreamDeckConnection.OnPropertyInspectorDidAppear += Connection_OnPropertyInspectorDidAppear;
344-
StreamDeckConnection.OnPropertyInspectorDidDisappear += Connection_OnPropertyInspectorDidDisappear;
345-
StreamDeckConnection.OnSystemDidWakeUp += StreamDeckConnection_OnSystemDidWakeUp;
379+
await StreamDeckConnection.SetFeedbackAsync(dictKeyValues, ContextId);
346380
}
347381

348382
/// <summary>
349-
/// Dispose (Destructor) function
383+
/// Sets the value of a single touchpad layout item
350384
/// </summary>
351-
public void Dispose()
385+
/// <param name="dictKeyValues"></param>
386+
/// <returns></returns>
387+
public async Task SetFeedbackAsync(string layoutItemKey, string value)
352388
{
353-
StreamDeckConnection.OnSendToPlugin -= Connection_OnSendToPlugin;
354-
StreamDeckConnection.OnTitleParametersDidChange -= Connection_OnTitleParametersDidChange;
355-
StreamDeckConnection.OnApplicationDidTerminate -= Connection_OnApplicationDidTerminate;
356-
StreamDeckConnection.OnApplicationDidLaunch -= Connection_OnApplicationDidLaunch;
357-
StreamDeckConnection.OnDeviceDidDisconnect -= Connection_OnDeviceDidDisconnect;
358-
StreamDeckConnection.OnDeviceDidConnect -= Connection_OnDeviceDidConnect;
359-
StreamDeckConnection.OnPropertyInspectorDidAppear -= Connection_OnPropertyInspectorDidAppear;
360-
StreamDeckConnection.OnPropertyInspectorDidDisappear -= Connection_OnPropertyInspectorDidDisappear;
361-
StreamDeckConnection.OnSystemDidWakeUp -= StreamDeckConnection_OnSystemDidWakeUp;
389+
await StreamDeckConnection.SetFeedbackAsync(new Dictionary<string, string>() { { layoutItemKey, value } }, ContextId);
362390
}
363391

392+
#endregion
364393

365394
#region Event Wrappers
366395

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Newtonsoft.Json;
2+
using System.Collections.Generic;
3+
4+
namespace BarRaider.SdTools.Communication.Messages
5+
{
6+
internal class SetFeedbackMessage : IMessage
7+
{
8+
[JsonProperty("event")]
9+
public string Event { get { return "setFeedback"; } }
10+
11+
[JsonProperty("context")]
12+
public string Context { get; private set; }
13+
14+
[JsonProperty("payload")]
15+
public Dictionary<string, string> DictKeyValues { get; private set; }
16+
17+
public SetFeedbackMessage(Dictionary<string, string> dictKeyValues, string pluginUUID)
18+
{
19+
this.Context = pluginUUID;
20+
DictKeyValues = dictKeyValues;
21+
}
22+
}
23+
}

barraider-sdtools/Communication/SDEvents/BaseEvent.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ internal static class EventTypes
2626
public const string PropertyInspectorDidAppear = "propertyInspectorDidAppear";
2727
public const string PropertyInspectorDidDisappear = "propertyInspectorDidDisappear";
2828
public const string SendToPlugin = "sendToPlugin";
29+
public const string DialRotate = "dialRotate";
30+
public const string DialPress = "dialPress";
31+
public const string TouchpadPress = "touchTap";
2932
}
3033

3134
/// <summary>
@@ -58,6 +61,10 @@ public abstract class BaseEvent
5861
{ EventTypes.PropertyInspectorDidDisappear, typeof(PropertyInspectorDidDisappearEvent) },
5962

6063
{ EventTypes.SendToPlugin, typeof(SendToPluginEvent) },
64+
65+
{ EventTypes.DialRotate, typeof(DialRotateEvent) },
66+
{ EventTypes.DialPress, typeof(DialPressEvent) },
67+
{ EventTypes.TouchpadPress, typeof(TouchpadPress) },
6168
};
6269

6370
/// <summary>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using BarRaider.SdTools.Payloads;
2+
using Newtonsoft.Json;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
7+
namespace BarRaider.SdTools.Communication.SDEvents
8+
{
9+
/// <summary>
10+
/// Payload for Dial press/unpress event
11+
/// </summary>
12+
public class DialPressEvent : BaseEvent
13+
{
14+
/// <summary>
15+
/// Action Name
16+
/// </summary>
17+
[JsonProperty("action")]
18+
public string Action { get; private set; }
19+
20+
/// <summary>
21+
/// Unique Action UUID
22+
/// </summary>
23+
[JsonProperty("context")]
24+
public string Context { get; private set; }
25+
26+
/// <summary>
27+
/// Device UUID key was pressed on
28+
/// </summary>
29+
[JsonProperty("device")]
30+
public string Device { get; private set; }
31+
32+
/// <summary>
33+
/// Information on dial rotation
34+
/// </summary>
35+
[JsonProperty("payload")]
36+
public DialPressPayload Payload { get; private set; }
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using BarRaider.SdTools.Payloads;
2+
using Newtonsoft.Json;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
7+
namespace BarRaider.SdTools.Communication.SDEvents
8+
{
9+
/// <summary>
10+
/// Payload for dial rotation event
11+
/// </summary>
12+
public class DialRotateEvent : BaseEvent
13+
{
14+
/// <summary>
15+
/// Action Name
16+
/// </summary>
17+
[JsonProperty("action")]
18+
public string Action { get; private set; }
19+
20+
/// <summary>
21+
/// Unique Action UUID
22+
/// </summary>
23+
[JsonProperty("context")]
24+
public string Context { get; private set; }
25+
26+
/// <summary>
27+
/// Device UUID key was pressed on
28+
/// </summary>
29+
[JsonProperty("device")]
30+
public string Device { get; private set; }
31+
32+
/// <summary>
33+
/// Information on dial rotation
34+
/// </summary>
35+
[JsonProperty("payload")]
36+
public DialRotatePayload Payload { get; private set; }
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using BarRaider.SdTools.Payloads;
2+
using Newtonsoft.Json;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
7+
namespace BarRaider.SdTools.Communication.SDEvents
8+
{
9+
/// <summary>
10+
/// Payload for touchpad press
11+
/// </summary>
12+
public class TouchpadPress : BaseEvent
13+
{
14+
/// <summary>
15+
/// Action Name
16+
/// </summary>
17+
[JsonProperty("action")]
18+
public string Action { get; private set; }
19+
20+
/// <summary>
21+
/// Unique Action UUID
22+
/// </summary>
23+
[JsonProperty("context")]
24+
public string Context { get; private set; }
25+
26+
/// <summary>
27+
/// Device UUID key was pressed on
28+
/// </summary>
29+
[JsonProperty("device")]
30+
public string Device { get; private set; }
31+
32+
/// <summary>
33+
/// Information on touchpad press
34+
/// </summary>
35+
[JsonProperty("payload")]
36+
public TouchpadPressPayload Payload { get; private set; }
37+
}
38+
}

barraider-sdtools/Communication/SDEvents/WillAppearEvent.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Newtonsoft.Json;
1+
using BarRaider.SdTools.Payloads;
2+
using Newtonsoft.Json;
23

34
namespace BarRaider.SdTools.Communication.SDEvents
45
{

barraider-sdtools/Communication/SDEvents/WillDisappearEvent.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Newtonsoft.Json;
1+
using BarRaider.SdTools.Payloads;
2+
using Newtonsoft.Json;
23

34
namespace BarRaider.SdTools.Communication.SDEvents
45
{

0 commit comments

Comments
 (0)