From 22315fbe47e5b99b9674917d6fde305e5a551771 Mon Sep 17 00:00:00 2001 From: Gregor Riepl Date: Sun, 31 Jan 2021 18:30:22 +0100 Subject: [PATCH] Fetch status on startup --- uncanny/can.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/uncanny/can.go b/uncanny/can.go index 5fbdaf1..6faabb7 100644 --- a/uncanny/can.go +++ b/uncanny/can.go @@ -28,8 +28,9 @@ func NewCan(intf string) (*Can, error) { func (c *Can) Start() { go func() { - // send the init sequence - c.initialize() + // send the init sequence, but (hopefully) defer until after we start listening + // FIXME this is inherently racy :( + go c.initialize() // ConnectAndPublish will block, so we'll just leave the Printf hanging here log.Printf("CAN bus shut down: %v", c.bus.ConnectAndPublish()) }() @@ -113,7 +114,9 @@ func (c *Can) Cancel() error { return c.bus.Publish(DispenseMessage{DispenseSlotOff}.Encode()) } -func (c *Can) initialize() error { +func (c *Can) initialize() { // enable automatic status updates - return c.bus.Publish(AutoMessage{true}.Encode()) + c.bus.Publish(AutoMessage{true}.Encode()) + c.bus.Publish(RequestFeedbackMessage()) + c.bus.Publish(RequestPowerMessage()) }