apa102

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2017 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package apa102 drives a strip of APA102 LEDs connected on a SPI port.

These devices are interesting because they have 2 PWMs: one global of 5 bits of resolution and one per channel of 8 bits of resolution. This means that the dynamic range is of 13 bits.

This driver handles color intensity and temperature correction and uses the full near 8000:1 dynamic range as supported by the device.

Datasheet

https://cpldcpu.files.wordpress.com/2014/08/apa-102c-super-led-specifications-2014-en.pdf

Example
s, err := spireg.Open("")
if err != nil {
	log.Fatalf("failed to open SPI: %v", err)
}
defer s.Close()
// Opens a strip of 150 lights are 50% intensity with color temperature at
// 5000 Kelvin.
dev, err := New(s, 150, 127, 5000)
if err != nil {
	log.Fatalf("failed to open apa102: %v", err)
}
img := image.NewNRGBA(image.Rect(0, 0, dev.Bounds().Dy(), 1))
for x := 0; x < img.Rect.Max.X; x++ {
	img.SetNRGBA(x, 0, color.NRGBA{uint8(x), uint8(255 - x), 0, 255})
}
dev.Draw(dev.Bounds(), img, image.Point{})
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToRGB

func ToRGB(p []color.NRGBA) []byte

ToRGB converts a slice of color.NRGBA to a byte stream of RGB pixels.

Ignores alpha.

Types

type Dev

type Dev struct {
	Intensity   uint8  // Set an intensity between 0 (off) and 255 (full brightness).
	Temperature uint16 // In Kelvin.
	// contains filtered or unexported fields
}

Dev represents a strip of APA-102 LEDs as a strip connected over a SPI port. It accepts a stream of raw RGB pixels and converts it to the full dynamic range as supported by APA102 protocol (nearly 8000:1 contrast ratio).

Includes intensity and temperature correction.

func New

func New(p spi.Port, numLights int, intensity uint8, temperature uint16) (*Dev, error)

New returns a strip that communicates over SPI to APA102 LEDs.

The SPI port speed should be high, at least in the Mhz range, as there's 32 bits sent per LED, creating a staggered effect. See https://cpldcpu.wordpress.com/2014/11/30/understanding-the-apa102-superled/

Temperature is in °Kelvin and a reasonable default value is 6500°K.

As per APA102-C spec, the chip's max refresh rate is 400hz. https://en.wikipedia.org/wiki/Flicker_fusion_threshold is a recommended reading.

func (*Dev) Bounds

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

Bounds implements devices.Display. Min is guaranteed to be {0, 0}.

func (*Dev) ColorModel

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

ColorModel implements devices.Display. There's no surprise, it is color.NRGBAModel.

func (*Dev) Draw

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

Draw implements devices.Display.

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

func (*Dev) Halt

func (d *Dev) Halt() error

Halt turns off all the lights.

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 pixels and sends it as APA102 encoded stream.

Jump to

Keyboard shortcuts

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