Skip to content

Commit c37f1c8

Browse files
committed
add actions to send and stop morse code
1 parent f094887 commit c37f1c8

4 files changed

Lines changed: 203 additions & 0 deletions

File tree

manifest.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,30 @@
187187
"PropertyInspectorPath": "pi/antenna.html",
188188
"Controllers": ["Keypad"],
189189
"States": [{ "Title": "Ant" }]
190+
},
191+
{
192+
"Name": "Send Morse",
193+
"UUID": "com.thecodingflow.hamlibplugin.sendmorse",
194+
"Tooltip": "Send a Morse code message",
195+
"Icon": "icons/radio_light",
196+
"DisableAutomaticStates": false,
197+
"VisibleInActionsList": true,
198+
"SupportedInMultiActions": true,
199+
"PropertyInspectorPath": "pi/sendmorse.html",
200+
"Controllers": ["Keypad"],
201+
"States": [{ "Title": "CW" }]
202+
},
203+
{
204+
"Name": "Stop Morse",
205+
"UUID": "com.thecodingflow.hamlibplugin.stopmorse",
206+
"Tooltip": "Stop the current Morse code transmission",
207+
"Icon": "icons/radio_light",
208+
"DisableAutomaticStates": false,
209+
"VisibleInActionsList": true,
210+
"SupportedInMultiActions": true,
211+
"PropertyInspectorPath": "pi/empty.html",
212+
"Controllers": ["Keypad"],
213+
"States": [{ "Title": "Stop CW" }]
190214
}
191215
],
192216
"OS": [{ "Platform": "linux" }],

pi/sendmorse.html

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<script>
5+
let update = () => {};
6+
let textSetting = "";
7+
8+
function connectOpenActionSocket(
9+
inPort,
10+
inPropertyInspectorUUID,
11+
inRegisterEvent,
12+
inInfo,
13+
inActionInfo,
14+
) {
15+
const websocket = new WebSocket("ws://localhost:" + inPort);
16+
inActionInfo = JSON.parse(inActionInfo);
17+
websocket.onopen = () => {
18+
websocket.send(
19+
JSON.stringify({
20+
event: inRegisterEvent,
21+
uuid: inPropertyInspectorUUID,
22+
}),
23+
);
24+
};
25+
26+
textSetting = inActionInfo.payload.settings.text ?? "";
27+
28+
websocket.onmessage = (event) => {
29+
const data = JSON.parse(event.data);
30+
if (data.event == "didReceiveSettings") {
31+
textSetting = data.payload.settings.text ?? "";
32+
}
33+
};
34+
35+
const textElement = document.getElementById("text");
36+
textElement.value = inActionInfo.payload.settings.text ?? "";
37+
38+
update = () => {
39+
websocket.send(
40+
JSON.stringify({
41+
event: "setSettings",
42+
context: inActionInfo.context,
43+
payload: {
44+
text: textElement.value || "",
45+
},
46+
}),
47+
);
48+
};
49+
}
50+
51+
const connectElgatoStreamDeckSocket = connectOpenActionSocket;
52+
</script>
53+
54+
<style>
55+
* {
56+
font-family: system-ui, sans-serif;
57+
font-size: 16px;
58+
color: oklch(92.2% 0 0);
59+
}
60+
body {
61+
margin: 16px;
62+
background-color: oklch(26.9% 0 0);
63+
}
64+
label {
65+
margin-right: 4px;
66+
}
67+
input {
68+
margin: 4px;
69+
padding: 4px;
70+
background-color: oklch(37.1% 0 0);
71+
border: 1px solid oklch(43.9% 0 0);
72+
border-radius: 8px;
73+
}
74+
</style>
75+
</head>
76+
77+
<body>
78+
<div>
79+
<label for="text">Text:</label>
80+
<input id="text" oninput="update()" type="text" />
81+
</div>
82+
</body>
83+
</html>

pkg/action/action.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ type RigClient interface {
5050
GetPowerStatus() (hl.PowerStatus, error)
5151
SetPowerStatus(hl.PowerStatus) error
5252
SetAntenna(hl.VFO, int, int) error
53+
SendMorse(string) error
54+
StopMorse() error
5355
}
5456

5557
type Deck interface {

pkg/action/morse.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package action
2+
3+
import (
4+
"log"
5+
6+
sdk "github.com/SkYNewZ/streamdeck-sdk"
7+
)
8+
9+
const (
10+
SendMorseUUID = "com.thecodingflow.hamlibplugin.sendmorse"
11+
StopMorseUUID = "com.thecodingflow.hamlibplugin.stopmorse"
12+
)
13+
14+
func init() {
15+
Factories[SendMorseUUID] = NewSendMorse
16+
Factories[StopMorseUUID] = NewStopMorse
17+
}
18+
19+
type SendMorse struct {
20+
basicAction
21+
}
22+
23+
func NewSendMorse(context string, client RigClient, deck Deck) Action {
24+
return &SendMorse{
25+
basicAction: basicAction{
26+
context: context,
27+
client: client,
28+
deck: deck,
29+
},
30+
}
31+
}
32+
33+
func (a *SendMorse) parseSettings(settings map[string]any) string {
34+
text, ok := settings["text"].(string)
35+
if !ok {
36+
text = ""
37+
}
38+
return text
39+
}
40+
41+
func (a *SendMorse) DidReceiveSettings(payload *sdk.ReceivedEventPayload) error {
42+
a.UpdateVisual(payload)
43+
return nil
44+
}
45+
46+
func (a *SendMorse) UpdateVisual(payload *sdk.ReceivedEventPayload) error {
47+
a.deck.SetTitle(a.context, "CW", sdk.HardwareAndSoftware)
48+
return nil
49+
}
50+
51+
func (a *SendMorse) KeyDown(payload *sdk.ReceivedEventPayload) error {
52+
text := a.parseSettings(payload.Settings)
53+
if text == "" {
54+
return nil
55+
}
56+
57+
err := a.client.SendMorse(text)
58+
if err != nil {
59+
log.Printf("[ERROR] send morse: %v", err)
60+
}
61+
return nil
62+
}
63+
64+
type StopMorse struct {
65+
basicAction
66+
}
67+
68+
func NewStopMorse(context string, client RigClient, deck Deck) Action {
69+
return &StopMorse{
70+
basicAction: basicAction{
71+
context: context,
72+
client: client,
73+
deck: deck,
74+
},
75+
}
76+
}
77+
78+
func (a *StopMorse) DidReceiveSettings(payload *sdk.ReceivedEventPayload) error {
79+
a.UpdateVisual(payload)
80+
return nil
81+
}
82+
83+
func (a *StopMorse) UpdateVisual(payload *sdk.ReceivedEventPayload) error {
84+
a.deck.SetTitle(a.context, "Stop CW", sdk.HardwareAndSoftware)
85+
return nil
86+
}
87+
88+
func (a *StopMorse) KeyDown(payload *sdk.ReceivedEventPayload) error {
89+
err := a.client.StopMorse()
90+
if err != nil {
91+
log.Printf("[ERROR] stop morse: %v", err)
92+
}
93+
return nil
94+
}

0 commit comments

Comments
 (0)