Skip to content

Commit df4ffb5

Browse files
committed
inline documentation
1 parent 0f2b167 commit df4ffb5

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

canvas.go

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func (c *Canvas) Close() error {
6666
return c.m.Close()
6767
}
6868

69+
// Matrix is an interface that represent any RGB matrix, very useful for testing
6970
type Matrix interface {
7071
Geometry() (width, height int)
7172
At(position int) color.Color

examples/basic/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@ package main
22

33
import (
44
"flag"
5+
"fmt"
56
"image/color"
67

78
"github.com/mcuadros/go-rpi-rgb-led-matrix"
89
)
910

1011
var (
1112
rows = flag.Int("led-rows", 32, "number of rows supported")
13+
parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels")
1214
chain = flag.Int("led-chain", 2, "number of displays daisy-chained")
1315
brightness = flag.Int("brightness", 100, "brightness (0-100)")
1416
)
1517

1618
func main() {
1719
config := &rgbmatrix.DefaultConfig
1820
config.Rows = *rows
21+
config.Parallel = *parallel
1922
config.ChainLength = *chain
2023
config.Brightness = *brightness
2124

@@ -28,6 +31,7 @@ func main() {
2831
bounds := c.Bounds()
2932
for x := bounds.Min.X; x < bounds.Max.X; x++ {
3033
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
34+
fmt.Println("x", x, "y", y)
3135
c.Set(x, y, color.RGBA{255, 0, 0, 255})
3236
c.Render()
3337
}

examples/image/main.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"flag"
5+
"image"
56
"os"
67
"time"
78

@@ -11,18 +12,21 @@ import (
1112

1213
var (
1314
rows = flag.Int("led-rows", 32, "number of rows supported")
15+
parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels")
1416
chain = flag.Int("led-chain", 2, "number of displays daisy-chained")
1517
brightness = flag.Int("brightness", 100, "brightness (0-100)")
16-
image = flag.String("image", "", "image path")
17-
rotate = flag.Int("rotate", 0, "rotate angle, 90, 180, 270")
18+
img = flag.String("image", "", "image path")
19+
20+
rotate = flag.Int("rotate", 0, "rotate angle, 90, 180, 270")
1821
)
1922

2023
func main() {
21-
f, err := os.Open(*image)
24+
f, err := os.Open(*img)
2225
fatal(err)
2326

2427
config := &rgbmatrix.DefaultConfig
2528
config.Rows = *rows
29+
config.Parallel = *parallel
2630
config.ChainLength = *chain
2731
config.Brightness = *brightness
2832

examples/rpc/server/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
var (
1111
rows = flag.Int("led-rows", 32, "number of rows supported")
1212
chain = flag.Int("led-chain", 2, "number of displays daisy-chained")
13+
parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels")
1314
brightness = flag.Int("brightness", 100, "brightness (0-100)")
1415
)
1516

@@ -18,6 +19,7 @@ func main() {
1819
config.Rows = *rows
1920
config.ChainLength = *chain
2021
config.Brightness = *brightness
22+
config.Parallel = *parallel
2123

2224
m, err := rgbmatrix.NewRGBLedMatrix(config)
2325
fatal(err)

toolkit.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,29 @@ import (
88
"time"
99
)
1010

11+
// ToolKit is a convinient set of function to operate with a led of Matrix
1112
type ToolKit struct {
12-
Canvas *Canvas
13+
// Canvas is the Canvas wrapping the Matrix, if you want to instanciate
14+
// a ToolKit with a custom Canvas you can use directly the struct,
15+
// without calling NewToolKit
16+
Canvas *Canvas
17+
18+
// Transform function if present is applied just before draw the image to
19+
// the Matrix, this is a small example:
20+
// tk.Transform = func(img image.Image) *image.NRGBA {
21+
// return imaging.Fill(img, 64, 96, imaging.Center, imaging.Lanczos)
22+
// }
1323
Transform func(img image.Image) *image.NRGBA
1424
}
1525

26+
// NewToolKit returns a new ToolKit wrapping the given Matrix
1627
func NewToolKit(m Matrix) *ToolKit {
1728
return &ToolKit{
1829
Canvas: NewCanvas(m),
1930
}
2031
}
2132

33+
// PlayImage draws the given image during the given delay
2234
func (tk *ToolKit) PlayImage(i image.Image, delay time.Duration) error {
2335
start := time.Now()
2436
defer func() { time.Sleep(delay - time.Since(start)) }()
@@ -31,6 +43,9 @@ func (tk *ToolKit) PlayImage(i image.Image, delay time.Duration) error {
3143
return tk.Canvas.Render()
3244
}
3345

46+
// PlayImages draws a sequence of images during the given delays, the len of
47+
// images should be equal to the len of delay. If loop is true the function
48+
// loops over images until a true is sent to the returned chan
3449
func (tk *ToolKit) PlayImages(images []image.Image, delay []time.Duration, loop int) chan bool {
3550
quit := make(chan bool, 0)
3651

@@ -60,6 +75,8 @@ func (tk *ToolKit) PlayImages(images []image.Image, delay []time.Duration, loop
6075
return quit
6176
}
6277

78+
// PlayGIF reads and draw a gif file from r. It use the contained images and
79+
// delays and loops over it, until a true is sent to the returned chan
6380
func (tk *ToolKit) PlayGIF(r io.Reader) (chan bool, error) {
6481
gif, err := gif.DecodeAll(r)
6582
if err != nil {
@@ -76,6 +93,7 @@ func (tk *ToolKit) PlayGIF(r io.Reader) (chan bool, error) {
7693
return tk.PlayImages(images, delay, gif.LoopCount), nil
7794
}
7895

96+
// Close close the toolkit and the inner canvas
7997
func (tk *ToolKit) Close() error {
8098
return tk.Canvas.Close()
8199
}

0 commit comments

Comments
 (0)