From 15b9202bc6e77a7d2a3caf380f75dbb10e73b5bc Mon Sep 17 00:00:00 2001 From: Friedl Ulrich Date: Sat, 7 Feb 2015 22:45:12 +0100 Subject: [PATCH] Better mode handling --- rfm69handler.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/rfm69handler.go b/rfm69handler.go index 1feff8f..df9e52f 100644 --- a/rfm69handler.go +++ b/rfm69handler.go @@ -49,12 +49,12 @@ func (r *Device) Loop() (chan Data, chan int) { log.Print("transmit") log.Print(dataToTransmit) - err = r.SetMode(RF_OPMODE_TRANSMITTER) + err = r.writeReg(REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_00) if err != nil { log.Fatal(err) } - err = r.writeReg(REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_00) + err = r.SetMode(RF_OPMODE_TRANSMITTER) if err != nil { log.Fatal(err) } @@ -62,7 +62,12 @@ func (r *Device) Loop() (chan Data, chan int) { <-irq log.Print("transmit done") - err = r.SetMode(RF_OPMODE_RECEIVER) + err = r.SetMode(RF_OPMODE_STANDBY) + if err != nil { + log.Fatal(err) + } + + err = r.waitForMode() if err != nil { log.Fatal(err) } @@ -71,7 +76,22 @@ func (r *Device) Loop() (chan Data, chan int) { if err != nil { log.Fatal(err) } + err = r.SetMode(RF_OPMODE_RECEIVER) + if err != nil { + log.Fatal(err) + } case <-irq: + if r.mode != RF_OPMODE_RECEIVER { + continue + } + + flags, err := r.readReg(REG_IRQFLAGS2) + if err != nil { + return + } + if flags&RF_IRQFLAGS2_PAYLOADREADY == 0 { + continue + } data, err := r.readFifo() if err != nil {