rgbmatrix

package
v0.0.0-...-8df2434 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const MatrixEmulatorENV = "MATRIX_EMULATOR"

Variables

View Source
var DefaultConfig = HardwareConfig{
	Rows:              32,
	Cols:              32,
	ChainLength:       1,
	Parallel:          1,
	PWMBits:           11,
	PWMLSBNanoseconds: 130,
	Brightness:        100,
	ScanMode:          Progressive,
}

DefaultConfig default WS281x configuration

Functions

This section is empty.

Types

type Animation

type Animation interface {
	Next() (image.Image, <-chan time.Time, error)
}

type Canvas

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

Canvas is a image.Image representation of a WS281x matrix, it implements image.Image interface and can be used with draw.Draw for example

func NewCanvas

func NewCanvas(m Matrix) *Canvas

NewCanvas returns a new Canvas using the given width and height and creates a new WS281x matrix using the given config

func (*Canvas) At

func (c *Canvas) At(x, y int) color.Color

At returns the color of the pixel at (x, y)

func (*Canvas) Bounds

func (c *Canvas) Bounds() image.Rectangle

Bounds return the topology of the Canvas

func (*Canvas) Clear

func (c *Canvas) Clear() error

Clear set all the leds on the matrix with color.Black

func (*Canvas) Close

func (c *Canvas) Close() error

Close clears the matrix and close the matrix

func (*Canvas) ColorModel

func (c *Canvas) ColorModel() color.Model

ColorModel returns the canvas' color model, always color.RGBAModel

func (*Canvas) Render

func (c *Canvas) Render() error

Render update the display with the data from the LED buffer

func (*Canvas) Set

func (c *Canvas) Set(x, y int, color color.Color)

Set set LED at position x,y to the provided 24-bit color value

type HardwareConfig

type HardwareConfig struct {
	// Rows the number of rows supported by the display, so 32 or 16.
	Rows int
	// Cols the number of columns supported by the display, so 32 or 64 .
	Cols int
	// ChainLengthis the number of displays daisy-chained together
	// (output of one connected to input of next).
	ChainLength int
	// Parallel is the number of parallel chains connected to the Pi; in old Pis
	// with 26 GPIO pins, that is 1, in newer Pis with 40 interfaces pins, that
	// can also be 2 or 3. The effective number of pixels in vertical direction is
	// then thus rows * parallel.
	Parallel int
	// Set PWM bits used for output. Default is 11, but if you only deal with
	// limited comic-colors, 1 might be sufficient. Lower require less CPU and
	// increases refresh-rate.
	PWMBits int
	// Change the base time-unit for the on-time in the lowest significant bit in
	// nanoseconds.  Higher numbers provide better quality (more accurate color,
	// less ghosting), but have a negative impact on the frame rate.
	PWMLSBNanoseconds int // the DMA channel to use
	// Brightness is the initial brightness of the panel in percent. Valid range
	// is 1..100
	Brightness int
	// ScanMode progressive or interlaced
	ScanMode ScanMode // strip color layout
	// Disable the PWM hardware subsystem to create pulses. Typically, you don't
	// want to disable hardware pulsing, this is mostly for debugging and figuring
	// out if there is interference with the sound system.
	// This won't do anything if output enable is not connected to GPIO 18 in
	// non-standard wirings.
	DisableHardwarePulsing bool

	ShowRefreshRate bool
	InverseColors   bool

	// Name of GPIO mapping used
	HardwareMapping string
}

HardwareConfig rgb-led-matrix configuration

type Matrix

type Matrix interface {
	Geometry() (width, height int)
	At(position int) color.Color
	Set(position int, c color.Color)
	Apply([]color.Color) error
	Render() error
	Close() error
}

Matrix is an interface that represent any RGB matrix, very useful for testing

func NewRGBLedMatrix

func NewRGBLedMatrix(config *HardwareConfig) (c Matrix, err error)

NewRGBLedMatrix returns a new matrix using the given size and config

type RGBLedMatrix

type RGBLedMatrix struct {
	Config *HardwareConfig
	// contains filtered or unexported fields
}

RGBLedMatrix matrix representation for ws281x

func (*RGBLedMatrix) Apply

func (c *RGBLedMatrix) Apply(leds []color.Color) error

Apply set all the pixels to the values contained in leds

func (*RGBLedMatrix) At

func (c *RGBLedMatrix) At(position int) color.Color

At return an Color which allows access to the LED agents data as if it were a sequence of 24-bit RGB values.

func (*RGBLedMatrix) Close

func (c *RGBLedMatrix) Close() error

Close finalizes the ws281x interface

func (*RGBLedMatrix) Geometry

func (c *RGBLedMatrix) Geometry() (width, height int)

Geometry returns the width and the height of the matrix

func (*RGBLedMatrix) Initialize

func (c *RGBLedMatrix) Initialize() error

Initialize initialize library, must be called once before other functions are called.

func (*RGBLedMatrix) Render

func (c *RGBLedMatrix) Render() error

Render update the agents with the data from the LED buffer

func (*RGBLedMatrix) Set

func (c *RGBLedMatrix) Set(position int, color color.Color)

Set set LED at position x,y to the provided 24-bit color value.

type ScanMode

type ScanMode int8
const (
	Progressive ScanMode = 0
	Interlaced  ScanMode = 1
)

type ToolKit

type ToolKit struct {
	// Canvas is the Canvas wrapping the Matrix, if you want to instanciate
	// a ToolKit with a custom Canvas you can use directly the struct,
	// without calling NewToolKit
	Canvas *Canvas

	// Transform function if present is applied just before draw the image to
	// the Matrix, this is a small example:
	//	tk.Transform = func(img image.Image) *image.NRGBA {
	//		return imaging.Fill(img, 64, 96, imaging.Center, imaging.Lanczos)
	//	}
	Transform func(img image.Image) *image.NRGBA
}

ToolKit is a convinient set of function to operate with a led of Matrix

func NewToolKit

func NewToolKit(m Matrix) *ToolKit

NewToolKit returns a new ToolKit wrapping the given Matrix

func (*ToolKit) Close

func (tk *ToolKit) Close() error

Close close the toolkit and the inner canvas

func (*ToolKit) PlayAnimation

func (tk *ToolKit) PlayAnimation(a Animation) error

PlayAnimation play the image during the delay returned by Next, until an err is returned, if io.EOF is returned, PlayAnimation finish without an error

func (*ToolKit) PlayGIF

func (tk *ToolKit) PlayGIF(r io.Reader) (chan bool, error)

PlayGIF reads and draw a gif file from r. It use the contained images and delays and loops over it, until a true is sent to the returned chan

func (*ToolKit) PlayImage

func (tk *ToolKit) PlayImage(i image.Image, delay time.Duration) error

PlayImage draws the given image during the given delay

func (*ToolKit) PlayImageUntil

func (tk *ToolKit) PlayImageUntil(i image.Image, notify <-chan time.Time) error

PlayImageUntil draws the given image until is notified to stop

func (*ToolKit) PlayImages

func (tk *ToolKit) PlayImages(images []image.Image, delay []time.Duration, loop int) chan bool

PlayImages draws a sequence of images during the given delays, the len of images should be equal to the len of delay. If loop is true the function loops over images until a true is sent to the returned chan

Jump to

Keyboard shortcuts

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