|
| 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