blinkstickgo

package module
v0.0.0-...-ec3bebe Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 License: MPL-2.0 Imports: 5 Imported by: 0

README

blinkstickgo

A libusb-based Go package for controlling the BlinkStick line of products

Currently, this package has only been tested on Linux, but theoretically it might work on your system, too.

Installation

blinkstickgo only depends on gousb. But installing gousb requires that you have the headers for libusb on your system.

Linux users, it's pretty straightforward, just install your distro's libusb-dev package.
For macOS, seems like you have a few gotchas you may have to deal with.
Windows users, you're going to need MINGW and I wish you luck.

After you get that sorted out, just go get github.com/different55/blinkstickgo.

Documentation

Documentation is available over on godoc.org.

Basic Example

Turning all connected LEDs to white.

blinkstickgo.Init()
defer blinkstickgo.Fini()

sticks, err := blinkstickgo.FindAll()
if err != nil {
	panic(err)
} else if len(sticks) == 0 {
	panic("No connected BlinkStick devices")
}

for _, stick := range sticks {
	count := stick.GetLEDCount()
	if count < 1 { // The Pros report their count as -1
		err := stick.SetRGB(0, 0, 255, 255, 255)
		if err != nil {
			panic(err)
		}
	} else {
		err := stick.SetAllRGB(0, 255, 255, 255)
		if err != nil {
			panic(err)
		}
	}
}

Documentation

Overview

Package blinkstickgo provides functions to interact with the BlinkStick line of products.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fini

func Fini()

Fini closes the USB context.

func Init

func Init()

Init initializes the USB library.

Types

type BlinkStick

type BlinkStick struct {
	Device  *gousb.Device
	Serial  string
	Inverse bool
	RGB     bool // Currently unimplemented, will be true if the strip uses RGB format instead of the default GRB.
	// contains filtered or unexported fields
}

The BlinkStick struct represents an individual BlinkStick device.

Example

Basic usage, setting all LEDs white

Init()
defer Fini()

sticks, err := FindAll()
if err != nil {
	panic(err)
} else if len(sticks) == 0 {
	panic("No connected BlinkStick devices for testing")
}

for _, stick := range sticks {
	count := stick.GetLEDCount()
	if count < 1 { // The Pros report their count as -1
		err := stick.SetRGB(0, 0, 255, 255, 255)
		if err != nil {
			panic(err)
		}
	} else {
		err := stick.SetAllRGB(0, 255, 255, 255)
		if err != nil {
			panic(err)
		}
	}
}
Output:

func FindAll

func FindAll() ([]BlinkStick, error)

FindAll detects and returns all BlinkSticks connected to the system.

func (*BlinkStick) GetInfo

func (stk *BlinkStick) GetInfo() string

GetInfo returns a string of data from info block two.

func (*BlinkStick) GetLEDCount

func (stk *BlinkStick) GetLEDCount() int

GetLEDCount returns the number of LEDs for supported devices.

func (*BlinkStick) GetLEDData

func (stk *BlinkStick) GetLEDData(count int) ([]byte, error)

GetLEDData retrieves the LED data from the device.

func (*BlinkStick) GetName

func (stk *BlinkStick) GetName() string

GetName returns the name of the device.

func (*BlinkStick) SetAllRGB

func (stk *BlinkStick) SetAllRGB(channel, r, g, b byte) error

SetAllRGB sends a color to all LEDs on a channel in RGB format.

func (*BlinkStick) SetInfo

func (stk *BlinkStick) SetInfo(info string) error

SetInfo writes a new block of data to info block two.

If you're worried about extreme longevity, use sparingly. I hear this stuff can only withstand so many writes.

func (*BlinkStick) SetLEDData

func (stk *BlinkStick) SetLEDData(channel byte, data []byte) error

SetLEDData updates the entire stick with a slice of alternating RGB values.

func (*BlinkStick) SetName

func (stk *BlinkStick) SetName(name string) error

SetName writes a new name for the device to info block one.

If you're worried about extreme longevity, use sparingly. I hear this stuff can only withstand so many writes.

func (*BlinkStick) SetRGB

func (stk *BlinkStick) SetRGB(channel, index, r, g, b byte) error

SetRGB sets one LED to a color in RGB format.

func (*BlinkStick) SetRandom

func (stk *BlinkStick) SetRandom(channel, index byte) error

SetRandom sets one LED to a random color.

Jump to

Keyboard shortcuts

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