Skip to content

Commit de283e1

Browse files
committed
Starting to use the new device type
1 parent 0cb85a3 commit de283e1

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

comms.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ func rawOpen(reset bool) (*Device, error) {
8383
return retval, nil
8484
}
8585

86+
// GetName returns the name of the type of Streamdeck
87+
func (d *Device) GetName() string {
88+
return d.deviceType.name
89+
}
90+
8691
// Close the device
8792
func (d *Device) Close() {
8893
d.fd.Close()
@@ -160,7 +165,7 @@ func (d *Device) ButtonPress(f func(int, *Device, error)) {
160165

161166
// ResetComms will reset the comms protocol to the StreamDeck; useful if things have gotten de-synced, but it will also reboot the StreamDeck
162167
func (d *Device) ResetComms() {
163-
payload := []byte{'\x03', '\x02'}
168+
payload := d.deviceType.resetPacket
164169
d.fd.SendFeatureReport(payload)
165170
}
166171

@@ -213,7 +218,7 @@ func (d *Device) rawWriteToButton(btnIndex int, rawImage []byte) error {
213218
bytesRemaining = bytesRemaining - thisLength
214219
pageNumber = pageNumber + 1
215220
if pageNumber >= len(payloads) {
216-
return errors.New("Image too big for button, aborting. You probably need to reset the Streamdeck at this stage, and modify the size of `payloads` on line 142 to be something bigger.")
221+
return errors.New("Image too big for button comms, aborting - you probably need to reset the Streamdeck at this stage, and modify the size of `payloads` on line 142 to be something bigger")
217222
}
218223
}
219224
return nil

examples/client/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"image/color"
56
"time"
67

@@ -16,6 +17,7 @@ func main() {
1617
if err != nil {
1718
panic(err)
1819
}
20+
fmt.Printf("Found device [%s]\n", sd.GetName())
1921

2022
myButton := buttons.NewTextButton("Hi world")
2123
myButton.SetActionHandler(&actionhandlers.TextPrintAction{Label: "You pressed me"})

examples/test/test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package main
22

33
import (
4+
"fmt"
45
"image/color"
56
"sync"
67

78
streamdeck "github.com/magicmonkey/go-streamdeck"
9+
_ "github.com/magicmonkey/go-streamdeck/devices"
810
)
911

1012
func main() {
1113
sd, err := streamdeck.Open()
1214
if err != nil {
1315
panic(err)
1416
}
17+
fmt.Printf("Found device [%s]\n", sd.GetName())
18+
1519
sd.ClearButtons()
1620

1721
sd.SetBrightness(50)

streamdeck.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ func New() (*StreamDeck, error) {
4747
return sd, nil
4848
}
4949

50+
// GetName returns the name of the type of Streamdeck
51+
func (sd *StreamDeck) GetName() string {
52+
return sd.dev.deviceType.name
53+
}
54+
5055
// AddButton adds a `Button` object to the StreamDeck at the specified index
5156
func (sd *StreamDeck) AddButton(btnIndex int, b Button) {
5257
b.RegisterUpdateHandler(sd.ButtonUpdateHandler)

0 commit comments

Comments
 (0)