From 2ef3182af5118bc170f5e42c458e2c2c16288e6c Mon Sep 17 00:00:00 2001 From: Kevin Wallace Date: Thu, 5 Mar 2026 20:18:45 -0800 Subject: beep when you press the button Polls PIC32 ignition button state, tells the cVEND to beep. --- cmd/beep/main.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 cmd/beep/main.go (limited to 'cmd') diff --git a/cmd/beep/main.go b/cmd/beep/main.go new file mode 100644 index 0000000..56263d5 --- /dev/null +++ b/cmd/beep/main.go @@ -0,0 +1,42 @@ +package main + +import ( + "encoding/binary" + "time" + + "pm3.dev/cvend" + "pm3.dev/pic32" +) + +func must[V any](v V, err error) V { + if err != nil { + panic(err) + } + return v +} + +func main() { + cv := must(cvend.OpenIPP(nil)) + defer cv.Close() + var lastIgnition bool + pic := must(pic32.OpenIPP(func(msgType byte, msgData []byte) { + if msgType == 0x03 && binary.BigEndian.Uint16(msgData[:2]) == 0x03fb { + ignition := msgData[2] != 0 + if lastIgnition != ignition { + lastIgnition = ignition + if ignition { + if err := cv.SendIPP(0x22, []byte{0x06, 0x00, 0x01, 0x00}); err != nil { + panic(err) + } + } + } + } + })) + defer pic.Close() + for { + if err := pic.SendIPP(0x02, []byte{0x03, 0xfb}); err != nil { + panic(err) + } + time.Sleep(100 * time.Millisecond) + } +} -- cgit v1.2.3