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 }