forked from mcuadros/go-rpi-rgb-led-matrix
/
main.go
75 lines (62 loc) · 2.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"flag"
"github.com/BoskyWSMFN/go-rpi-rgb-led-matrix/pkg/canvas"
"github.com/BoskyWSMFN/go-rpi-rgb-led-matrix/pkg/matrix"
"os"
"time"
"github.com/disintegration/imaging"
)
var (
rows = flag.Int("led-rows", 32, "number of rows supported")
cols = flag.Int("led-cols", 32, "number of columns 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)")
hardwareMapping = flag.String("led-gpio-mapping", "regular", "Name of GPIO mapping used.")
showRefresh = flag.Bool("led-show-refresh", false, "Show refresh rate.")
inverseColors = flag.Bool("led-inverse", false, "Switch if your matrix has inverse colors on.")
disableHardwarePulsing = flag.Bool("led-no-hardware-pulse", false, "Don't use hardware pin-pulse generation.")
pixelMapping = flag.String("led-pixel-mapper", "U-mapper", "Pixel mapping from api")
img = flag.String("image", "", "image path")
rotate = flag.Int("rotate", 0, "rotate angle, 90, 180, 270")
)
func main() {
f, err := os.Open(*img)
fatal(err)
config := &matrix.DefaultConfig
config.Rows = *rows
config.Cols = *cols
config.Parallel = *parallel
config.ChainLength = *chain
config.Brightness = *brightness
config.HardwareMapping = *hardwareMapping
config.ShowRefreshRate = *showRefresh
config.InverseColors = *inverseColors
config.DisableHardwarePulsing = *disableHardwarePulsing
config.PixelMapping = *pixelMapping
m, err := matrix.NewRGBLedMatrix(config)
fatal(err)
tk := canvas.NewToolKit(m)
defer tk.Close()
switch *rotate {
case 90:
tk.Transform = imaging.Rotate90
case 180:
tk.Transform = imaging.Rotate180
case 270:
tk.Transform = imaging.Rotate270
}
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)
}
}