Giter Club home page Giter Club logo

go-streamdeck's Introduction

Go Streamdeck

A Go interface to an Elgato Streamdeck (currently works with the 32-button XL only because that's what I have).

GoDoc

Designed for and tested with Ubuntu, Go 1.13+ and a Streamdeck XL. Images are the wrong size for other streamdecks; bug reports and patches are welcome!

Installation

Either include the library in your project or install it with the following command:

go get github.com/magicmonkey/go-streamdeck

On Linux, you might also need to add some udev rules. Put this into /etc/udev/rules.d/99-streamdeck.rules:

SUBSYSTEM=="usb", ATTRS{idVendor}=="0fd9", ATTRS{idProduct}=="0060", MODE:="666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fd9", ATTRS{idProduct}=="0063", MODE:="666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fd9", ATTRS{idProduct}=="006c", MODE:="666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fd9", ATTRS{idProduct}=="006d", MODE:="666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fd9", ATTRS{idProduct}=="0080", MODE:="666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fd9", ATTRS{idProduct}=="0090", MODE:="666"

Usage

There are 2 ways to use this: the low-level "comms-oriented" interface (using streamdeck.Open) which wraps the USB HID protocol, or the higher-level "button-oriented" interface (using streamdeck.New) which represents buttons and actions.

If you want to implement your own actions, I suggest that you either instantiate a CustomAction or alternatively implement the ButtonActionHandler interface (basing your code on the CustomAction).

Example high-level usage

High level usage gives some helpers to set up buttons. This example has a few things to look at:

  • A button in position 2 that says "Hi world" and prints to the console when pressed

  • A button in position 7 displaying the number 7 - changes to number 8 when pressed.

  • A yellow button in position 26

  • A purple button in position 27, it changes colour and prints to the console when pressed.

import (
	"image/color"
	"time"

	streamdeck "github.com/magicmonkey/go-streamdeck"
	"github.com/magicmonkey/go-streamdeck/actionhandlers"
	"github.com/magicmonkey/go-streamdeck/buttons"
	_ "github.com/magicmonkey/go-streamdeck/devices"
)

func main() {
	sd, err := streamdeck.New()
	if err != nil {
		panic(err)
	}

	// A simple yellow button in position 26
	cButton := buttons.NewColourButton(color.RGBA{255, 255, 0, 255})
	sd.AddButton(26, cButton)

	// A button with text on it in position 2, which echoes to the console when presesd
	myButton := buttons.NewTextButton("Hi world")
	myButton.SetActionHandler(&actionhandlers.TextPrintAction{Label: "You pressed me"})
	sd.AddButton(2, myButton)

	// A button with text on it which changes when pressed
	myNextButton := buttons.NewTextButton("7")
	myNextButton.SetActionHandler(&actionhandlers.TextLabelChangeAction{NewLabel: "8"})
	sd.AddButton(7, myNextButton)

	// A button which performs multiple actions when pressed
	multiActionButton := buttons.NewColourButton(color.RGBA{255, 0, 255, 255})
	thisActionHandler := &actionhandlers.ChainedAction{}
	thisActionHandler.AddAction(&actionhandlers.TextPrintAction{Label: "Purple press"})
	thisActionHandler.AddAction(&actionhandlers.ColourChangeAction{NewColour: color.RGBA{255, 0, 0, 255}})
	multiActionButton.SetActionHandler(thisActionHandler)
	sd.AddButton(27, multiActionButton)

	time.Sleep(20 * time.Second)
}

The program runs for 20 seconds and then exits.

Example low-level usage

The low-level usage gives more control over the operations of the streamdeck and buttons.

This example shows an image on any pressed button, updating each time another button is pressed.

import streamdeck "github.com/magicmonkey/go-streamdeck"

func main() {
	sd, err := streamdeck.Open()
	if err != nil {
		panic(err)
	}
	sd.ClearButtons()

	sd.SetBrightness(50)

	sd.ButtonPress(func(btnIndex int, sd *streamdeck.Device, err error) {
		if err != nil {
			panic(err)
		}
		sd.ClearButtons()
		sd.WriteImageToButton("play.jpg", btnIndex)
	})

	time.Sleep(20 * time.Second)

}

The program runs for 20 seconds and then exits.

Showcase

Projects using this library (pull request to add yours!)

Contributions

This is a very new project but all feedback, comments, questions and patches are more than welcome. Please get in touch by opening an issue, it would be good to hear who is using the project and how things are going.

For more, see CONTRIBUTING.md.

go-streamdeck's People

Contributors

derickr avatar dhollinger avatar fabianexe avatar juwit avatar lornajane avatar magicmonkey avatar s00500 avatar tuomaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

go-streamdeck's Issues

[BUG] Images not scaled exactly to 80x80 pixels, Stream Deck Mini will not display

Describe the bug
When using an image larger than the Stream Deck mini's key size (80x80), then the image doesn't apply

Streamdeck version
Mini (6 buttons)

To Reproduce

Create new Image File Button and launch the go program

func (s *Screenshot) Buttons() {
    // Command
    myButton, err := buttons.NewImageFileButton(viper.GetString("buttons.images") + "/screenshot.png")
    if err != nil {
        log.Error().Err(err).Msg("Could not load image")
    }

    shotaction := &sdactionhandlers.CustomAction{}
    shotaction.SetHandler(func(btn streamdeck.Button) {
        go takeScreenshot()
    })
    myButton.SetActionHandler(shotaction)
    s.SD.AddButton(s.ButtonId, myButton)
}

Expected behavior
Image should resize, rotate, and display regardless of size.

Environment (please complete the following information):

  • OS: Pop!_OS 20.10
  • Go version: 1.14.13 (from ASDF)

[BUG] Border decorator only works for the XL

Describe the bug
There's a hard-coded "96" in the border decorator code

Streamdeck version
Anything except an XL

Additional context
This needs to look at the dimensions of the incoming image, rather than looking up what streamdeck is in use.

Reset the USB HID comms on Open()

The comms can get into a "de-sync'd" state, if a bad message is sent, which leaves the streamdeck in a non-responsive mode and all the comms is slow as it waits for an end to a half-done packet. There's a "reset" packet which can be sent, which should be used (at least) every time it's Open()'d and possibly periodically in between times, just in case.

Error handling on missing images

When I give an invalid file name to an image, the whole program stops. Can we use a default image or something in this situation?

Make a way to detach the button callback

Registering a button callback means that the Go program will never end. Either allow it to be detached, or alternatively make it based on channels so it becomes a concern for the calling code.

Either way, calling the Close() method should shut it down.

[BUG] sd.UnsetDecorator doesn't work for imagefile buttons

Describe the bug
I'm using SetDecorator and UnsetDecorator on my streamdeck buttons. This works perfectly for a text button but doesn't undecorate the ImageFileButton ones. No error, just the decorator persists.

Streamdeck version
XL (32 buttons)

To Reproduce
Add one ImageFileButton and one TextButton, have them turn decorators on and off. The Text one works, but the image one doesn't

Expected behavior
I expected UnsetDecorator to undecorate on an image button as well as on a text one.

Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Go version: go version go1.14.3 linux/amd64

Additional context
Add any other context about the problem here.

[BUG] Can't remove a decorator

Describe the bug
After you set a decorator on a button, you can't unset it.

Streamdeck version
All versions

To Reproduce
Add a decorator to a button, then try to remove it. There is no interface for it.

[BUG] Contributing guidelines

Need contributing guidelines, whether for code, testing, feature requests, suggestions, pointers to usage by other projects, etc.

Support multiple button press listeners

Currently the code will only support 1 listener as the USB comms is inside of the listener loop and only 1 thing can do that. Needs the listening code separating from the call-the-callbacks code.

Word-wrap text

Currently text draws on a single line. Would be good to word-wrap it, although as it isn't a fixed-width font, this will involve some tricky maths.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.