Documentation ¶
Overview ¶
Package blinkygo provides utilities to control a BlinkyTape LED strip.
Index ¶
- Constants
- Variables
- type Animation
- type AnimationConfig
- type AnimationStatus
- type BlinkyTape
- func (bt *BlinkyTape) Close() error
- func (bt *BlinkyTape) IsRunning() bool
- func (bt *BlinkyTape) Pause()
- func (bt *BlinkyTape) Play(a *Animation, cfg *AnimationConfig)
- func (bt *BlinkyTape) Render() error
- func (bt *BlinkyTape) Reset() error
- func (bt *BlinkyTape) Resume()
- func (bt *BlinkyTape) SetColor(c Color) error
- func (bt *BlinkyTape) SetNextPixel(p Pixel) error
- func (bt *BlinkyTape) SetPixelAt(p *Pixel, position uint) error
- func (bt *BlinkyTape) SetPixels(p []Pixel) error
- func (bt *BlinkyTape) Status() AnimationStatus
- func (bt *BlinkyTape) Stop()
- func (bt *BlinkyTape) SwitchOff() error
- type Color
- type Frame
- type InvalidHEXColor
- type Pattern
- type Pixel
- type PixelError
- type RangeError
Constants ¶
const ( // ControlHeader is the byte sent to the led strip to render a new state. ControlHeader byte = 0xFF // AnimationDefaultDelay is the default delay to wait between two frames // of a pattern. AnimationDefaultDelay time.Duration = 75 * time.Millisecond )
const ( HEX3DigitsForm = "%1x%1x%1x" HEX6DigitsForm = "%02x%02x%02x" )
HTML hecadecimal color-string formats.
Variables ¶
var ( // ErrBusyPlaying is returned when a command that attempt to modify the // state of the LED strip is called when an animation is currently running. ErrBusyPlaying = errors.New("led strip is busy playing an animation") // ErrNoPixels is returned when a null number of pixels is used to create // a BlinkyTape instance. ErrNoPixels = errors.New("number of pixels cannot be null") // ErrEmptyBuffer is returned when an attempt to send accumulated data to the // led strip find an empty buffer. ErrEmptyBuffer = errors.New("nothing to render, the buffer is empty") // ErrWriteCtrlHeader is returned when an error occur while attempting to write // the control header at the end of the buffer. ErrWriteCtrlHeader = errors.New("couldn't write control header at the end of the buffer") // ErrOutOfRange is returned when attempting to set a pixel out of the range of // the led strip available pixels. ErrOutOfRange = errors.New("attempting to set pixel outside of range") // ErrUnknownColorName is returned when a named color is unknown. ErrUnknownColorName = errors.New("unknown color name") )
var ( RedExponent = 1.8 GreenExponent = 1.8 BlueExponent = 2.1 )
Exponents are the factors used to convert a color from the screen space to the LED space.
Functions ¶
This section is empty.
Types ¶
type Animation ¶
type Animation struct { Name string `json:"name"` Repeat int `json:"repeat"` Speed uint `json:"speed"` Pattern Pattern `json:"pattern"` }
An Animation is composed of a Pattern to play with a BlinkyTape based on a playback speed and an number of repetitions.
func NewAnimationFromFile ¶
NewAnimationFromFile create a new Animation instance from a file. The animation file must use JSON as its marshalling format.
func (Animation) SaveToFile ¶
SaveToFile marshall an Animation to JSON format and write it to a file.
type AnimationConfig ¶
type AnimationConfig struct { // Repeat indicates how many times the pattern has to be played Repeat int // Delay is the duration to wait between the rendering of two frames Delay time.Duration }
AnimationConfig represents the configuration of an Animation.
type AnimationStatus ¶
type AnimationStatus int
AnimationStatus represents the animation loop status of a BlinkyTape instance.
const ( // StatusStopped means no animation is running. StatusStopped AnimationStatus = iota // StatusRunning means an animations is being played. StatusRunning // StatusPaused means a running animation is paused. StatusPaused )
Status constants.
type BlinkyTape ¶
type BlinkyTape struct { // PixelCount is the number of pixels the LED strip was initialized with. PixelCount uint // contains filtered or unexported fields }
A BlinkyTape represents a BlinkyTape LED strip. All operations that modify the state of the strip are buffered.
func NewBlinkyTape ¶
func NewBlinkyTape(portName string, count uint) (*BlinkyTape, error)
NewBlinkyTape creates a new BlinkyTape instance. The led strip is created with all pixels set to black.
func (*BlinkyTape) IsRunning ¶
func (bt *BlinkyTape) IsRunning() bool
IsRunning returns whether or not an animation is running.
func (*BlinkyTape) Pause ¶
func (bt *BlinkyTape) Pause()
Pause pauses the animation being played on the LED strip. If there is no animation being played, do nothing.
func (*BlinkyTape) Play ¶
func (bt *BlinkyTape) Play(a *Animation, cfg *AnimationConfig)
Play plays an Animation with the LED strip. If an animation is already being played, it is stopped in favor of the new one. The animation loop can be paused, resumed or stopped at any moment, regardless its status. A negative number of repetitions will start an infinite loop.
func (*BlinkyTape) Render ¶
func (bt *BlinkyTape) Render() error
Render sends all accumulated pixel data followed by a control byte to the LED strip to render a new state. It also reset the internal buffer and reset the next position to 0.
func (*BlinkyTape) Reset ¶
func (bt *BlinkyTape) Reset() error
Reset discards any changes made to the LED strip's state.
func (*BlinkyTape) Resume ¶
func (bt *BlinkyTape) Resume()
Resume resumes a previous animation that was paused. If the animation was paused during the delay between the render of two frames, the remaining of the delay will be respected. If there is no animation to resume, do nothing.
func (*BlinkyTape) SetColor ¶
func (bt *BlinkyTape) SetColor(c Color) error
SetColor sets all pixels to the same color.
func (*BlinkyTape) SetNextPixel ¶
func (bt *BlinkyTape) SetNextPixel(p Pixel) error
SetNextPixel sets a pixel at the next position.
func (*BlinkyTape) SetPixelAt ¶
func (bt *BlinkyTape) SetPixelAt(p *Pixel, position uint) error
SetPixelAt sets a pixel at the specified position. The operation has to rewrite the whole buffer.
func (*BlinkyTape) SetPixels ¶
func (bt *BlinkyTape) SetPixels(p []Pixel) error
SetPixels sets pixels from a list.
func (*BlinkyTape) Status ¶
func (bt *BlinkyTape) Status() AnimationStatus
Status returns the animation status of the LED strip.
func (*BlinkyTape) Stop ¶
func (bt *BlinkyTape) Stop()
Stop stops the animation being played on the LED strip. A stop can occur at any moment between the render of two frames regardless the delay, or during a pause. If there is no animation being played or paused, do nothing.
func (*BlinkyTape) SwitchOff ¶
func (bt *BlinkyTape) SwitchOff() error
SwitchOff switches off the LED strip. This actually set the color to black for all pixels and calls Render().
type Color ¶
A Color represents a color.
func NewHEXColor ¶
NewHEXColor returns a new color parsed from its "html" hex color-string format, either in the 3 "#F06" or 6 "#FF0066" digits form. First char '#' is optional.
func NewNamedColor ¶
NewNamedColor returns a new color from its name. Supported names are from the package "colornames", see https://godoc.org/golang.org/x/image/colornames
func NewRGBColor ¶
NewRGBColor returns a new Color from its RGB representation.
type InvalidHEXColor ¶
type InvalidHEXColor struct {
// contains filtered or unexported fields
}
InvalidHEXColor describes an error related to an HTML hex-color parsing.
func (InvalidHEXColor) Error ¶
func (e InvalidHEXColor) Error() string
type Pattern ¶
type Pattern []Frame
A Pattern represents a list of frames.
func NewPatternFromArduinoExport ¶
NewPatternFromArduinoExport returns a new pattern created from an Arduino C header file exported from PatternPaint.
type Pixel ¶
type Pixel struct {
Color Color `json:"color"`
}
A Pixel represents a led of the strip.
type PixelError ¶
PixelError describes an error related to a pixel command. It provides a copy of the pixel, and its position inside the LED strip's pixels range.
func (PixelError) Error ¶
func (e PixelError) Error() string
type RangeError ¶
RangeError describes an error related to a range excess. It provides the position that caused the error, and the max range of the led strip's pixels.
func (RangeError) Error ¶
func (e RangeError) Error() string