Documentation ¶
Overview ¶
Package rpiws281x is used for controlling WS281x LEDs on the Raspberry Pi using plain GO.
Index ¶
- Constants
- Variables
- type Config
- func (c *Config) Initialize() error
- func (c *Config) Render(stripIndex int) error
- func (c *Config) SetBrightness(brightness uint32, stripIndex int) error
- func (c *Config) SetDMAChannel(channel uint32) error
- func (c *Config) SetFrequency(frequency uint32) error
- func (c *Config) SetStrip(ledStrip LEDs, pin uint32, stripType StripType, stripIndex int, ...) error
- func (c *Config) Stop() error
- type DriverType
- type LEDStrip
- func (l *LEDStrip) Blue(position int) uint8
- func (l *LEDStrip) Green(position int) uint8
- func (l *LEDStrip) Red(position int) uint8
- func (l *LEDStrip) SetColor(position int, c color.Color)
- func (l *LEDStrip) SetDirect(position int, val uint32)
- func (l *LEDStrip) SetRGBA(position int, r, g, b, a uint32)
- func (l *LEDStrip) ShiftLeft(shift int)
- func (l *LEDStrip) ShiftRight(shift int)
- func (l *LEDStrip) TotalCount() int
- func (l *LEDStrip) UInt32(position int) uint32
- func (l *LEDStrip) White(position int) uint8
- type LEDs
- type SingleLED
- func (l *SingleLED) Blue(unused int) uint8
- func (l *SingleLED) Green(unused int) uint8
- func (l *SingleLED) Red(unused int) uint8
- func (l *SingleLED) SetColor(c color.Color)
- func (l *SingleLED) SetDirect(val uint32)
- func (l *SingleLED) SetRGBA(r, g, b, a uint32)
- func (l *SingleLED) ToColor() color.Color
- func (l *SingleLED) TotalCount() int
- func (l *SingleLED) UInt32(unused int) uint32
- func (l *SingleLED) White(unused int) uint8
- type StripType
Constants ¶
const ( // 4 color R, G, B and W ordering SK6812StripRGBW StripType = 0x18100800 SK6812StripRBGW = 0x18100008 SK6812StripGRBW = 0x18081000 SK6812StripGBRW = 0x18080010 SK6812StripBRGW = 0x18001008 SK6812StripBGRW = 0x18000810 // 3 color R, G and B ordering WS2811StripRGB StripType = 0x00100800 WS2811StripRBG = 0x00100008 WS2811StripGRB = 0x00081000 WS2811StripGBR = 0x00080010 WS2811StripBRG = 0x00001008 WS2811StripBGR = 0x00000810 )
Valid StripTypes
const ( WS2812Strip = WS2811StripGRB SK6812Strip = WS2811StripGRB SK6812WStrip = SK6812StripGRBW )
Predefined fixed LED types
Variables ¶
var ( ErrNoClockMap = errors.New("clock device map not set. Not initialized?") ErrNoHardware = errors.New("no hardware set. Not initialized?") ErrDriverAlreadyUsed = errors.New("driver already initialized") ErrConfigInitialized = errors.New("config already initialized") ErrConfigWrongIndex = errors.New("wrong strip index") ErrDriverNotSupported = errors.New("driver not supported") ErrPinNotAllowed = errors.New("selected pin not allowed") ErrNoActiveChannel = errors.New("No active channel") ErrWrongFrequency = errors.New("Wrong Frequency") )
Errors
var Debug bool
Enable Debug output
var PWMAlwaysUseTwoChannel bool
Enable two channel mode for PWM no matter the configuration
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is the main struct which holds all information.
A Config can only contain one driver type (PWM, PCM, or SPI). However you can define multiple configurations with different driver types. Be aware that only one Config per driver type can be initialized and used at a time.
There are only some methods possible once the Config has been initialized. Use method Stop to deinitialize the Config.
func New ¶
func New(driverType DriverType) (*Config, error)
New returns a new Config for driverType.
Default Frequency: 800 kHz
Default DMAChannel: 10
func (*Config) Initialize ¶
Initialize activates a Config. If another Config for the same driverType is already active, an error is returned
func (*Config) SetBrightness ¶
SetBrightness sets the output brightness to use for the strip with index stripIndex. Valid values are between 0 and 255. This method can be called once the Config is initialized.
func (*Config) SetDMAChannel ¶
SetDMAChannel sets the DMAChannel to use. Default is 10.
If you want to use multiple Config, you can use the same DMAChannel IF you don't render the Config at the same time.
There are some DMAChannels used by the system. Please check only if you want to use another channel as 10.
func (*Config) SetFrequency ¶
SetFrequency sets the output frequency to use. Valid values are 400000 and 800000
func (*Config) SetStrip ¶
func (c *Config) SetStrip(ledStrip LEDs, pin uint32, stripType StripType, stripIndex int, invertSignal bool) error
SetStrip adds LEDs to the Config.
*****
A word about channels:
A channel represents a physical signal output on the Raspberry Pi.
There are two simultaniously available channels when using PWM as a driver. Otherwise there is only one channel available.
*****
For PWM the stripIndex can be 0 or 1. All other drivers require a stripIndex of 0. The pin is checked if it is suitable for the driverType.
type DriverType ¶
type DriverType uint8
DriverType defines the hardware type (PWM, PCM, SPI) which is used for communication
const ( DriverPWM DriverType = 1 << iota DriverPCM DriverSPI )
Valid DriverTypes
type LEDStrip ¶
type LEDStrip struct {
// contains filtered or unexported fields
}
LEDStrip represent a physical continious strip of LEDs. Each LED is represented by a SingleLED.
func NewLEDStrip ¶
NewLEDStrip returns a LEDStrip with count LEDs. Colors can be set with the methods.
func (*LEDStrip) SetDirect ¶
SetDirect sets the color value for LED at position directly. Format 0xWWRRGGBB
func (*LEDStrip) ShiftLeft ¶
ShiftLeft shifts the LED colors by shift to the left. Everything leaving on the left wraps around. Use ShiftRight instead of negative shitfs.
func (*LEDStrip) ShiftRight ¶
ShiftRight shifts the LED colors by shift to the right. Everything leaving on the right wraps around. Use ShiftLeft instead of negative shitfs.
func (*LEDStrip) TotalCount ¶
TotalCount returns the number of LEDs in the strip.
type LEDs ¶
type LEDs interface { Red(position int) uint8 Green(position int) uint8 Blue(position int) uint8 White(position int) uint8 UInt32(position int) uint32 //Format 0xWWRRGGBB TotalCount() int }
LEDs can be a single LED or a slice depending on the implementation. Position defines the physical position on the LED strip starting at 0 to the total number of LEDs on that strip.
type SingleLED ¶
type SingleLED uint32 //0xWWRRGGBB
SingleLED describes one LED with color values as 0xWWRRGGBB which can be used as an LEDs.
func ColorToSingleLED ¶
ColorToSingleLED turns a color.Color to a SingleLED.
func RGBAtoSingleLED ¶
RGBAtoSingleLED turns rgba valued to a SingleLED.
func (*SingleLED) TotalCount ¶
TotalCount returns the number of LEDs.
In this case this will always be 1.