From e5d10d77881255483ac9abbed9b95390b4f7fde3 Mon Sep 17 00:00:00 2001 From: Friedl Ulrich Date: Sat, 7 Feb 2015 11:27:05 +0100 Subject: [PATCH] Changed GPIO Implementation to "github.com/davecheney/gpio" --- rfm69d/rfm69d.go | 22 +++++----------------- rfm69device.go | 6 +++--- rfm69handler.go | 4 ++-- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/rfm69d/rfm69d.go b/rfm69d/rfm69d.go index 6402161..eaa9852 100644 --- a/rfm69d/rfm69d.go +++ b/rfm69d/rfm69d.go @@ -5,30 +5,18 @@ import ( "os" "os/signal" + "github.com/davecheney/gpio" "github.com/fulr/rfm69" - "github.com/kidoman/embd" - - _ "github.com/kidoman/embd/host/rpi" ) func main() { log.Print("Start") - if err := embd.InitGPIO(); err != nil { - panic(err) - } - defer embd.CloseGPIO() - - gpio, err := embd.NewDigitalPin(25) + pin, err := gpio.OpenPin(gpio.GPIO25, gpio.ModeInput) if err != nil { panic(err) } - defer gpio.Close() - - if err := gpio.SetDirection(embd.In); err != nil { - panic(err) - } - gpio.ActiveLow(false) + defer pin.Close() spiBus, err := rfm69.NewSPIDevice() if err != nil { @@ -36,7 +24,7 @@ func main() { } defer spiBus.Close() - rfm, err := rfm69.NewDevice(spiBus, gpio, 1, 10, true) + rfm, err := rfm69.NewDevice(spiBus, pin, 1, 10, true) if err != nil { log.Fatal(err) } @@ -50,7 +38,7 @@ func main() { quit := rfm.Loop() sigint := make(chan os.Signal, 1) - signal.Notify(sigint, os.Interrupt) + signal.Notify(sigint, os.Interrupt, os.Kill) for { select { diff --git a/rfm69device.go b/rfm69device.go index 0999327..fe20202 100644 --- a/rfm69device.go +++ b/rfm69device.go @@ -4,13 +4,13 @@ package rfm69 import ( "log" - "github.com/kidoman/embd" + "github.com/davecheney/gpio" ) // Device RFM69 Device type Device struct { SpiDevice *SPIDevice - gpio embd.DigitalPin + gpio gpio.Pin mode byte address byte network byte @@ -34,7 +34,7 @@ type Data struct { } // NewDevice creates a new device -func NewDevice(spi *SPIDevice, gpio embd.DigitalPin, nodeID, networkID byte, isRfm69HW bool) (*Device, error) { +func NewDevice(spi *SPIDevice, gpio gpio.Pin, nodeID, networkID byte, isRfm69HW bool) (*Device, error) { ret := &Device{ SpiDevice: spi, gpio: gpio, diff --git a/rfm69handler.go b/rfm69handler.go index b7117f9..d3c3573 100644 --- a/rfm69handler.go +++ b/rfm69handler.go @@ -3,7 +3,7 @@ package rfm69 import ( "log" - "github.com/kidoman/embd" + "github.com/davecheney/gpio" ) // Loop is the main receive and transmit handling loop @@ -13,7 +13,7 @@ func (r *Device) Loop() chan int { go func() { irq := make(chan int) - r.gpio.Watch(embd.EdgeRising, func(pin embd.DigitalPin) { + r.gpio.BeginWatch(gpio.EdgeRising, func() { irq <- 1 })