You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rgb-led-board/main.go

80 lines
2.3 KiB
Go

package main
import (
"flag"
"fmt"
_ "image/jpeg"
"log"
"os"
"os/signal"
"syscall"
rgbmatrix "gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix"
mqtt "github.com/eclipse/paho.mqtt.golang"
)
// flags from cmd line
var (
rows = flag.Int("led-rows", 64, "number of rows supported")
cols = flag.Int("led-cols", 64, "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)")
hardware_mapping = flag.String("led-gpio-mapping", "regular", "Name of GPIO mapping used.")
show_refresh = flag.Bool("led-show-refresh", false, "Show refresh rate.")
inverse_colors = flag.Bool("led-inverse", false, "Switch if your matrix has inverse colors on.")
disable_hardware_pulsing = flag.Bool("led-no-hardware-pulse", false, "Don't use hardware pin-pulse generation.")
led_slowdown_gpio = flag.Int("led-slowdown-gpio", 1, "GPIO pin slowdown")
)
// runs before main, parses flags
func init() {
flag.Parse()
}
// small function for handling fatal errors
func fatal(err error) {
if err != nil {
panic(err)
}
}
func main() {
config := &rgbmatrix.DefaultConfig
config.Rows = *rows
config.Cols = *cols
config.Parallel = *parallel
config.ChainLength = *chain
config.Brightness = *brightness
config.HardwareMapping = *hardware_mapping
config.ShowRefreshRate = *show_refresh
config.InverseColors = *inverse_colors
config.DisableHardwarePulsing = *disable_hardware_pulsing
var rt rgbmatrix.RunTimeConfig
rt.Gpio_slowdown = *led_slowdown_gpio
setupMQTT()
m, err := rgbmatrix.NewRGBLedMatrix(config, &rt)
fatal(err)
mqMessages := make(chan mqtt.Message)
log.Println("making listener")
go listener(mqMessages)
tk := rgbmatrix.NewToolKit(m)
defer tk.Close()
log.Println("making animator")
go orchestrator(tk, mqMessages)
log.Println("I guess I'm at the end")
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
done := make(chan bool, 1)
go func() {
sig := <-sigs
fmt.Println()
fmt.Println(sig)
done <- true
}()
fmt.Println("awaiting signal")
<-done
fmt.Println("exiting")
}