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/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 {

@ -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,

@ -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
})

Loading…
Cancel
Save