From df4ffb58f4c6186beb72a3c950f48adebc828a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ximo=20Cuadros?= Date: Sun, 13 Nov 2016 18:21:03 +0100 Subject: [PATCH] inline documentation --- canvas.go | 1 + examples/basic/main.go | 4 ++++ examples/image/main.go | 10 +++++++--- examples/rpc/server/main.go | 2 ++ toolkit.go | 20 +++++++++++++++++++- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/canvas.go b/canvas.go index bc908a3..3b7d7f5 100644 --- a/canvas.go +++ b/canvas.go @@ -66,6 +66,7 @@ func (c *Canvas) Close() error { return c.m.Close() } +// Matrix is an interface that represent any RGB matrix, very useful for testing type Matrix interface { Geometry() (width, height int) At(position int) color.Color diff --git a/examples/basic/main.go b/examples/basic/main.go index 5fdf81a..d04cb9c 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -2,6 +2,7 @@ package main import ( "flag" + "fmt" "image/color" "github.com/mcuadros/go-rpi-rgb-led-matrix" @@ -9,6 +10,7 @@ import ( var ( 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") brightness = flag.Int("brightness", 100, "brightness (0-100)") ) @@ -16,6 +18,7 @@ var ( func main() { config := &rgbmatrix.DefaultConfig config.Rows = *rows + config.Parallel = *parallel config.ChainLength = *chain config.Brightness = *brightness @@ -28,6 +31,7 @@ func main() { bounds := c.Bounds() for x := bounds.Min.X; x < bounds.Max.X; x++ { 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.Render() } diff --git a/examples/image/main.go b/examples/image/main.go index b812a66..6d71bed 100644 --- a/examples/image/main.go +++ b/examples/image/main.go @@ -2,6 +2,7 @@ package main import ( "flag" + "image" "os" "time" @@ -11,18 +12,21 @@ import ( var ( 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") brightness = flag.Int("brightness", 100, "brightness (0-100)") - image = flag.String("image", "", "image path") - rotate = flag.Int("rotate", 0, "rotate angle, 90, 180, 270") + img = flag.String("image", "", "image path") + + rotate = flag.Int("rotate", 0, "rotate angle, 90, 180, 270") ) func main() { - f, err := os.Open(*image) + f, err := os.Open(*img) fatal(err) config := &rgbmatrix.DefaultConfig config.Rows = *rows + config.Parallel = *parallel config.ChainLength = *chain config.Brightness = *brightness diff --git a/examples/rpc/server/main.go b/examples/rpc/server/main.go index b7a4eb1..7e634b2 100644 --- a/examples/rpc/server/main.go +++ b/examples/rpc/server/main.go @@ -10,6 +10,7 @@ import ( var ( rows = flag.Int("led-rows", 32, "number of rows supported") 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)") ) @@ -18,6 +19,7 @@ func main() { config.Rows = *rows config.ChainLength = *chain config.Brightness = *brightness + config.Parallel = *parallel m, err := rgbmatrix.NewRGBLedMatrix(config) fatal(err) diff --git a/toolkit.go b/toolkit.go index ce9eac2..ede8938 100644 --- a/toolkit.go +++ b/toolkit.go @@ -8,17 +8,29 @@ import ( "time" ) +// ToolKit is a convinient set of function to operate with a led of Matrix 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 } +// NewToolKit returns a new ToolKit wrapping the given Matrix func NewToolKit(m Matrix) *ToolKit { return &ToolKit{ Canvas: NewCanvas(m), } } +// PlayImage draws the given image during the given delay func (tk *ToolKit) PlayImage(i image.Image, delay time.Duration) error { start := time.Now() 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() } +// 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 { quit := make(chan bool, 0) @@ -60,6 +75,8 @@ func (tk *ToolKit) PlayImages(images []image.Image, delay []time.Duration, loop 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) { gif, err := gif.DecodeAll(r) 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 } +// Close close the toolkit and the inner canvas func (tk *ToolKit) Close() error { return tk.Canvas.Close() }