From 53fa87a5d31136e6173fef6b832d5d1aeddd313a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ximo=20Cuadros?= Date: Mon, 24 Oct 2016 02:17:15 +0200 Subject: [PATCH] examples --- examples/basic/main.go | 45 ++++++++++++++++++++++++++++++++++ examples/image/main.go | 48 +++++++++++++++++++++++++++++++++++++ examples/rpc/client/main.go | 42 ++++++++++++++++++++++++++++++++ examples/rpc/server/main.go | 32 +++++++++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 examples/basic/main.go create mode 100644 examples/image/main.go create mode 100644 examples/rpc/client/main.go create mode 100644 examples/rpc/server/main.go diff --git a/examples/basic/main.go b/examples/basic/main.go new file mode 100644 index 0000000..5fdf81a --- /dev/null +++ b/examples/basic/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "flag" + "image/color" + + "github.com/mcuadros/go-rpi-rgb-led-matrix" +) + +var ( + rows = flag.Int("led-rows", 32, "number of rows supported") + chain = flag.Int("led-chain", 2, "number of displays daisy-chained") + brightness = flag.Int("brightness", 100, "brightness (0-100)") +) + +func main() { + config := &rgbmatrix.DefaultConfig + config.Rows = *rows + config.ChainLength = *chain + config.Brightness = *brightness + + m, err := rgbmatrix.NewRGBLedMatrix(config) + fatal(err) + + c := rgbmatrix.NewCanvas(m) + defer c.Close() + + bounds := c.Bounds() + for x := bounds.Min.X; x < bounds.Max.X; x++ { + for y := bounds.Min.Y; y < bounds.Max.Y; y++ { + c.Set(x, y, color.RGBA{255, 0, 0, 255}) + c.Render() + } + } +} + +func init() { + flag.Parse() +} + +func fatal(err error) { + if err != nil { + panic(err) + } +} diff --git a/examples/image/main.go b/examples/image/main.go new file mode 100644 index 0000000..fefba69 --- /dev/null +++ b/examples/image/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "flag" + "os" + "time" + + "github.com/mcuadros/go-rpi-rgb-led-matrix" +) + +var ( + rows = flag.Int("led-rows", 32, "number of rows supported") + 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") +) + +func main() { + f, err := os.Open(*image) + fatal(err) + + config := &rgbmatrix.DefaultConfig + config.Rows = *rows + config.ChainLength = *chain + config.Brightness = *brightness + + m, err := rgbmatrix.NewRGBLedMatrix(config) + fatal(err) + + tk := rgbmatrix.NewToolKit(m) + defer tk.Close() + + close, err := tk.PlayGIF(f) + fatal(err) + + time.Sleep(time.Second * 30) + close <- true +} + +func init() { + flag.Parse() +} + +func fatal(err error) { + if err != nil { + panic(err) + } +} diff --git a/examples/rpc/client/main.go b/examples/rpc/client/main.go new file mode 100644 index 0000000..0bee0f5 --- /dev/null +++ b/examples/rpc/client/main.go @@ -0,0 +1,42 @@ +package main + +import ( + "flag" + "os" + "time" + + "github.com/mcuadros/go-rpi-rgb-led-matrix" + "github.com/mcuadros/go-rpi-rgb-led-matrix/rpc" +) + +var ( + img = flag.String("image", "", "image path") +) + +func main() { + f, err := os.Open(*img) + fatal(err) + + m, err := rpc.NewClient("tcp", "10.20.20.20:1234") + fatal(err) + + c := rgbmatrix.NewCanvas(m) + defer c.Close() + + tk := &rgbmatrix.ToolKit{c} + close, err := tk.PlayGIF(f) + fatal(err) + + time.Sleep(time.Second * 3) + close <- true +} + +func init() { + flag.Parse() +} + +func fatal(err error) { + if err != nil { + panic(err) + } +} diff --git a/examples/rpc/server/main.go b/examples/rpc/server/main.go new file mode 100644 index 0000000..b7a4eb1 --- /dev/null +++ b/examples/rpc/server/main.go @@ -0,0 +1,32 @@ +package main + +import ( + "flag" + + "github.com/mcuadros/go-rpi-rgb-led-matrix" + "github.com/mcuadros/go-rpi-rgb-led-matrix/rpc" +) + +var ( + rows = flag.Int("led-rows", 32, "number of rows supported") + chain = flag.Int("led-chain", 2, "number of displays daisy-chained") + brightness = flag.Int("brightness", 100, "brightness (0-100)") +) + +func main() { + config := &rgbmatrix.DefaultConfig + config.Rows = *rows + config.ChainLength = *chain + config.Brightness = *brightness + + m, err := rgbmatrix.NewRGBLedMatrix(config) + fatal(err) + + rpc.Serve(m) +} + +func fatal(err error) { + if err != nil { + panic(err) + } +}