Skip to content

Commit

Permalink
Add -device flag, to enforce connecting to a device with a specific s…
Browse files Browse the repository at this point in the history
…erial
  • Loading branch information
muesli committed Jun 8, 2021
1 parent dd855b9 commit d06d32a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
recentWindows []Window

deckFile = flag.String("deck", "deckmaster.deck", "path to deck config file")
device = flag.String("device", "", "which device to use (serial number)")
brightness = flag.Uint("brightness", 80, "brightness in percent")
)

Expand Down Expand Up @@ -116,7 +117,25 @@ func initDevice() (*streamdeck.Device, error) {
if len(d) == 0 {
return nil, fmt.Errorf("no Stream Deck devices found")
}

dev := d[0]
if len(*device) > 0 {
found := false
for _, v := range d {
if v.Serial == *device {
dev = v
found = true
break
}
}
if !found {
log.Println("can't find device. Available devices:")
for _, v := range d {
log.Printf("Serial %s (%d buttons)\n", v.Serial, v.Columns*v.Rows)
}
os.Exit(1)
}
}

if err := dev.Open(); err != nil {
return nil, err
Expand All @@ -125,8 +144,8 @@ func initDevice() (*streamdeck.Device, error) {
if err != nil {
return nil, err
}
log.Printf("Found device with serial %s (firmware %s)\n",
dev.Serial, ver)
log.Printf("Found device with serial %s (%d buttons, firmware %s)\n",
dev.Serial, dev.Columns*dev.Rows, ver)

if err := dev.Reset(); err != nil {
return nil, err
Expand Down

0 comments on commit d06d32a

Please sign in to comment.