just moving functions around
Some checks failed
rgb/pipeline/head There was a failure building this commit
Some checks failed
rgb/pipeline/head There was a failure building this commit
This commit is contained in:
87
main.go
87
main.go
@@ -19,9 +19,8 @@ import (
|
|||||||
"github.com/fogleman/gg"
|
"github.com/fogleman/gg"
|
||||||
)
|
)
|
||||||
|
|
||||||
/* contents of struct mostly don't matter for toolkit.
|
// contents of struct mostly don't matter for toolkit.
|
||||||
|
|
||||||
*/
|
|
||||||
type Animation struct {
|
type Animation struct {
|
||||||
ctx *gg.Context
|
ctx *gg.Context
|
||||||
position image.Point
|
position image.Point
|
||||||
@@ -35,6 +34,7 @@ type Animation struct {
|
|||||||
msg string
|
msg string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//flags from cmd line
|
||||||
var (
|
var (
|
||||||
rows = flag.Int("led-rows", 32, "number of rows supported")
|
rows = flag.Int("led-rows", 32, "number of rows supported")
|
||||||
cols = flag.Int("led-cols", 32, "number of columns supported")
|
cols = flag.Int("led-cols", 32, "number of columns supported")
|
||||||
@@ -47,43 +47,7 @@ var (
|
|||||||
disable_hardware_pulsing = flag.Bool("led-no-hardware-pulse", false, "Don't use hardware pin-pulse generation.")
|
disable_hardware_pulsing = flag.Bool("led-no-hardware-pulse", false, "Don't use hardware pin-pulse generation.")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
//listens on topic for messages
|
||||||
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
|
|
||||||
setupMQTT()
|
|
||||||
|
|
||||||
m, err := rgbmatrix.NewRGBLedMatrix(config)
|
|
||||||
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 animator(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")
|
|
||||||
}
|
|
||||||
|
|
||||||
func listener(mqMessages chan mqtt.Message) {
|
func listener(mqMessages chan mqtt.Message) {
|
||||||
opts := setupMQTT()
|
opts := setupMQTT()
|
||||||
client := MQTT.NewClient(opts)
|
client := MQTT.NewClient(opts)
|
||||||
@@ -105,9 +69,13 @@ func animator(tk *rgbmatrix.ToolKit, mqMessages chan mqtt.Message) {
|
|||||||
tk.PlayAnimation(NewAnimation(image.Point{64, 32}, mqMessages))
|
tk.PlayAnimation(NewAnimation(image.Point{64, 32}, mqMessages))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//connection lost management
|
||||||
func onConnectionLostHandler(c MQTT.Client, reason error) {
|
func onConnectionLostHandler(c MQTT.Client, reason error) {
|
||||||
log.Fatalf(reason.Error())
|
log.Fatalf(reason.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//setup connection to mqtt, topic to listen to, qos
|
||||||
func setupMQTT() *mqtt.ClientOptions {
|
func setupMQTT() *mqtt.ClientOptions {
|
||||||
opts := MQTT.NewClientOptions()
|
opts := MQTT.NewClientOptions()
|
||||||
opts.AddBroker(fmt.Sprintf("tcp://%s:%s", os.Getenv("MQTTBROKER"), os.Getenv("MQTTPORT")))
|
opts.AddBroker(fmt.Sprintf("tcp://%s:%s", os.Getenv("MQTTBROKER"), os.Getenv("MQTTPORT")))
|
||||||
@@ -119,10 +87,13 @@ func setupMQTT() *mqtt.ClientOptions {
|
|||||||
|
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//runs before main, parses flags
|
||||||
func init() {
|
func init() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//small function for handling fatal errors
|
||||||
func fatal(err error) {
|
func fatal(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -180,6 +151,7 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
|
|||||||
return a.ctx.Image(), time.After(time.Millisecond * 50), nil
|
return a.ctx.Image(), time.After(time.Millisecond * 50), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//what mario does every frame
|
||||||
func (a *Animation) updatePosition() {
|
func (a *Animation) updatePosition() {
|
||||||
a.position.X += 1 * a.dir.X
|
a.position.X += 1 * a.dir.X
|
||||||
a.position.Y += 1 * a.dir.Y
|
a.position.Y += 1 * a.dir.Y
|
||||||
@@ -198,3 +170,40 @@ func (a *Animation) updatePosition() {
|
|||||||
a.dir.X = 1
|
a.dir.X = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
setupMQTT()
|
||||||
|
|
||||||
|
m, err := rgbmatrix.NewRGBLedMatrix(config)
|
||||||
|
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 animator(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")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user