From afaa02f8b2ab2391cce23afb5e24e3fd35f61068 Mon Sep 17 00:00:00 2001 From: Daniel Prows Date: Tue, 8 Aug 2023 15:34:37 -0600 Subject: [PATCH] adding support for stream deck plus --- action.go | 2 +- client.go | 11 ++++- constants.go | 6 +++ event.go | 8 +++- examples/counter/main.go | 2 +- examples/cpu/main.go | 4 +- go.mod | 5 +++ go.sum | 2 + payloads.go | 93 ++++++++++++++++++++++++++-------------- 9 files changed, 94 insertions(+), 39 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/action.go b/action.go index 5b7e2a7..be1374b 100644 --- a/action.go +++ b/action.go @@ -3,7 +3,7 @@ package streamdeck import ( "context" - sdcontext "github.com/samwho/streamdeck/context" + sdcontext "code.encyclopediaofdaniel.com/dlprows/streamdeck-sdk/context" ) type Action struct { diff --git a/client.go b/client.go index 94a1aa0..11b31b4 100644 --- a/client.go +++ b/client.go @@ -12,8 +12,8 @@ import ( "sync" "time" + sdcontext "code.encyclopediaofdaniel.com/dlprows/streamdeck-sdk/context" "github.com/gorilla/websocket" - sdcontext "github.com/samwho/streamdeck/context" ) var ( @@ -180,6 +180,15 @@ func (client *Client) SetImage(ctx context.Context, base64image string, target T return client.send(NewEvent(ctx, SetImage, SetImagePayload{Base64Image: base64image, Target: target})) } +func (client *Client) SetFeedback(ctx context.Context, payload any) error { + return client.send(NewEvent(ctx, SetFeedback, payload)) +} + +// SetFeedbackLayout +func (client *Client) SetFeedbackLayout(ctx context.Context, layout string) error { + return client.send(NewEvent(ctx, SetImage, SetFeedbackLayoutPayload{Layout: layout})) +} + func (client *Client) ShowAlert(ctx context.Context) error { return client.send(NewEvent(ctx, ShowAlert, nil)) } diff --git a/constants.go b/constants.go index d70e044..729b74f 100644 --- a/constants.go +++ b/constants.go @@ -5,6 +5,10 @@ const ( DidReceiveGlobalSettings = "didReceiveGlobalSettings" KeyDown = "keyDown" KeyUp = "keyUp" + TouchTap = "touchTap" + DialDown = "dialDown" + DialUp = "dialUp" + DialRotate = "dialRotate" WillAppear = "willAppear" WillDisappear = "willDisappear" TitleParametersDidChange = "titleParametersDidChange" @@ -26,6 +30,8 @@ const ( LogMessage = "logMessage" SetTitle = "setTitle" SetImage = "setImage" + SetFeedback = "setFeedback" + SetFeedbackLayout = "setFeedbackLayout" ShowAlert = "showAlert" ShowOk = "showOk" SetState = "setState" diff --git a/event.go b/event.go index 23a77ec..bf49665 100644 --- a/event.go +++ b/event.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" - sdcontext "github.com/samwho/streamdeck/context" + sdcontext "code.encyclopediaofdaniel.com/dlprows/streamdeck-sdk/context" ) type Event struct { @@ -35,9 +35,13 @@ const ( StreamDeckMini DeviceType = 1 StreamDeckXL DeviceType = 2 StreamDeckMobile DeviceType = 3 + CorsairGKeys DeviceType = 4 + StreamDeckPedal DeviceType = 5 + CorsairVoyager DeviceType = 6 + StreamDeckPlus DeviceType = 7 ) -func NewEvent(ctx context.Context, name string, payload interface{}) Event { +func NewEvent(ctx context.Context, name string, payload any) Event { p, err := json.Marshal(payload) if err != nil { panic(err) diff --git a/examples/counter/main.go b/examples/counter/main.go index 1746d76..6cecc51 100644 --- a/examples/counter/main.go +++ b/examples/counter/main.go @@ -11,7 +11,7 @@ import ( "os" "strconv" - "github.com/samwho/streamdeck" + "code.encyclopediaofdaniel.com/dlprows/streamdeck-sdk" ) type Settings struct { diff --git a/examples/cpu/main.go b/examples/cpu/main.go index ca8806b..f5e515d 100644 --- a/examples/cpu/main.go +++ b/examples/cpu/main.go @@ -11,8 +11,8 @@ import ( "os" "time" - "github.com/samwho/streamdeck" - sdcontext "github.com/samwho/streamdeck/context" + "code.encyclopediaofdaniel.com/dlprows/streamdeck-sdk" + sdcontext "code.encyclopediaofdaniel.com/dlprows/streamdeck-sdk/context" "github.com/shirou/gopsutil/cpu" ) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..801e549 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module code.encyclopediaofdaniel.com/dlprows/streamdeck-sdk + +go 1.20 + +require github.com/gorilla/websocket v1.5.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e5a03d4 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= diff --git a/payloads.go b/payloads.go index 91033e8..c424502 100644 --- a/payloads.go +++ b/payloads.go @@ -1,7 +1,5 @@ package streamdeck -import "encoding/json" - type LogMessagePayload struct { Message string `json:"message"` } @@ -28,10 +26,14 @@ type SwitchProfilePayload struct { Profile string `json:"profile"` } -type DidReceiveSettingsPayload struct { - Settings json.RawMessage `json:"settings,omitempty"` - Coordinates Coordinates `json:"coordinates,omitempty"` - IsInMultiAction bool `json:"isInMultiAction,omitempty"` +type SetFeedbackLayoutPayload struct { + Layout string `json:"layout"` +} + +type DidReceiveSettingsPayload[T any] struct { + Settings T `json:"settings,omitempty"` + Coordinates Coordinates `json:"coordinates,omitempty"` + IsInMultiAction bool `json:"isInMultiAction,omitempty"` } type Coordinates struct { @@ -39,42 +41,69 @@ type Coordinates struct { Row int `json:"row,omitempty"` } -type DidReceiveGlobalSettingsPayload struct { - Settings json.RawMessage `json:"settings,omitempty"` +type DidReceiveGlobalSettingsPayload[T any] struct { + Settings T `json:"settings,omitempty"` } -type KeyDownPayload struct { - Settings json.RawMessage `json:"settings,omitempty"` - Coordinates Coordinates `json:"coordinates,omitempty"` - State int `json:"state,omitempty"` - UserDesiredState int `json:"userDesiredState,omitempty"` - IsInMultiAction bool `json:"isInMultiAction,omitempty"` +type KeyDownPayload[T any] struct { + Settings T `json:"settings,omitempty"` + Coordinates Coordinates `json:"coordinates,omitempty"` + State int `json:"state,omitempty"` + UserDesiredState int `json:"userDesiredState,omitempty"` + IsInMultiAction bool `json:"isInMultiAction,omitempty"` } -type KeyUpPayload struct { - Settings json.RawMessage `json:"settings,omitempty"` - Coordinates Coordinates `json:"coordinates,omitempty"` - State int `json:"state,omitempty"` - UserDesiredState int `json:"userDesiredState,omitempty"` - IsInMultiAction bool `json:"isInMultiAction,omitempty"` +type KeyUpPayload[T any] struct { + Settings T `json:"settings,omitempty"` + Coordinates Coordinates `json:"coordinates,omitempty"` + State int `json:"state,omitempty"` + UserDesiredState int `json:"userDesiredState,omitempty"` + IsInMultiAction bool `json:"isInMultiAction,omitempty"` } -type WillAppearPayload struct { - Settings json.RawMessage `json:"settings,omitempty"` - Coordinates Coordinates `json:"coordinates,omitempty"` - State int `json:"state,omitempty"` - IsInMultiAction bool `json:"isInMultiAction,omitempty"` +// TouchTapPayload A json object +type TouchTapPayload[T any] struct { + Settings T `json:"settings,omitempty"` + Coordinates Coordinates `json:"coordinates,omitempty"` + TapPos [2]int `json:"tapPos,omitempty"` + Hold bool `json:"hold,omitempty"` } -type WillDisappearPayload struct { - Settings json.RawMessage `json:"settings,omitempty"` - Coordinates Coordinates `json:"coordinates,omitempty"` - State int `json:"state,omitempty"` - IsInMultiAction bool `json:"isInMultiAction,omitempty"` +type DialDownPayload[T any] struct { + Settings T `json:"settings,omitempty"` + Coordinates Coordinates `json:"coordinates,omitempty"` + Controller string `json:"controller,omitempty"` } -type TitleParametersDidChangePayload struct { - Settings json.RawMessage `json:"settings,omitempty"` +type DialUpPayload[T any] struct { + Settings T `json:"settings,omitempty"` + Coordinates Coordinates `json:"coordinates,omitempty"` + Controller string `json:"controller,omitempty"` +} + +type DialRotatePayload[T any] struct { + Settings T `json:"settings,omitempty"` + Coordinates Coordinates `json:"coordinates,omitempty"` + Ticks int `json:"ticks,omitempty"` + Pressed bool `json:"pressed,omitempty"` +} + +type WillAppearPayload[T any] struct { + Settings T `json:"settings,omitempty"` + Coordinates Coordinates `json:"coordinates,omitempty"` + State int `json:"state,omitempty"` + IsInMultiAction bool `json:"isInMultiAction,omitempty"` +} + +type WillDisappearPayload[T any] struct { + Settings T `json:"settings,omitempty"` + Coordinates Coordinates `json:"coordinates,omitempty"` + State int `json:"state,omitempty"` + IsInMultiAction bool `json:"isInMultiAction,omitempty"` +} + +type TitleParametersDidChangePayload[T any] struct { + Settings T `json:"settings,omitempty"` Coordinates Coordinates `json:"coordinates,omitempty"` State int `json:"state,omitempty"` Title string `json:"title,omitempty"`