From d574df99385e6fe8bdfed7bbc1eef658ab32602b Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Fri, 16 Feb 2024 04:41:58 +0000 Subject: [PATCH] split out msg receiver --- board.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/board.go b/board.go index 20fb325..d17960e 100644 --- a/board.go +++ b/board.go @@ -43,14 +43,9 @@ func animate(sz image.Point, mqMessages chan mqtt.Message) *Animation { }, } } -func (a *Animation) Next() (image.Image, <-chan time.Time, error) { + +func (a *Animation) useMsg() { var incoming incomingMessage - switch { - case a.doorbell != (Doorbell{}): - a.animateDoorbell() - default: - a.animateMario() - } select { case msg := <-a.mqmsg: json.Unmarshal([]byte(string(msg.Payload())), &incoming) @@ -62,5 +57,15 @@ func (a *Animation) Next() (image.Image, <-chan time.Time, error) { } default: } +} + +func (a *Animation) Next() (image.Image, <-chan time.Time, error) { + switch { + case a.doorbell != (Doorbell{}): + a.animateDoorbell() + default: + a.animateMario() + } + a.useMsg() return a.ctx.Image(), time.After(time.Millisecond * 50), nil }