|
|
@ -2,6 +2,7 @@ package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"flag"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"image"
|
|
|
|
"image"
|
|
|
|
"image/color"
|
|
|
|
"image/color"
|
|
|
|
_ "image/jpeg"
|
|
|
|
_ "image/jpeg"
|
|
|
@ -11,9 +12,23 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
rgbmatrix "gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix"
|
|
|
|
rgbmatrix "gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix"
|
|
|
|
"github.com/disintegration/imaging"
|
|
|
|
"github.com/disintegration/imaging"
|
|
|
|
|
|
|
|
MQTT "github.com/eclipse/paho.mqtt.golang"
|
|
|
|
|
|
|
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
|
|
|
"github.com/fogleman/gg"
|
|
|
|
"github.com/fogleman/gg"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type Animation struct {
|
|
|
|
|
|
|
|
ctx *gg.Context
|
|
|
|
|
|
|
|
position image.Point
|
|
|
|
|
|
|
|
dir image.Point
|
|
|
|
|
|
|
|
height int
|
|
|
|
|
|
|
|
width int
|
|
|
|
|
|
|
|
stroke int
|
|
|
|
|
|
|
|
image []image.Image
|
|
|
|
|
|
|
|
updown int
|
|
|
|
|
|
|
|
msg chan mqtt.Message
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
@ -37,7 +52,7 @@ func main() {
|
|
|
|
config.ShowRefreshRate = *show_refresh
|
|
|
|
config.ShowRefreshRate = *show_refresh
|
|
|
|
config.InverseColors = *inverse_colors
|
|
|
|
config.InverseColors = *inverse_colors
|
|
|
|
config.DisableHardwarePulsing = *disable_hardware_pulsing
|
|
|
|
config.DisableHardwarePulsing = *disable_hardware_pulsing
|
|
|
|
|
|
|
|
setupMQTT()
|
|
|
|
/*bounds := mario.Bounds()
|
|
|
|
/*bounds := mario.Bounds()
|
|
|
|
var histogram [16][4]int
|
|
|
|
var histogram [16][4]int
|
|
|
|
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
|
|
|
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
|
|
@ -53,13 +68,39 @@ func main() {
|
|
|
|
}*/
|
|
|
|
}*/
|
|
|
|
m, err := rgbmatrix.NewRGBLedMatrix(config)
|
|
|
|
m, err := rgbmatrix.NewRGBLedMatrix(config)
|
|
|
|
fatal(err)
|
|
|
|
fatal(err)
|
|
|
|
|
|
|
|
mqMessages := make(chan mqtt.Message)
|
|
|
|
|
|
|
|
go listener(mqMessages)
|
|
|
|
tk := rgbmatrix.NewToolKit(m)
|
|
|
|
tk := rgbmatrix.NewToolKit(m)
|
|
|
|
defer tk.Close()
|
|
|
|
defer tk.Close()
|
|
|
|
|
|
|
|
go animator(tk, mqMessages)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func listener(mqMessages chan mqtt.Message) {
|
|
|
|
|
|
|
|
opts := setupMQTT()
|
|
|
|
|
|
|
|
client := MQTT.NewClient(opts)
|
|
|
|
|
|
|
|
topic := "home/rgbboard"
|
|
|
|
|
|
|
|
if token := client.Connect(); token.Wait() && token.Error() != nil {
|
|
|
|
|
|
|
|
panic(token.Error())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
client.Subscribe(topic, 0, func(client mqtt.Client, msg mqtt.Message) {
|
|
|
|
|
|
|
|
log.Println("Receiving ", string(msg.Payload()), " on topic: ", msg.Topic())
|
|
|
|
|
|
|
|
mqMessages <- msg
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func animator(tk *rgbmatrix.ToolKit, mqMessages chan mqtt.Message) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tk.PlayAnimation(NewAnimation(image.Point{64, 32}, mqMessages))
|
|
|
|
|
|
|
|
|
|
|
|
tk.PlayAnimation(NewAnimation(image.Point{64, 32}))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func setupMQTT() *mqtt.ClientOptions {
|
|
|
|
|
|
|
|
opts := MQTT.NewClientOptions()
|
|
|
|
|
|
|
|
opts.AddBroker(fmt.Sprintf("tcp://%s:%s", os.Getenv("MQTTBROKER"), os.Getenv("MQTTPORT")))
|
|
|
|
|
|
|
|
opts.SetUsername(os.Getenv("MQTTUSER"))
|
|
|
|
|
|
|
|
opts.SetPassword(os.Getenv("MQTTPASS"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return opts
|
|
|
|
|
|
|
|
}
|
|
|
|
func init() {
|
|
|
|
func init() {
|
|
|
|
flag.Parse()
|
|
|
|
flag.Parse()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -70,18 +111,7 @@ func fatal(err error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type Animation struct {
|
|
|
|
func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation {
|
|
|
|
ctx *gg.Context
|
|
|
|
|
|
|
|
position image.Point
|
|
|
|
|
|
|
|
dir image.Point
|
|
|
|
|
|
|
|
height int
|
|
|
|
|
|
|
|
width int
|
|
|
|
|
|
|
|
stroke int
|
|
|
|
|
|
|
|
image []image.Image
|
|
|
|
|
|
|
|
updown int
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func NewAnimation(sz image.Point) *Animation {
|
|
|
|
|
|
|
|
reader, err := os.Open("marioUp.png")
|
|
|
|
reader, err := os.Open("marioUp.png")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
log.Fatal(err)
|
|
|
@ -107,6 +137,7 @@ func NewAnimation(sz image.Point) *Animation {
|
|
|
|
stroke: 8,
|
|
|
|
stroke: 8,
|
|
|
|
image: images,
|
|
|
|
image: images,
|
|
|
|
updown: 0,
|
|
|
|
updown: 0,
|
|
|
|
|
|
|
|
msg: mqMessages,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -114,16 +145,17 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
|
|
|
|
defer a.updatePosition()
|
|
|
|
defer a.updatePosition()
|
|
|
|
a.ctx.SetColor(color.Black)
|
|
|
|
a.ctx.SetColor(color.Black)
|
|
|
|
a.ctx.Clear()
|
|
|
|
a.ctx.Clear()
|
|
|
|
//a.ctx.SetColor(color.RGBA{0, 255, 0, 255})
|
|
|
|
|
|
|
|
//a.ctx.DrawCircle(float64(8), float64(8), float64(a.stroke))
|
|
|
|
|
|
|
|
//a.ctx.Fill()
|
|
|
|
|
|
|
|
if a.dir.X == 1 {
|
|
|
|
if a.dir.X == 1 {
|
|
|
|
a.ctx.DrawImageAnchored(a.image[a.updown], a.position.X, a.position.Y, 0.5, 0.5)
|
|
|
|
a.ctx.DrawImageAnchored(a.image[a.updown], a.position.X, a.position.Y, 0.5, 0.5)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
a.ctx.DrawImageAnchored(imaging.FlipH(a.image[a.updown]), a.position.X, a.position.Y, 0.5, 0.5)
|
|
|
|
a.ctx.DrawImageAnchored(imaging.FlipH(a.image[a.updown]), a.position.X, a.position.Y, 0.5, 0.5)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a.ctx.SetColor(color.White)
|
|
|
|
a.ctx.SetColor(color.White)
|
|
|
|
a.ctx.DrawString("mario", 5, 9)
|
|
|
|
select {
|
|
|
|
|
|
|
|
case msg := <-a.msg:
|
|
|
|
|
|
|
|
a.ctx.DrawString(string(msg.Payload()), 5, 9)
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
}
|
|
|
|
return a.ctx.Image(), time.After(time.Millisecond * 50), nil
|
|
|
|
return a.ctx.Image(), time.After(time.Millisecond * 50), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|