streamdeck

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2022 License: MIT Imports: 9 Imported by: 0

README

go.streamdeck

Go Reference gopherbadger-tag-do-not-edit

Go library for using Elgato Streamdeck devices

  • No Cgo
  • Native Windows support
  • Linux wrapper provided (uses github.com/karalabe/hid)

Compatible devices

While the library should in theory support all known Streamdeck devices it has only been tested with Streamdeck XL.
Other devices using API v2 likely work without issues, but older devices using API v1 might have issues as they use different image format and haven't been confirmed to work.

If you happen to own a non-XL device I'd appreciate if you could send a report to let me know if the device works as expected (please include OS and product ID of the device). Testers with original Streamdeck (pid: 0x0060) or either version of Streamdeck Mini (pids: 0x0063 or 0x0090) would be especially useful as those devices are using API v1.

Usage

package main

import (
	"image"
	"log"
	"time"

	streamdeck "git.sr.ht/~errnoh/go.streamdeck"
)

func main() {
	devices := streamdeck.Devices()

	if len(devices) > 0 {
		dev := devices[0]
		if err := dev.Open(); err != nil {
			log.Fatal(err)
		}

		dev.SetImage(2, image.White)

		c := dev.Events()
		end := time.After(time.Second * 3)
		for {
			select {
			case <-end:
				dev.Reset()
				dev.Close()
			case e, ok := <-c:
				if !ok {
					return
				}
				if e.Pressed {
					dev.SetImage(e.Index, image.White)
				}
			}
		}
	} else {
		log.Println("No Streamdeck devices found")
	}
}

Issues & Contributing

Contributions are welcome, especially for additional wrappers and reports about device compatibility.

(You can participate easily by sending an email to address listed on either page)

NOTES

Documentation

Index

Constants

View Source
const (
	VendorId = 0x0fd9
)

Variables

View Source
var (
	APIv1 = APIspec{
			// contains filtered or unexported fields
	}
	APIv2 = APIspec{
			// contains filtered or unexported fields
	}
)
View Source
var (
	Original = DeviceType{
		APIspec:      APIv1,
		PacketLength: 8191,

		ProductName: "Streamdeck",
		Columns:     5,
		Rows:        3,
		IconSize:    72,
		// contains filtered or unexported fields
	}
	OriginalV2 = DeviceType{
		APIspec:      APIv2,
		PacketLength: 1024,

		ProductName: "Streamdeck",
		Columns:     5,
		Rows:        3,
		IconSize:    72,
		// contains filtered or unexported fields
	}
	OriginalMk2 = DeviceType{
		APIspec:      APIv2,
		PacketLength: 1024,

		ProductName: "Streamdeck Mk2",
		Columns:     5,
		Rows:        3,
		IconSize:    72,
		// contains filtered or unexported fields
	}
	XL = DeviceType{
		APIspec:      APIv2,
		PacketLength: 1024,

		ProductName: "Streamdeck XL",
		Columns:     8,
		Rows:        4,
		IconSize:    96,
		// contains filtered or unexported fields
	}
	Mini = DeviceType{
		APIspec:      APIv1,
		PacketLength: 1024,

		ProductName: "Streamdeck Mini",
		Columns:     3,
		Rows:        2,
		IconSize:    80,
		// contains filtered or unexported fields
	}
	MiniV2 = DeviceType{
		APIspec:      APIv1,
		PacketLength: 1024,

		ProductName: "Streamdeck Mini",
		Columns:     3,
		Rows:        2,
		IconSize:    80,
		// contains filtered or unexported fields
	}
)
View Source
var DeviceFunc func() []HIDDevice = func() []HIDDevice {
	log.Fatal("DeviceFunc is not set for this platform")
	return nil
}

DeviceFunc is any function that returns a slice of devices that satisfy HIDDevice interface. Any custom wrapper should set this function to a compatible function before calling .Devices() Devices should be returned in closed state.

Functions

This section is empty.

Types

type APIspec

type APIspec struct {
	// contains filtered or unexported fields
}

type ButtonEvent

type ButtonEvent struct {
	Index   byte
	Pressed bool
}

ButtonEvent holds information about which button state changed and if the button was pressed down (true) or if it released (false).

type Device

type Device struct {
	HIDDevice
	DeviceType
}

Device represents single Elgato Streamdeck device

device.Open() should be called before attempting to use the device and device.Close() after device is no longer being used.

func Devices

func Devices() (devices []Device)

Devices returns slice of supported Elgato Streamdeck devices. device.Open() should be called before attempting to use the device

func (Device) Brightness

func (d Device) Brightness(level byte) (err error)

Brightness sets the brightness level (between 0 and 100) of the device. Setting brightness to 0 shuts down the display.

func (Device) Events

func (d Device) Events() <-chan ButtonEvent

Events returns a channel that forwards button press events from the device. Channel will close itself when device.Close() is called.

Listener should drain the channel before shutting down.

func (Device) Firmware

func (d Device) Firmware() (s string, err error)

Firmware returns the firmware version of the device.

func (Device) Reset

func (d Device) Reset() (err error)

Reset clears the device screen to show the default logo.

func (Device) Serial

func (d Device) Serial() (s string, err error)

Serial returns the serial number of the device.

func (Device) SetImage

func (d Device) SetImage(buttonIndex byte, img image.Image) (err error)

SetImage sets image to button at the specified index.

type DeviceType

type DeviceType struct {
	APIspec
	PacketLength uint16

	ProductName string
	Columns     int
	Rows        int
	IconSize    int
	// contains filtered or unexported fields
}

type HIDDevice

type HIDDevice interface {
	ProductId() uint16

	Open() error
	Close()

	Write(p []byte) (n int, err error)
	Read(p []byte) (n int, err error)
	SendFeatureReport(data []byte) (n int, err error)
	GetFeatureReport(data []byte) (n int, err error)
}

type ImageFormat

type ImageFormat func(w io.Writer, m image.Image) error

ImageFormat defines an encounter function that writes encoded image to the writer `w`

Directories

Path Synopsis
wrapper

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL