Skip to content
This repository was archived by the owner on Dec 2, 2025. It is now read-only.

Commit 01e4070

Browse files
committed
Add support for SD+
With the release of SD+ you now have control over dials and touchscreen on top of the usual buttons. Support adds a few new events received and sent and new configuration objects like Encoder and Layout.
1 parent 0289df8 commit 01e4070

5 files changed

Lines changed: 434 additions & 0 deletions

File tree

src/Action.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ActionEvents } from "./events";
22
import { State, StateProps } from "./State";
33
import { Target } from "./Target";
44
import type { Plugin } from "./Plugin";
5+
import { Encoder } from "./Encoder";
56

67
/**
78
* The Action must match a few files:
@@ -90,6 +91,8 @@ export class Action<
9091
*/
9192
public device = "";
9293

94+
public encoder: Encoder = undefined as unknown as Encoder;
95+
9396
constructor(params: {
9497
name: string;
9598
inspectorName?: string;
@@ -129,6 +132,8 @@ export class Action<
129132
this.hasMultiActionSupport === false,
130133
this.hasMultiActionSupport,
131134
],
135+
["Controllers", this.encoder !== undefined, ["KeyPad", "Encoder"]],
136+
["Encoder", this.encoder !== undefined, this.encoder.toManifest()],
132137
];
133138

134139
optionals.forEach(([prop, condition, value]) => {
@@ -406,4 +411,34 @@ export class Action<
406411
payload: { profile },
407412
});
408413
}
414+
415+
/**
416+
* Send event to dynamically change properties of the SD+ touch display
417+
* @param {Record<string, unknown>} payload Key/Value pairs of properties to
418+
* change
419+
* @return {void}
420+
*/
421+
public setFeedback(payload: Record<string, unknown>) {
422+
this.send({
423+
event: "setFeedback",
424+
context: this.context,
425+
payload,
426+
});
427+
}
428+
429+
/**
430+
* Send an event to dynamically change the layout of a SD+ touch display
431+
* @param {string} layout Internal `id` of built-in layout or path to json
432+
* file that contains a custom layout
433+
* @return {void}
434+
*/
435+
public setFeedbackLayout(layout: string) {
436+
this.send({
437+
event: "setFeedbackLayout",
438+
context: this.context,
439+
payload: {
440+
layout,
441+
},
442+
});
443+
}
409444
}

src/Encoder.ts

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* The encoder is used to configure the dial and display segment on an SD+.
3+
* It is completely optional.
4+
*/
5+
export class Encoder {
6+
/**
7+
* Default background for the touch display slot
8+
* @type {string}
9+
*/
10+
public background?: string;
11+
12+
/**
13+
* Default icon for the Property Inspector, dial stack and layout. Falls back
14+
* to the Action List Icon
15+
*
16+
* @type {string}
17+
*/
18+
public icon?: string;
19+
20+
/**
21+
* Either a built-in layout (string) or a path to a JSON file that describes
22+
* a custom layout. Can be changed with `setFeedbackLayout` event.
23+
* @see Layout
24+
* @type {string}
25+
*/
26+
public layout?: string;
27+
28+
/**
29+
* The color used as the background of the Dial Stack
30+
* @type {string}
31+
*/
32+
public stackColor?: string;
33+
34+
/**
35+
* Part of TriggerDescription. Describes the action performed on rotation of
36+
* the dial
37+
* @type {string}
38+
*/
39+
public onRotateDescription?: string;
40+
41+
/**
42+
* Part of TriggerDescription. Describes the action performed on pressing of
43+
* the dial
44+
* @type {string}
45+
*/
46+
public onPushDescription?: string;
47+
48+
/**
49+
* Part of TriggerDescription. Describes the action performed on touching the
50+
* display pad
51+
* @type {string}
52+
*/
53+
public onTouchDescription?: string;
54+
55+
/**
56+
* Part of TriggerDescription. Describes the action performed on long pressing
57+
* the display pad
58+
* @type {string}
59+
*/
60+
public onLongTouchDescription?: string;
61+
62+
public toManifest(): Record<string, unknown> {
63+
const snippet: Record<string, unknown> = {
64+
background: this.background,
65+
Icon: this.icon,
66+
layout: this.layout,
67+
StackColor: this.stackColor,
68+
TriggerDescription: {
69+
Rotate: this.onRotateDescription,
70+
Push: this.onPushDescription,
71+
Touch: this.onTouchDescription,
72+
LongTouch: this.onLongTouchDescription,
73+
},
74+
};
75+
76+
const optionals: [string, unknown, unknown][] = [
77+
["background", this.background, this.background],
78+
["Icon", this.icon, this.icon],
79+
["layout", this.layout, this.layout],
80+
["StackColor", this.stackColor, this.stackColor],
81+
["StackColor", this.stackColor, this.stackColor],
82+
[
83+
"TriggerDescription",
84+
this.onRotateDescription ||
85+
this.onPushDescription ||
86+
this.onTouchDescription ||
87+
this.onLongTouchDescription,
88+
this.buildTriggerDescription(),
89+
],
90+
];
91+
92+
this.evaluateOptionalValues(optionals, snippet);
93+
return snippet;
94+
}
95+
96+
private buildTriggerDescription() {
97+
const snippet: Record<string, unknown> = {};
98+
99+
const optionals: [string, unknown, unknown][] = [
100+
["Rotate", this.onRotateDescription, this.onRotateDescription],
101+
["Push", this.onPushDescription, this.onPushDescription],
102+
["Touch", this.onTouchDescription, this.onTouchDescription],
103+
["LongTouch", this.onLongTouchDescription, this.onLongTouchDescription],
104+
];
105+
106+
this.evaluateOptionalValues(optionals, snippet);
107+
return snippet;
108+
}
109+
110+
private evaluateOptionalValues(
111+
optionals: [string, unknown, unknown][],
112+
object: Record<string, unknown>,
113+
): Record<string, unknown> {
114+
optionals.forEach(([prop, condition, value]) => {
115+
if (condition) {
116+
object[prop] = value;
117+
}
118+
});
119+
120+
return object;
121+
}
122+
}

0 commit comments

Comments
 (0)