Skip to content

Commit

Permalink
v6.1 - DialUp & DialDown support
Browse files Browse the repository at this point in the history
- Support for new `DialDown` and `DialUp` events.
- Removed support for deprecated `DialPress` event
  • Loading branch information
BarRaider committed Apr 25, 2023
1 parent 6054509 commit f786a7a
Show file tree
Hide file tree
Showing 13 changed files with 199 additions and 74 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# Stream Deck+ Support
Instead of `PluginBase`, Derive from either `KeypadBase` (if you don't support dials), `EncoderBase` (for only dials), `KeyAndEncoderBase` (for both keys and dials)


# Getting Started
Introducing our new [wiki](https://github.com/BarRaider/streamdeck-tools/wiki) packed with usage instructions, examples and more.

Expand All @@ -34,6 +33,10 @@ Introducing our new [wiki](https://github.com/BarRaider/streamdeck-tools/wiki) p

# Change Log

### Version 6.1
- Support for new `DialDown` and `DialUp` events.
- Removed support for deprecated `DialPress` event

### Version 6.0
1. Merged streamdeck-client-csharp package into library to allow better logging of errors
2. Added support for SD+ SDK
Expand Down
9 changes: 7 additions & 2 deletions barraider-sdtools/Backend/EncoderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ public abstract class EncoderBase : IEncoderPlugin
public abstract void DialRotate(DialRotatePayload payload);

/// <summary>
/// Called when the Dial is pressed or released
/// Called when the Dial is pressed
/// </summary>
public abstract void DialPress(DialPressPayload payload);
public abstract void DialDown(DialPayload payload);

/// <summary>
/// Called when the Dial is released
/// </summary>
public abstract void DialUp(DialPayload payload);

/// <summary>
/// Called when the touchpad (above the dials) is pressed
Expand Down
9 changes: 7 additions & 2 deletions barraider-sdtools/Backend/IEncoderPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ public interface IEncoderPlugin : ICommonPluginFunctions
void DialRotate(DialRotatePayload payload);

/// <summary>
/// Called when the Dial is pressed or released
/// Called when the Dial is pressed
/// </summary>
void DialPress(DialPressPayload payload);
void DialDown(DialPayload payload);

/// <summary>
/// Called when the Dial is released
/// </summary>
void DialUp(DialPayload payload);

/// <summary>
/// Called when the touchpad (above the dials) is pressed
Expand Down
9 changes: 7 additions & 2 deletions barraider-sdtools/Backend/KeyAndEncoderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ public abstract class KeyAndEncoderBase : IKeypadPlugin, IEncoderPlugin
public abstract void DialRotate(DialRotatePayload payload);

/// <summary>
/// Called when the Dial is pressed or released
/// Called when the Dial is pressed
/// </summary>
public abstract void DialPress(DialPressPayload payload);
public abstract void DialDown(DialPayload payload);

/// <summary>
/// Called when the Dial is released
/// </summary>
public abstract void DialUp(DialPayload payload);

/// <summary>
/// Called when the touchpad (above the dials) is pressed
Expand Down
42 changes: 37 additions & 5 deletions barraider-sdtools/Backend/PluginContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public void Run(StreamDeckOptions options)
connection.OnWillAppear += Connection_OnWillAppear;
connection.OnWillDisappear += Connection_OnWillDisappear;
connection.OnDialRotate += Connection_OnDialRotate;
connection.OnDialPress += Connection_OnDialPress;
connection.OnDialDown += Connection_OnDialDown;
connection.OnDialUp += Connection_OnDialUp;
connection.OnTouchpadPress += Connection_OnTouchpadPress;

// Settings changed
Expand Down Expand Up @@ -285,7 +286,38 @@ private async void Connection_OnTouchpadPress(object sender, SDEventReceivedEven
}
}

private async void Connection_OnDialPress(object sender, SDEventReceivedEventArgs<DialPressEvent> e)
// Dial Up

private async void Connection_OnDialUp(object sender, SDEventReceivedEventArgs<DialUpEvent> e)
{
await instancesLock.WaitAsync();
try
{
#if DEBUG
Logger.Instance.LogMessage(TracingLevel.DEBUG, $"DialPress: Context: {e.Event.Context} Action: {e.Event.Action} Payload: {e.Event.Payload?.ToStringEx()}");
#endif

if (instances.ContainsKey(e.Event.Context))
{
DialPayload payload = new DialPayload(e.Event.Payload.Coordinates, e.Event.Payload.Settings, e.Event.Payload.Controller);
if (instances[e.Event.Context] is IEncoderPlugin plugin)
{
plugin.DialUp(payload);
}
else
{
Logger.Instance.LogMessage(TracingLevel.ERROR, $"DialDown General Error: Could not convert {e.Event.Context} to IEncoderPlugin");
}
}
}
finally
{
instancesLock.Release();
}
}

// Dial Down
private async void Connection_OnDialDown(object sender, SDEventReceivedEventArgs<DialDownEvent> e)
{
await instancesLock.WaitAsync();
try
Expand All @@ -296,14 +328,14 @@ private async void Connection_OnDialPress(object sender, SDEventReceivedEventArg

if (instances.ContainsKey(e.Event.Context))
{
DialPressPayload payload = new DialPressPayload(e.Event.Payload.Coordinates, e.Event.Payload.Settings, e.Event.Payload.Controller, e.Event.Payload.IsDialPressed);
DialPayload payload = new DialPayload(e.Event.Payload.Coordinates, e.Event.Payload.Settings, e.Event.Payload.Controller);
if (instances[e.Event.Context] is IEncoderPlugin plugin)
{
plugin.DialPress(payload);
plugin.DialDown(payload);
}
else
{
Logger.Instance.LogMessage(TracingLevel.ERROR, $"DialPress General Error: Could not convert {e.Event.Context} to IEncoderPlugin");
Logger.Instance.LogMessage(TracingLevel.ERROR, $"DialDown General Error: Could not convert {e.Event.Context} to IEncoderPlugin");
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion barraider-sdtools/Communication/SDEvents/BaseEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ internal static class EventTypes
public const string SendToPlugin = "sendToPlugin";
public const string DialRotate = "dialRotate";
public const string DialPress = "dialPress";
public const string DialDown = "dialDown";
public const string DialUp = "dialUp";
public const string TouchpadPress = "touchTap";
}

Expand Down Expand Up @@ -63,7 +65,8 @@ public abstract class BaseEvent
{ EventTypes.SendToPlugin, typeof(SendToPluginEvent) },

{ EventTypes.DialRotate, typeof(DialRotateEvent) },
{ EventTypes.DialPress, typeof(DialPressEvent) },
{ EventTypes.DialDown, typeof(DialDownEvent) },
{ EventTypes.DialUp, typeof(DialUpEvent) },
{ EventTypes.TouchpadPress, typeof(TouchpadPressEvent) },
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
namespace BarRaider.SdTools.Communication.SDEvents
{
/// <summary>
/// Payload for Dial press/unpress event
/// Payload for Dial down event
/// </summary>
public class DialPressEvent : BaseEvent
public class DialDownEvent : BaseEvent
{
/// <summary>
/// Action Name
Expand All @@ -30,9 +30,9 @@ public class DialPressEvent : BaseEvent
public string Device { get; private set; }

/// <summary>
/// Information on dial rotation
/// Information on dial status
/// </summary>
[JsonProperty("payload")]
public DialPressPayload Payload { get; private set; }
public DialPayload Payload { get; private set; }
}
}
38 changes: 38 additions & 0 deletions barraider-sdtools/Communication/SDEvents/DialUpEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using BarRaider.SdTools.Payloads;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace BarRaider.SdTools.Communication.SDEvents
{
/// <summary>
/// Payload for Dial up event
/// </summary>
public class DialUpEvent : BaseEvent
{
/// <summary>
/// Action Name
/// </summary>
[JsonProperty("action")]
public string Action { get; private set; }

/// <summary>
/// Unique Action UUID
/// </summary>
[JsonProperty("context")]
public string Context { get; private set; }

/// <summary>
/// Device UUID key was pressed on
/// </summary>
[JsonProperty("device")]
public string Device { get; private set; }

/// <summary>
/// Information on dial status
/// </summary>
[JsonProperty("payload")]
public DialPayload Payload { get; private set; }
}
}
13 changes: 10 additions & 3 deletions barraider-sdtools/Communication/StreamDeckConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,14 @@ public class StreamDeckConnection
public event EventHandler<SDEventReceivedEventArgs<DialRotateEvent>> OnDialRotate;

/// <summary>
/// Raised when a dial is pressed or unpressed
/// Raised when a dial is down
/// </summary>
public event EventHandler<SDEventReceivedEventArgs<DialPressEvent>> OnDialPress;
public event EventHandler<SDEventReceivedEventArgs<DialDownEvent>> OnDialDown;

/// <summary>
/// Raised when a dial is up
/// </summary>
public event EventHandler<SDEventReceivedEventArgs<DialUpEvent>> OnDialUp;

/// <summary>
/// Raised when the tochpad is pressed
Expand Down Expand Up @@ -394,7 +399,9 @@ private async Task<WebSocketCloseStatus> ReceiveAsync()
case EventTypes.PropertyInspectorDidDisappear: OnPropertyInspectorDidDisappear?.Invoke(this, new SDEventReceivedEventArgs<PropertyInspectorDidDisappearEvent>(evt as PropertyInspectorDidDisappearEvent)); break;
case EventTypes.SendToPlugin: OnSendToPlugin?.Invoke(this, new SDEventReceivedEventArgs<SendToPluginEvent>(evt as SendToPluginEvent)); break;
case EventTypes.DialRotate: OnDialRotate?.Invoke(this, new SDEventReceivedEventArgs<DialRotateEvent>(evt as DialRotateEvent)); break;
case EventTypes.DialPress: OnDialPress?.Invoke(this, new SDEventReceivedEventArgs<DialPressEvent>(evt as DialPressEvent)); break;
case EventTypes.DialDown: OnDialDown?.Invoke(this, new SDEventReceivedEventArgs<DialDownEvent>(evt as DialDownEvent)); break;
case EventTypes.DialUp: OnDialUp?.Invoke(this, new SDEventReceivedEventArgs<DialUpEvent>(evt as DialUpEvent)); break;
case EventTypes.DialPress: /* Ignoring deprecated Stream Deck event;*/ break;
case EventTypes.TouchpadPress: OnTouchpadPress?.Invoke(this, new SDEventReceivedEventArgs<TouchpadPressEvent>(evt as TouchpadPressEvent)); break;
default:
Logger.Instance.LogMessage(TracingLevel.WARN, $"{this.GetType()} Unsupported Stream Deck event: {strBuffer}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
namespace BarRaider.SdTools.Payloads
{
/// <summary>
/// Payload received when a dial is pressed or unpressed
/// Payload received when a dial is down or up
/// </summary>
public class DialPressPayload
public class DialPayload
{
/// <summary>
/// Controller which issued the event
Expand All @@ -29,30 +29,22 @@ public class DialPressPayload
[JsonProperty("coordinates")]
public KeyCoordinates Coordinates { get; private set; }

/// <summary>
/// Boolean whether the dial is currently pressed or not
/// </summary>
[JsonProperty("pressed")]
public bool IsDialPressed { get; private set; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="coordinates"></param>
/// <param name="settings"></param>
/// <param name="controller"></param>
/// <param name="isDialPressed"></param>
public DialPressPayload(KeyCoordinates coordinates, JObject settings, string controller, bool isDialPressed)
public DialPayload(KeyCoordinates coordinates, JObject settings, string controller)
{
Coordinates = coordinates;
Settings = settings;
Controller = controller;
IsDialPressed = isDialPressed;
}

/// <summary>
/// Default constructor for serialization
/// </summary>
public DialPressPayload() { }
public DialPayload() { }
}
}
4 changes: 2 additions & 2 deletions barraider-sdtools/Tools/PayloadExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ internal static string ToStringEx(this DialRotatePayload drp)
return $"Controller: {drp.Controller} Ticks: {drp.Ticks} Coordinates: ({drp.Coordinates?.Row},{drp.Coordinates?.Column}) Settings: {drp.Settings}";
}

internal static string ToStringEx(this DialPressPayload dpp)
internal static string ToStringEx(this DialPayload dpp)
{
if (dpp == null)
{
return "DialPressPayload is null!";
}
return $"Controller: {dpp.Controller} IsDialPressed: {dpp.IsDialPressed} Coordinates: ({dpp.Coordinates?.Row},{dpp.Coordinates?.Column}) Settings: {dpp.Settings}";
return $"Controller: {dpp.Controller} Coordinates: ({dpp.Coordinates?.Row},{dpp.Coordinates?.Column}) Settings: {dpp.Settings}";
}

internal static string ToStringEx(this TouchpadPressPayload tpp)
Expand Down
10 changes: 3 additions & 7 deletions barraider-sdtools/barraider-sdtools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ Feel free to contact me for more information: https://barraider.com</Description
<PackageTags>StreamDeck Elgato Library Plugin Stream Deck Toolkit</PackageTags>
<PackageId>StreamDeck-Tools</PackageId>
<PackageIconUrl></PackageIconUrl>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>6.1.0.0</AssemblyVersion>
<FileVersion>6.0.0.0</FileVersion>
<Version>6.0</Version>
<PackageReleaseNotes>6.0 - 1. Merged streamdeck-client-csharp package into library to allow better logging of errors
2. Added support for SD+ SDK
3. Increased timeout of connection to Stream Deck due to the Stream Deck taking longer than before to reply on load
4. Added error catching to prevent 3rd party plugin exception to impact communication
</PackageReleaseNotes>
<Version>6.1.0</Version>
<PackageReleaseNotes>6.1.0 - Support for new DialDown and DialUp events. Removed support for deprecated DialPress event</PackageReleaseNotes>
<RootNamespace>BarRaider.SdTools</RootNamespace>
<AssemblyName>StreamDeckTools</AssemblyName>
<PackageIcon>BRLogo_460.png</PackageIcon>
Expand Down
Loading

0 comments on commit f786a7a

Please sign in to comment.