timeout in waitForMode

master
Friedl Ulrich 9 years ago
parent 582954a052
commit f89e07539a

@ -2,7 +2,9 @@
package rfm69 package rfm69
import ( import (
"errors"
"log" "log"
"time"
"github.com/davecheney/gpio" "github.com/davecheney/gpio"
"github.com/fulr/spidev" "github.com/fulr/spidev"
@ -175,16 +177,24 @@ func (r *Device) setup() error {
} }
func (r *Device) waitForMode() error { func (r *Device) waitForMode() error {
for { errChan := make(chan error)
reg, err := r.readReg(REG_IRQFLAGS1) go func() {
if err != nil { for {
return err reg, err := r.readReg(REG_IRQFLAGS1)
} if err != nil {
if reg&RF_IRQFLAGS1_MODEREADY != 0 { errChan <- err
break break
}
if reg&RF_IRQFLAGS1_MODEREADY != 0 {
errChan <- nil
break
}
} }
} }()
return nil time.AfterFunc(5*time.Second, func() {
errChan <- errors.New("timeout")
})
return <-errChan
} }
// Encrypt sets the encryption key and enables AES encryption // Encrypt sets the encryption key and enables AES encryption

Loading…
Cancel
Save