commit efe8866f28f229446440c6d871e4f9845a97266f
parent f20896ef3b147ac07769eb36c67ba436c6d2ed22
Author: Martin Ashby <martin@martin-laptop.lan>
Date: Mon, 28 May 2018 16:57:07 +0100
Added build tags. Builds & runs OK on RPi (can show test animation)
Diffstat:
4 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/unicorn/BaseFakeUnicorn.go b/unicorn/BaseFakeUnicorn.go
@@ -1,3 +1,5 @@
+// +build linux,386 linux,amd64
+
package unicorn
import "github.com/veandco/go-sdl2/sdl"
diff --git a/unicorn/FakeUnicorn2.go b/unicorn/FakeUnicorn2.go
@@ -1,3 +1,5 @@
+// +build linux,386 linux,amd64
+
package unicorn
import (
@@ -37,6 +39,10 @@ func (u *FakeUnicorn2) renderImage(im image.Image) {
u.renderer.Present()
}
+func (u *FakeUnicorn2) StartRender() chan bool {
+ return u.StartRenderBase(u.renderImage)
+}
+
func NewUnicorn2() (*FakeUnicorn2, error) {
baseFake, err := NewBaseFakeUnicorn(300, 300)
if err != nil {
diff --git a/unicorn/RealUnicorn2.go b/unicorn/RealUnicorn2.go
@@ -60,6 +60,12 @@ func NewUnicorn2() (*RealUnicorn2, error) {
}, nil
}
+// StartRender ...
+// Passes through to base to actually do the render
+func (u *RealUnicorn2) StartRender() chan bool {
+ return u.StartRenderBase(u.renderImage)
+}
+
// MainLoop ...
// Just blocks until sigterm
func (u *RealUnicorn2) MainLoop() {
diff --git a/unicorn/Unicorn2.go b/unicorn/Unicorn2.go
@@ -42,11 +42,9 @@ func (u *BaseUnicorn2) SetGif(g *gif.GIF) {
u.g = g
}
-// StartRender ...
-// Starts rendering the image. If it's an animated image,
-// renders animation frames. Return a channel to stop the
-// image rendering.
-func (u *FakeUnicorn2) StartRender() chan bool {
+// StartRenderBase ...
+// Deals with the timing aspect of animated GIFs
+func (u *BaseUnicorn2) StartRenderBase(renderImage func(image.Image)) chan bool {
stopChan := make(chan bool)
go func() {
timer := time.NewTimer(0)
@@ -61,12 +59,12 @@ func (u *FakeUnicorn2) StartRender() chan bool {
gf := u.GetGif()
im := gf.Image[imageIndex]
delay := gf.Delay[imageIndex] //100ths of a second, 10^-2
- u.renderImage(im)
-
+ renderImage(im)
+
timer.Reset(time.Duration(delay * 10000000)) // nanoseconds 10^-9 sec
imageIndex = (imageIndex + 1) % len(gf.Image)
}
}
}()
return stopChan
-}
-\ No newline at end of file
+}