inline documentation
This commit is contained in:
@@ -66,6 +66,7 @@ func (c *Canvas) Close() error {
|
|||||||
return c.m.Close()
|
return c.m.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Matrix is an interface that represent any RGB matrix, very useful for testing
|
||||||
type Matrix interface {
|
type Matrix interface {
|
||||||
Geometry() (width, height int)
|
Geometry() (width, height int)
|
||||||
At(position int) color.Color
|
At(position int) color.Color
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
"github.com/mcuadros/go-rpi-rgb-led-matrix"
|
"github.com/mcuadros/go-rpi-rgb-led-matrix"
|
||||||
@@ -9,6 +10,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
rows = flag.Int("led-rows", 32, "number of rows supported")
|
rows = flag.Int("led-rows", 32, "number of rows supported")
|
||||||
|
parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels")
|
||||||
chain = flag.Int("led-chain", 2, "number of displays daisy-chained")
|
chain = flag.Int("led-chain", 2, "number of displays daisy-chained")
|
||||||
brightness = flag.Int("brightness", 100, "brightness (0-100)")
|
brightness = flag.Int("brightness", 100, "brightness (0-100)")
|
||||||
)
|
)
|
||||||
@@ -16,6 +18,7 @@ var (
|
|||||||
func main() {
|
func main() {
|
||||||
config := &rgbmatrix.DefaultConfig
|
config := &rgbmatrix.DefaultConfig
|
||||||
config.Rows = *rows
|
config.Rows = *rows
|
||||||
|
config.Parallel = *parallel
|
||||||
config.ChainLength = *chain
|
config.ChainLength = *chain
|
||||||
config.Brightness = *brightness
|
config.Brightness = *brightness
|
||||||
|
|
||||||
@@ -28,6 +31,7 @@ func main() {
|
|||||||
bounds := c.Bounds()
|
bounds := c.Bounds()
|
||||||
for x := bounds.Min.X; x < bounds.Max.X; x++ {
|
for x := bounds.Min.X; x < bounds.Max.X; x++ {
|
||||||
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
||||||
|
fmt.Println("x", x, "y", y)
|
||||||
c.Set(x, y, color.RGBA{255, 0, 0, 255})
|
c.Set(x, y, color.RGBA{255, 0, 0, 255})
|
||||||
c.Render()
|
c.Render()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"image"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -11,18 +12,21 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
rows = flag.Int("led-rows", 32, "number of rows supported")
|
rows = flag.Int("led-rows", 32, "number of rows supported")
|
||||||
|
parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels")
|
||||||
chain = flag.Int("led-chain", 2, "number of displays daisy-chained")
|
chain = flag.Int("led-chain", 2, "number of displays daisy-chained")
|
||||||
brightness = flag.Int("brightness", 100, "brightness (0-100)")
|
brightness = flag.Int("brightness", 100, "brightness (0-100)")
|
||||||
image = flag.String("image", "", "image path")
|
img = flag.String("image", "", "image path")
|
||||||
rotate = flag.Int("rotate", 0, "rotate angle, 90, 180, 270")
|
|
||||||
|
rotate = flag.Int("rotate", 0, "rotate angle, 90, 180, 270")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
f, err := os.Open(*image)
|
f, err := os.Open(*img)
|
||||||
fatal(err)
|
fatal(err)
|
||||||
|
|
||||||
config := &rgbmatrix.DefaultConfig
|
config := &rgbmatrix.DefaultConfig
|
||||||
config.Rows = *rows
|
config.Rows = *rows
|
||||||
|
config.Parallel = *parallel
|
||||||
config.ChainLength = *chain
|
config.ChainLength = *chain
|
||||||
config.Brightness = *brightness
|
config.Brightness = *brightness
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
rows = flag.Int("led-rows", 32, "number of rows supported")
|
rows = flag.Int("led-rows", 32, "number of rows supported")
|
||||||
chain = flag.Int("led-chain", 2, "number of displays daisy-chained")
|
chain = flag.Int("led-chain", 2, "number of displays daisy-chained")
|
||||||
|
parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels")
|
||||||
brightness = flag.Int("brightness", 100, "brightness (0-100)")
|
brightness = flag.Int("brightness", 100, "brightness (0-100)")
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ func main() {
|
|||||||
config.Rows = *rows
|
config.Rows = *rows
|
||||||
config.ChainLength = *chain
|
config.ChainLength = *chain
|
||||||
config.Brightness = *brightness
|
config.Brightness = *brightness
|
||||||
|
config.Parallel = *parallel
|
||||||
|
|
||||||
m, err := rgbmatrix.NewRGBLedMatrix(config)
|
m, err := rgbmatrix.NewRGBLedMatrix(config)
|
||||||
fatal(err)
|
fatal(err)
|
||||||
|
|||||||
20
toolkit.go
20
toolkit.go
@@ -8,17 +8,29 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ToolKit is a convinient set of function to operate with a led of Matrix
|
||||||
type ToolKit struct {
|
type ToolKit struct {
|
||||||
Canvas *Canvas
|
// 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
|
Transform func(img image.Image) *image.NRGBA
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewToolKit returns a new ToolKit wrapping the given Matrix
|
||||||
func NewToolKit(m Matrix) *ToolKit {
|
func NewToolKit(m Matrix) *ToolKit {
|
||||||
return &ToolKit{
|
return &ToolKit{
|
||||||
Canvas: NewCanvas(m),
|
Canvas: NewCanvas(m),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PlayImage draws the given image during the given delay
|
||||||
func (tk *ToolKit) PlayImage(i image.Image, delay time.Duration) error {
|
func (tk *ToolKit) PlayImage(i image.Image, delay time.Duration) error {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
defer func() { time.Sleep(delay - time.Since(start)) }()
|
defer func() { time.Sleep(delay - time.Since(start)) }()
|
||||||
@@ -31,6 +43,9 @@ func (tk *ToolKit) PlayImage(i image.Image, delay time.Duration) error {
|
|||||||
return tk.Canvas.Render()
|
return tk.Canvas.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
func (tk *ToolKit) PlayImages(images []image.Image, delay []time.Duration, loop int) chan bool {
|
func (tk *ToolKit) PlayImages(images []image.Image, delay []time.Duration, loop int) chan bool {
|
||||||
quit := make(chan bool, 0)
|
quit := make(chan bool, 0)
|
||||||
|
|
||||||
@@ -60,6 +75,8 @@ func (tk *ToolKit) PlayImages(images []image.Image, delay []time.Duration, loop
|
|||||||
return quit
|
return quit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 (tk *ToolKit) PlayGIF(r io.Reader) (chan bool, error) {
|
func (tk *ToolKit) PlayGIF(r io.Reader) (chan bool, error) {
|
||||||
gif, err := gif.DecodeAll(r)
|
gif, err := gif.DecodeAll(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -76,6 +93,7 @@ func (tk *ToolKit) PlayGIF(r io.Reader) (chan bool, error) {
|
|||||||
return tk.PlayImages(images, delay, gif.LoopCount), nil
|
return tk.PlayImages(images, delay, gif.LoopCount), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close close the toolkit and the inner canvas
|
||||||
func (tk *ToolKit) Close() error {
|
func (tk *ToolKit) Close() error {
|
||||||
return tk.Canvas.Close()
|
return tk.Canvas.Close()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user