ws2811

package module
v1.0.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// RpiPwmChannels is the number of PWM leds in the Raspberry Pi
	RpiPwmChannels = 2
	// TargetFreq is the target frequency. It is usually 800kHz (800000), and an go as low as 400000
	TargetFreq = 800000
	// DefaultLedCount is the default number of LEDs on the stripe.
	DefaultLedCount = 16
	// DefaultBrightness is the default maximum brightness of the LEDs. The brightness value can be between 0 and 255.
	DefaultBrightness = 64 // Safe value between 0 and 255.
)
View Source
const (
	// SK6812StripRGBW is the RGBW Mode
	SK6812StripRGBW = 0x18100800
	// SK6812StripRBGW is the StripRBGW Mode
	SK6812StripRBGW = 0x18100008
	// SK6812StripGRBW is the StripGRBW Mode
	SK6812StripGRBW = 0x18081000
	// SK6812StrioGBRW is the StrioGBRW Mode
	SK6812StrioGBRW = 0x18080010
	// SK6812StrioBRGW is the StrioBRGW Mode
	SK6812StrioBRGW = 0x18001008
	// SK6812StripBGRW is the StripBGRW Mode
	SK6812StripBGRW = 0x18000810
	// SK6812ShiftWMask is the Shift White Mask
	SK6812ShiftWMask = 0xf0000000
)

4 color R, G, B and W ordering

View Source
const (
	// WS2811StripRGB is the RGB Mode
	WS2811StripRGB = 0x100800
	// WS2811StripRBG is the RBG Mode
	WS2811StripRBG = 0x100008
	// WS2811StripGRB is the GRB Mode
	WS2811StripGRB = 0x081000
	// WS2811StripGBR is the GBR Mode
	WS2811StripGBR = 0x080010
	// WS2811StripBRG is the BRG Mode
	WS2811StripBRG = 0x001008
	// WS2811StripBGR is the BGR Mode
	WS2811StripBGR = 0x000810
)

3 color R, G and B ordering

View Source
const (
	// WS2812Strip is the WS2812 Mode
	WS2812Strip = WS2811StripGRB
	// SK6812Strip is the SK6812 Mode
	SK6812Strip = WS2811StripGRB
	// SK6812WStrip is the SK6812W Mode
	SK6812WStrip = SK6812StripGRBW
)

Predefined fixed LED types

Variables

View Source
var DefaultOptions = Option{
	Frequency: TargetFreq,
	Channels: []ChannelOption{
		{
			LedCount:   DefaultLedCount,
			Brightness: DefaultBrightness,
			StripeType: WS2812Strip,
			Gamma:      nil,
		},
	},
}

DefaultOptions defines sensible default options for MakeWS2811

Functions

func ServeWs

func ServeWs(hub *Hub, w http.ResponseWriter, r *http.Request)

ServeWs handles websocket requests from the peer.

Types

type ChannelOption

type ChannelOption struct {
	// LedCount is the number of LEDs, 0 if channel is unused
	LedCount int
	// StripeType is the strip color layout -- one of WS2811StripXXX constants
	StripeType int
	// Brightness is the maximum brightness of the LEDs. Value between 0 and 255
	Brightness int
	// WShift is the white shift value
	WShift int
	// RShift is the red shift value
	RShift int
	// GShift is the green shift value
	GShift int
	// BShift is blue shift value
	BShift int
	// Gamma is the gamma correction table
	Gamma []byte
}

ChannelOption is the list of channel options

type Client

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

Client is a middleman between the websocket connection and the hub.

type Hub

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

Hub maintains the set of active clients and broadcasts messages to the clients.

func NewHub

func NewHub() *Hub

NewHub creates a new hub.

func (*Hub) Run

func (h *Hub) Run()

Run runs the hub process.

type Option

type Option struct {
	// RenderWaitTime is the time in µs before the next render can run
	RenderWaitTime int
	// Frequency is the required output frequency
	Frequency int
	// Channels are channel options
	Channels []ChannelOption
}

Option is the list of device options

type WS2811

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

WS2811 represent the ws2811 device

func MakeWS2811

func MakeWS2811(opt *Option, hub *Hub) (ws2811 *WS2811, err error)

MakeWS2811 create an instance of web WS2811 linked to a given hub.

func (*WS2811) Fini

func (ws2811 *WS2811) Fini()

Fini shuts down the device and frees memory.

func (*WS2811) Init

func (ws2811 *WS2811) Init() error

Init initialize the device. It should be called only once before any other method.

func (*WS2811) Leds

func (ws2811 *WS2811) Leds(channel int) []uint32

Leds returns the LEDs array of a given channel

func (*WS2811) Render

func (ws2811 *WS2811) Render() error

Render sends a complete frame to the Web Socket

func (*WS2811) SetLedsSync

func (ws2811 *WS2811) SetLedsSync(channel int, leds []uint32) error

SetLedsSync wait for the frame to finish and replace all the LEDs

func (*WS2811) Wait

func (ws2811 *WS2811) Wait() error

Wait waits for render to finish. The time needed for render is given by: time = 1/frequency * 8 * 3 * LedCount + 0.05 (8 is the color depth and 3 is the number of colors (LEDs) per pixel). See https://cdn-shop.adafruit.com/datasheets/WS2811.pdf for more details.

Jump to

Keyboard shortcuts

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