adding MQ
Some checks failed
rgb/pipeline/head There was a failure building this commit
wyze_sensor/pipeline/head Build queued...

This commit is contained in:
Nathan
2023-01-08 22:56:24 +00:00
parent 0da2344f4c
commit c7f4f17242
4 changed files with 85 additions and 16 deletions

43
main.go
View File

@@ -2,6 +2,7 @@ package main
import (
"flag"
"fmt"
"image"
"image/color"
_ "image/jpeg"
@@ -11,9 +12,21 @@ import (
rgbmatrix "gitea.wagshome.duckdns.org/publicWagsHome/go-rpi-rgb-led-matrix"
"github.com/disintegration/imaging"
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
}
var (
rows = flag.Int("led-rows", 32, "number of rows supported")
cols = flag.Int("led-cols", 32, "number of columns supported")
@@ -37,7 +50,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++ {
@@ -60,6 +73,20 @@ func main() {
tk.PlayAnimation(NewAnimation(image.Point{64, 32}))
}
func setupMQTT() {
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"))
opts.SetDefaultPublishHandler(messagePubHandler)
opts.OnConnect = connectHandler
opts.OnConnectionLost = connectLostHandler
client := MQTT.NewClient(opts)
if token := client.Connect(); token.Wait() && token.Error() != nil {
panic(token.Error())
}
}
func init() {
flag.Parse()
}
@@ -70,17 +97,6 @@ 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 {
reader, err := os.Open("marioUp.png")
if err != nil {
@@ -114,9 +130,6 @@ 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 {