diff options
author | Martin Ashby <martin@martin-laptop.lan> | 2018-05-21 10:16:53 +0100 |
---|---|---|
committer | Martin Ashby <martin@martin-laptop.lan> | 2018-05-21 10:16:53 +0100 |
commit | 042cfafc7dc2abac8f6ddb111a948aa1d9784811 (patch) | |
tree | e7116ef1bd99ca06f7918a8a6e8dbe46f215f4ce | |
parent | 34f1a11454fc38a77338569f466df879fd1792f7 (diff) | |
download | unicornpaint-042cfafc7dc2abac8f6ddb111a948aa1d9784811.tar.gz unicornpaint-042cfafc7dc2abac8f6ddb111a948aa1d9784811.tar.bz2 unicornpaint-042cfafc7dc2abac8f6ddb111a948aa1d9784811.tar.xz unicornpaint-042cfafc7dc2abac8f6ddb111a948aa1d9784811.zip |
Added mainloop
-rw-r--r-- | unicorn/FakeUnicorn.go | 16 | ||||
-rw-r--r-- | unicorn/RealUnicorn.go | 15 | ||||
-rw-r--r-- | unicorn/Unicorn.go | 3 |
3 files changed, 30 insertions, 4 deletions
diff --git a/unicorn/FakeUnicorn.go b/unicorn/FakeUnicorn.go index 85833c9..eaec4f2 100644 --- a/unicorn/FakeUnicorn.go +++ b/unicorn/FakeUnicorn.go @@ -96,3 +96,19 @@ func (f *FakeUnicorn) Show() { func (f *FakeUnicorn) Off() { f.Close() } + +// MainLoop ... +// Handle UI events so OS doesn't think we're frozen +func (f *FakeUnicorn) MainLoop() { + running := true + for running { + for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { + switch event.(type) { + case *sdl.QuitEvent: + println("Quit") + running = false + break + } + } + } +} diff --git a/unicorn/RealUnicorn.go b/unicorn/RealUnicorn.go index 4e5c376..fb10a79 100644 --- a/unicorn/RealUnicorn.go +++ b/unicorn/RealUnicorn.go @@ -3,10 +3,9 @@ package unicorn import ( - //"golang.org/x/exp/io/spi" - "log" - "github.com/ecc1/spi" + "log" + "os" ) type RealUnicorn struct { @@ -50,7 +49,6 @@ func (u *RealUnicorn) Show() { } } // Write to the device - //err := u.device.Tx(write, nil) err := u.device.Transfer(write) if err != nil { log.Printf("Error writing to SPI device %v", err) @@ -64,3 +62,12 @@ func (u *RealUnicorn) Off() { func (u *RealUnicorn) Close() error { return u.device.Close() } + +// MainLoop ... +// Do nothing until SIGTERM, then close the SPI library +func MainLoop() { + c := make(chan os.Signal, 2) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) + <- c + Close() +} diff --git a/unicorn/Unicorn.go b/unicorn/Unicorn.go index 8a2b68d..07fa3c2 100644 --- a/unicorn/Unicorn.go +++ b/unicorn/Unicorn.go @@ -21,6 +21,9 @@ type Unicorn interface { // Turns off the LEDs Off() + + // Unicorn needs to be in charge of the main thread + MainLoop() } // GetUnicorn ... |