From 042cfafc7dc2abac8f6ddb111a948aa1d9784811 Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Mon, 21 May 2018 10:16:53 +0100 Subject: Added mainloop --- unicorn/RealUnicorn.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'unicorn/RealUnicorn.go') 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() +} -- cgit v1.2.3-ZIG