nrzled

package
v3.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOpts = Opts{
	NumPixels: 150,
	Channels:  3,
	Freq:      800 * physic.KiloHertz,
}

DefaultOpts is the recommended default options.

Functions

func NRZ

func NRZ(b byte) uint32

NRZ converts a byte into the MSB-first Non-Return-to-Zero encoded 24 bits.

The upper 8 bits are zeros and shall be ignored.

The Non-return-to-zero protocol is a self-clocking signal that enables one-way communication without the need of a dedicated clock signal, unlike SPI driven LEDs like the apa102.

See https://en.wikipedia.org/wiki/Non-return-to-zero for more technical details.

Types

type Dev

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

Dev is a handle to the LED strip.

func New

func New(p gpiostream.PinOut, opts *Opts) (*Dev, error)

New opens a handle to a compatible LED strip.

func (*Dev) Bounds

func (d *Dev) Bounds() image.Rectangle

Bounds implements display.Drawer. Min is guaranteed to be {0, 0}.

func (*Dev) ColorModel

func (d *Dev) ColorModel() color.Model

ColorModel implements display.Drawer.

It is color.NRGBAModel.

func (*Dev) Draw

func (d *Dev) Draw(r image.Rectangle, src image.Image, sp image.Point) error

Draw implements display.Drawer.

Using something else than image.NRGBA is 10x slower and is not recommended. When using image.NRGBA, the alpha channel is ignored in RGB mode and used as White channel in RGBW mode.

A back buffer is kept so that partial updates are supported, albeit the full LED strip is updated synchronously.

func (*Dev) Halt

func (d *Dev) Halt() error

Halt turns the lights off.

It doesn't affect the back buffer.

func (*Dev) String

func (d *Dev) String() string

func (*Dev) Write

func (d *Dev) Write(pixels []byte) (int, error)

Write accepts a stream of raw RGB/RGBW pixels and sends it as NRZ encoded stream.

This bypasses the back buffer.

type Opts

type Opts struct {
	// NumPixels is the number of pixels to control. If too short, the following
	// pixels will be corrupted. If too long, the pixels will be drawn
	// unnecessarily but not visible issue will occur.
	NumPixels int
	// Channels is 1 for single color LEDs, 3 for RGB LEDs and 4 for RGBW (white)
	// LEDs.
	Channels int
	// Freq is the frequency to use to drive the LEDs. It should be either 800kHz
	// for fast ICs and 400kHz for the slow ones.
	Freq physic.Frequency
}

Opts defines the options for the device.

type SPIDev

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

SPIDev represents a strip of WS2812b LEDs as a strip connected over a SPI port. It accepts a stream of raw RGB pixels and converts it to a bit pattern consistent with the WS812b protocol. Includes intensity and temperature correction.

func NewSPI

func NewSPI(p spi.Port, o *Opts) (*SPIDev, error)

NewSPI returns a strip that communicates over SPI to NRZ encoded LEDs.

Due to the tight timing demands of these LEDs, the SPI port speed must be a reliable 2.5MHz

Note that your SPI buffer should be at least 12*num_pixels+2 bytes long

func (*SPIDev) Bounds

func (d *SPIDev) Bounds() image.Rectangle

Bounds implements display.Drawer. Min is guaranteed to be {0, 0}.

func (*SPIDev) ColorModel

func (d *SPIDev) ColorModel() color.Model

ColorModel implements display.Drawer. There's no surprise, it is color.NRGBAModel.

func (*SPIDev) Draw

func (d *SPIDev) Draw(r image.Rectangle, src image.Image, sp image.Point) error

Draw implements display.Drawer.

Using something else than image.NRGBA is 10x slower. When using image.NRGBA, the alpha channel is ignored.

func (*SPIDev) Halt

func (d *SPIDev) Halt() error

Halt turns off all the lights.

func (*SPIDev) String

func (d *SPIDev) String() string

func (*SPIDev) Write

func (d *SPIDev) Write(pixels []byte) (int, error)

Write accepts a stream of raw RGB pixels and sends it as WS2812b encoded stream.

type Strip

type Strip interface {
	display.Drawer
	Write(pixels []byte) (int, error)
}

A Strip is the high level interface all hardware implementations conform to

Jump to

Keyboard shortcuts

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