You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
983 B
Go

package main
import (
"log"
"os"
10 years ago
"os/signal"
10 years ago
"time"
"github.com/davecheney/gpio"
"github.com/fulr/rfm69"
)
func main() {
log.Print("Start")
pin, err := gpio.OpenPin(gpio.GPIO25, gpio.ModeInput)
if err != nil {
panic(err)
}
defer pin.Close()
spiBus, err := rfm69.NewSPIDevice()
if err != nil {
panic(err)
}
defer spiBus.Close()
10 years ago
rfm, err := rfm69.NewDevice(spiBus, pin, 1, 10, false)
if err != nil {
10 years ago
log.Fatal(err)
}
log.Print(rfm)
err = rfm.Encrypt([]byte("0123456789012345"))
10 years ago
if err != nil {
log.Fatal(err)
}
10 years ago
rxChan, txChan, quit := rfm.Loop()
sigint := make(chan os.Signal, 1)
signal.Notify(sigint, os.Interrupt, os.Kill)
for {
select {
case data := <-rxChan:
log.Print("main got data")
log.Print(data)
case <-sigint:
quit <- 1
<-quit
return
10 years ago
case <-time.After(3 * time.Second):
10 years ago
txChan <- rfm69.Data{
ToAddress: 99,
FromAddress: 1,
Data: []byte{1, 2, 3},
RequestAck: true,
}
}
}
}