Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SD+ example with Property Inspector #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "examples/RotaryEncoder/PropertyInspector/libs"]
path = examples/RotaryEncoder/PropertyInspector/libs
url = https://github.com/elgatosf/streamdeck-javascript-sdk.git
7 changes: 7 additions & 0 deletions SharpDeck.sln
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DynamicProfiles", "examples
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{FB8E473E-E823-47AA-B854-3490E26DF126}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DialCounter", "examples\RotaryEncoder\DialCounter.csproj", "{D8B1B1BE-0C7B-4DD5-9381-17B79AFCF211}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -70,6 +72,10 @@ Global
{C878D62A-22AD-4359-8A3F-17508423E46F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C878D62A-22AD-4359-8A3F-17508423E46F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C878D62A-22AD-4359-8A3F-17508423E46F}.Release|Any CPU.Build.0 = Release|Any CPU
{D8B1B1BE-0C7B-4DD5-9381-17B79AFCF211}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8B1B1BE-0C7B-4DD5-9381-17B79AFCF211}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8B1B1BE-0C7B-4DD5-9381-17B79AFCF211}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8B1B1BE-0C7B-4DD5-9381-17B79AFCF211}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -83,6 +89,7 @@ Global
{CD620C06-FD35-4A9E-936D-6B00C928ACB1} = {33FA25F3-1583-458E-B86C-80EE90C6EE38}
{7C66B2C5-F48E-4FF3-BE63-226F793163CC} = {33FA25F3-1583-458E-B86C-80EE90C6EE38}
{C878D62A-22AD-4359-8A3F-17508423E46F} = {91AE8732-D0CC-4618-968A-02EFDE46E4EF}
{D8B1B1BE-0C7B-4DD5-9381-17B79AFCF211} = {91AE8732-D0CC-4618-968A-02EFDE46E4EF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8CE7DE09-893D-4603-807D-674413F38D73}
Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* [Counter](/examples/Counter) - Single action counter plugin.
* [Shared Counter](/examples/SharedCounter) - Multiple action plugin with a shared counter and reset.
* [Dial Counter](/examples/DialCounter) - Single action counter plugin using SD+ dial.

## How it works

Expand Down
113 changes: 113 additions & 0 deletions examples/RotaryEncoder/Actions/CounterAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
namespace DialCounter.Actions;

using Newtonsoft.Json.Linq;
using SharpDeck;
using SharpDeck.Events.Received;
using SharpDeck.Layouts;
using System.Threading.Tasks;

