Documentation
¶
Overview ¶
Package blinkstickgo provides functions to interact with the BlinkStick line of products.
Index ¶
- func Fini()
- func Init()
- type BlinkStick
- func (stk *BlinkStick) GetInfo() string
- func (stk *BlinkStick) GetLEDCount() int
- func (stk *BlinkStick) GetLEDData(count int) ([]byte, error)
- func (stk *BlinkStick) GetMode() (byte, error)
- func (stk *BlinkStick) GetName() string
- func (stk *BlinkStick) SetAllRGB(channel, r, g, b byte) error
- func (stk *BlinkStick) SetInfo(info string) error
- func (stk *BlinkStick) SetLEDData(channel byte, data []byte) error
- func (stk *BlinkStick) SetMode(mode byte) error
- func (stk *BlinkStick) SetName(name string) error
- func (stk *BlinkStick) SetRGB(channel, index, r, g, b byte) error
- func (stk *BlinkStick) SetRandom(channel, index byte) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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)
}
}
}
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) GetMode ¶
func (stk *BlinkStick) GetMode() (byte, error)
GetMode fetches the mode of the BlinkStick.
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) SetMode ¶
func (stk *BlinkStick) SetMode(mode byte) error
SetMode sets the BlinkStick to a specific mode.
The possible modes are: 0 = analog RGB, 1 = inverse, 2 = addressable multi LED, 3 = addressable mirrored multi LED. After changing the mode, wait for ~10 ms with further queries.
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.