fixing map for doorbell
build rgb-board / build (push) Successful in 8m19s Details

main
Nathan Wagner 11 months ago
parent 7c3c385119
commit 4621c93b86

@ -14,6 +14,7 @@ import (
"os/signal"
"syscall"
"time"
rgbmatrix "gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix"
"github.com/disintegration/imaging"
MQTT "github.com/eclipse/paho.mqtt.golang"
@ -21,7 +22,7 @@ import (
"github.com/fogleman/gg"
)
// contents of struct mostly don't matter for toolkit.
// contents of struct mostly don't matter for toolkit.
type incomingImage struct {
Image string `json:"image"`
}
@ -42,7 +43,7 @@ type Animation struct {
countDown int
}
//flags from cmd line
// 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")
@ -56,7 +57,7 @@ var (
led_slowdown_gpio = flag.Int("led-slowdown-gpio", 1, "GPIO pin slowdown")
)
//listens on topic for messages
// listens on topic for messages
func listener(mqMessages chan mqtt.Message) {
opts := setupMQTT()
client := MQTT.NewClient(opts)
@ -72,19 +73,19 @@ func listener(mqMessages chan mqtt.Message) {
})
}
//animator is a wrapping function for go routine that can receive an mq channel
// animator is a wrapping function for go routine that can receive an mq channel
func animator(tk *rgbmatrix.ToolKit, mqMessages chan mqtt.Message) {
//Playanimation comes from the toolkit, all it takes is an animation struct
tk.PlayAnimation(NewAnimation(image.Point{128, 64}, mqMessages))
}
//connection lost management
// connection lost management
func onConnectionLostHandler(c MQTT.Client, reason error) {
log.Fatalf(reason.Error())
}
//setup connection to mqtt, topic to listen to, qos
// setup connection to mqtt, topic to listen to, qos
func setupMQTT() *mqtt.ClientOptions {
opts := MQTT.NewClientOptions()
opts.AddBroker(fmt.Sprintf("tcp://%s:%s", os.Getenv("MQTTBROKER"), os.Getenv("MQTTPORT")))
@ -97,19 +98,19 @@ func setupMQTT() *mqtt.ClientOptions {
return opts
}
//runs before main, parses flags
// runs before main, parses flags
func init() {
flag.Parse()
}
//small function for handling fatal errors
// small function for handling fatal errors
func fatal(err error) {
if err != nil {
panic(err)
}
}
//initializes the struct for the an play animation function, this could all be dumped into function that's wrapping go routine if I wanted
// initializes the struct for the an play animation function, this could all be dumped into function that's wrapping go routine if I wanted
func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation {
imageMap := make(map[string]image.Image)
reader, err := os.Open("marioUp.png")
@ -156,7 +157,7 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
a.animateMario()
if a.images["doorbell"] != nil {
if a.countDown > 0 {
a.ctx.DrawImageAnchored(a.image[2], 0, 0, 0, 0)
a.ctx.DrawImageAnchored(a.images["doorbell"], 0, 0, 0, 0)
a.countDown -= 50
} else {
//a.image = a.image[:len(a.image)-1]
@ -190,7 +191,7 @@ func (a *Animation) animateMario() {
}
}
//what mario does every frame
// what mario does every frame
func (a *Animation) updateMarioPosition() {
a.position.X += 1 * a.dir.X
a.position.Y += 1 * a.dir.Y

Loading…
Cancel
Save