addingMQ #2

Merged
nathan merged 4 commits from addingMQ into master 2 years ago

@ -3,15 +3,15 @@ from registry.local/rgbarm64lib:latest as builder
workdir /usr/src/app/rgb
COPY . .
RUN go mod tidy
#RUN CGO_ENABLED=1 CC=musl-gcc go build --ldflags 'linkmode external -extldflags "-static"'
RUN go build .
RUN CGO_ENABLED=1 go build --ldflags '-linkmode external -extldflags=-static'
#RUN go build .
RUN mkdir -p /usr/src/app/work/
RUN cp /usr/src/app/rgb/rgb /usr/src/app/work/rgb
RUN cp /usr/src/app/rgb/mario* /usr/src/app/work/
#FROM alpine:latest
FROM alpine:latest
#COPY --from=builder /usr/src/app/rgb/rgb /usr/src/app/work/
COPY --from=builder /usr/src/app/rgb/rgb /usr/src/app/work/

@ -5,6 +5,7 @@ go 1.18
require (
gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix v0.0.0-20220709235716-bf87ebdb3e55
github.com/disintegration/imaging v1.6.2
github.com/eclipse/paho.mqtt.golang v1.4.2
github.com/fogleman/gg v1.3.0
)
@ -12,12 +13,15 @@ require (
dmitri.shuralyov.com/gpu/mtl v0.0.0-20201218220906-28db891af037 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/jezek/xgb v1.0.0 // indirect
golang.org/x/exp/shiny v0.0.0-20220713135740-79cabaa25d75 // indirect
golang.org/x/image v0.0.0-20220617043117-41969df76e82 // indirect
golang.org/x/mobile v0.0.0-20220518205345-8578da9835fd // indirect
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
replace gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix v0.0.0-20220709235716-bf87ebdb3e55 => /usr/src/app
//replace gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix v0.0.0-20220709235716-bf87ebdb3e55 => /usr/src/app

@ -5,12 +5,16 @@ gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix v0.0.0-202207092
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
github.com/eclipse/paho.mqtt.golang v1.4.2 h1:66wOzfUHSSI1zamx7jR6yMEI5EuHnT1G6rNA5PM12m4=
github.com/eclipse/paho.mqtt.golang v1.4.2/go.mod h1:JGt0RsEwEX+Xa/agj90YJ9d9DH2b7upDZMK9HRbFvCA=
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4 h1:WtGNWLvXpe6ZudgnXrq0barxBImvnnJoMEhXAzcbM0I=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jezek/xgb v1.0.0 h1:s2rRzAV8KQRlpsYA7Uyxoidv1nodMF0m6dIG6FhhVLQ=
github.com/jezek/xgb v1.0.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
@ -38,11 +42,15 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d h1:20cMwl2fHAzkJMEA+8J4JgqBQcQGzbisXo31MIeenXI=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

@ -2,6 +2,7 @@ package main
import (
"flag"
"fmt"
"image"
"image/color"
_ "image/jpeg"
@ -11,9 +12,23 @@ import (
rgbmatrix "gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix"
"github.com/disintegration/imaging"
MQTT "github.com/eclipse/paho.mqtt.golang"
mqtt "github.com/eclipse/paho.mqtt.golang"
"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 (
rows = flag.Int("led-rows", 32, "number of rows supported")
cols = flag.Int("led-cols", 32, "number of columns supported")
@ -37,7 +52,7 @@ func main() {
config.ShowRefreshRate = *show_refresh
config.InverseColors = *inverse_colors
config.DisableHardwarePulsing = *disable_hardware_pulsing
setupMQTT()
/*bounds := mario.Bounds()
var histogram [16][4]int
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
@ -53,13 +68,39 @@ func main() {
}*/
m, err := rgbmatrix.NewRGBLedMatrix(config)
fatal(err)
mqMessages := make(chan mqtt.Message)
go listener(mqMessages)
tk := rgbmatrix.NewToolKit(m)
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() {
flag.Parse()
}
@ -70,18 +111,7 @@ func fatal(err error) {
}
}
type Animation struct {
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 {
func NewAnimation(sz image.Point, mqMessages chan mqtt.Message) *Animation {
reader, err := os.Open("marioUp.png")
if err != nil {
log.Fatal(err)
@ -107,6 +137,7 @@ func NewAnimation(sz image.Point) *Animation {
stroke: 8,
image: images,
updown: 0,
msg: mqMessages,
}
}
@ -114,16 +145,17 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) {
defer a.updatePosition()
a.ctx.SetColor(color.Black)
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 {
a.ctx.DrawImageAnchored(a.image[a.updown], a.position.X, a.position.Y, 0.5, 0.5)
} else {
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.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
}

Loading…
Cancel
Save