From 11a0f85c9f7a66be2dcfd35bbe0dfc6fc646364c Mon Sep 17 00:00:00 2001 From: Gregor Riepl Date: Wed, 5 May 2021 23:13:02 +0200 Subject: [PATCH] Roll display print loop --- uncanny/display.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/uncanny/display.go b/uncanny/display.go index 42e0cfe..f7081ba 100644 --- a/uncanny/display.go +++ b/uncanny/display.go @@ -28,16 +28,10 @@ func (c *Can) DisplayWrite(line int, a []byte) error { default: return errors.New("Invalid line") } - // print in 3 chunks, as one frame is limited to 8 bytes + // print in separate chunks, as one frame payload is limited to 7 bytes // the display has only 16 characters per line, so we truncate there - if len(a) > 0 { - return c.bus.Publish(DisplayCommand{addr, a[:7]}.Encode()) - } - if len(a) > 7 { - return c.bus.Publish(DisplayCommand{addr, a[7:14]}.Encode()) - } - if len(a) > 14 { - return c.bus.Publish(DisplayCommand{addr, a[14:16]}.Encode()) + for i := 0; i < len(a) && i < 16; i += 7 { + return c.bus.Publish(DisplayCommand{addr, a[i:i+7]}.Encode()) } return nil }