Changed GPIO Implementation to "github.com/davecheney/gpio"

master
Friedl Ulrich 10 years ago
parent dd8bde5239
commit e5d10d7788

@ -5,30 +5,18 @@ import (
"os" "os"
"os/signal" "os/signal"
"github.com/davecheney/gpio"
"github.com/fulr/rfm69" "github.com/fulr/rfm69"
"github.com/kidoman/embd"
_ "github.com/kidoman/embd/host/rpi"
) )
func main() { func main() {
log.Print("Start") log.Print("Start")
if err := embd.InitGPIO(); err != nil { pin, err := gpio.OpenPin(gpio.GPIO25, gpio.ModeInput)
panic(err)
}
defer embd.CloseGPIO()
gpio, err := embd.NewDigitalPin(25)
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer gpio.Close() defer pin.Close()
if err := gpio.SetDirection(embd.In); err != nil {
panic(err)
}
gpio.ActiveLow(false)
spiBus, err := rfm69.NewSPIDevice() spiBus, err := rfm69.NewSPIDevice()
if err != nil { if err != nil {
@ -36,7 +24,7 @@ func main() {
} }
defer spiBus.Close() defer spiBus.Close()
rfm, err := rfm69.NewDevice(spiBus, gpio, 1, 10, true) rfm, err := rfm69.NewDevice(spiBus, pin, 1, 10, true)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -50,7 +38,7 @@ func main() {
quit := rfm.Loop() quit := rfm.Loop()
sigint := make(chan os.Signal, 1) sigint := make(chan os.Signal, 1)
signal.Notify(sigint, os.Interrupt) signal.Notify(sigint, os.Interrupt, os.Kill)
for { for {
select { select {

@ -4,13 +4,13 @@ package rfm69
import ( import (
"log" "log"
"github.com/kidoman/embd" "github.com/davecheney/gpio"
) )
// Device RFM69 Device // Device RFM69 Device
type Device struct { type Device struct {
SpiDevice *SPIDevice SpiDevice *SPIDevice
gpio embd.DigitalPin gpio gpio.Pin
mode byte mode byte
address byte address byte
network byte network byte
@ -34,7 +34,7 @@ type Data struct {
} }
// NewDevice creates a new device // 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{ ret := &Device{
SpiDevice: spi, SpiDevice: spi,
gpio: gpio, gpio: gpio,

@ -3,7 +3,7 @@ package rfm69
import ( import (
"log" "log"
"github.com/kidoman/embd" "github.com/davecheney/gpio"
) )
// Loop is the main receive and transmit handling loop // Loop is the main receive and transmit handling loop
@ -13,7 +13,7 @@ func (r *Device) Loop() chan int {
go func() { go func() {
irq := make(chan int) irq := make(chan int)
r.gpio.Watch(embd.EdgeRising, func(pin embd.DigitalPin) { r.gpio.BeginWatch(gpio.EdgeRising, func() {
irq <- 1 irq <- 1
}) })

Loading…
Cancel
Save