/// <summary>
/// The dial counter action; displays the count in A1 layout which
/// - increases/decreases on rotating the dial
/// - reset on pressing the dial
/// - increases on pressing the LED screen
/// - reset on holding the LED screen
/// </summary>
[StreamDeckAction("com.geekyeggo.dialcounter.counter")]
public class CounterAction : StreamDeckAction<CounterSettings>
{
/// <summary>
/// Occurs when <see cref="IStreamDeckConnection.WillAppear" /> is received for this instance.
/// </summary>
/// <param name="args">The <see cref="ActionEventArgs{T}" /> instance containing the event data.</param>
/// <returns>The task of handling the event.</returns>
protected override Task OnWillAppear(ActionEventArgs<AppearancePayload> args)
{
// get the current, and set the layout
var settings = args.Payload.GetSettings<CounterSettings>();
return this.UpdateCountAsync(settings.Count);
}

protected override async Task OnSendToPlugin(ActionEventArgs<JObject> args)
{
switch (args.Payload["sdpi_collection"]?["key"]?.ToString())
{
case "tickmultiplier":
if (int.TryParse(args.Payload["sdpi_collection"]?["value"]?.ToString(), out var value))
{
// modify the multiplier
var settings = await this.GetSettingsAsync<CounterSettings>();
settings.TickMultiplier = value;

// save the settings
await this.SetSettingsAsync(settings);
}
break;
}

}

/// <summary>
/// Occurs when <see cref="IStreamDeckConnection.DialRotate" /> is received for this instance.
/// </summary>
/// <param name="args">The <see cref="ActionEventArgs{T}" /> instance containing the event data.</param>
/// <returns>The task of handling the event.</returns>
protected override async Task OnDialRotate(ActionEventArgs<DialRotatePayload> args)
{
// modify the count
var settings = args.Payload.GetSettings<CounterSettings>();
settings.Count += args.Payload.Ticks * settings.TickMultiplier;

// save the settings, and set the layout
await this.SetSettingsAsync(settings);
await this.UpdateCountAsync(settings.Count);
}

/// <summary>
/// Occurs when <see cref="IStreamDeckConnection.DialPress" /> is received for this instance.
/// </summary>
/// <param name="args">The <see cref="ActionEventArgs{T}" /> instance containing the event data.</param>
/// <returns>The task of handling the event.</returns>
protected override async Task OnDialPress(ActionEventArgs<DialPayload> args)
{
// reset the count
var settings = args.Payload.GetSettings<CounterSettings>();
settings.Count = 0;

// save the settings, and set the layout
await this.SetSettingsAsync(settings);
await this.UpdateCountAsync(settings.Count);
}

/// <summary>
/// Occurs when <see cref="IStreamDeckConnection.TouchTap" /> is received for this instance.
/// </summary>
/// <param name="args">The <see cref="ActionEventArgs{T}" /> instance containing the event data.</param>
/// <returns>The task of handling the event.</returns>
protected override async Task OnTouchTap(ActionEventArgs<TouchTapPayload> args)
{
var settings = args.Payload.GetSettings<CounterSettings>();
if (args.Payload.Hold)
{
// reset the count
settings.Count = 0;
}
else
{
// increase the count
settings.Count += 1;
}

// save the settings, and set the layout
await this.SetSettingsAsync(settings);
await this.UpdateCountAsync(settings.Count);
}

private Task UpdateCountAsync(int count)
{
return this.SetFeedbackAsync(new LayoutA1()
{
Value = count.ToString()
});
}
}
17 changes: 17 additions & 0 deletions examples/RotaryEncoder/Actions/CounterSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace DialCounter.Actions;

/// <summary>
/// The <see cref="CounterAction"/> settings.
/// </summary>
public class CounterSettings
{
/// <summary>
/// Gets or sets the count.
/// </summary>
public int Count { get; set; } = 0;

/// <summary>
/// Gets or sets the tick multiplier
/// </summary>
public int TickMultiplier { get; set; } = 1;
}
35 changes: 35 additions & 0 deletions examples/RotaryEncoder/DialCounter.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>$(APPDATA)\Elgato\StreamDeck\Plugins\com.geekyeggo.dialcounter.sdPlugin\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\SharpDeck\SharpDeck.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Images\**\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="PropertyInspector\**\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="manifest.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Exec Command="taskkill -f -t -im StreamDeck.exe -fi &quot;status eq running&quot;" />
</Target>

</Project>
Binary file added examples/RotaryEncoder/Images/Counter/Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/RotaryEncoder/Images/Counter/Icon@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/RotaryEncoder/Images/Counter/Image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/RotaryEncoder/Images/Plugin/Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/RotaryEncoder/Images/Plugin/Icon@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions examples/RotaryEncoder/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#if DEBUG
System.Diagnostics.Debugger.Launch();
#endif
SharpDeck.StreamDeckPlugin.Run();
30 changes: 30 additions & 0 deletions examples/RotaryEncoder/PropertyInspector/counter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Dial Counter Property Inspector</title>
<link rel="stylesheet" href="./libs/css/sdpi.css">
</head>
<body>
<div class="sdpi-wrapper">
<div type="range" class="sdpi-item" id="tickmultiplier">
<div class="sdpi-item-label">Tick Multiplier</div>
<div class="sdpi-item-value">
<span class="clickable" value="-10">-10</span>
<input class="floating-tooltip" type="range" min="-10" max="10" value=1>
<span class="clickable" value="10">10</span>
</div>
</div>
</div>

<div class="sdpi-info-label hidden" style="top: -1000;" value=""></div>

<script src="./libs/js/constants.js"></script>
<script src="./libs/js/events.js"></script>
<script src="./libs/js/api.js"></script>
<script src="./libs/js/property-inspector.js"></script>
<script src="./libs/js/dynamic-styles.js"></script>
<script src="./counter.js"></script>
</body>
</html>
Loading