master
Friedl Ulrich 10 years ago
parent 1dc12ff5c1
commit 82fc95a00d

@ -67,11 +67,11 @@ func (r *Device) readReg(addr byte) (byte, error) {
tx := make([]uint8, 2)
tx[0] = addr & 0x7f
tx[1] = 0
log.Printf("read %x", addr)
rx, err := r.SpiDevice.Xfer(tx)
if err != nil {
log.Println(err)
}
log.Printf("read %x: %x", addr, rx[1])
return rx[1], err
}
@ -322,8 +322,7 @@ func (r *Device) readRSSI(forceTrigger bool) (rssi int, err error) {
}
}
}
var data byte
data, err = r.readReg(REG_RSSIVALUE)
data, err := r.readReg(REG_RSSIVALUE)
if err != nil {
return
}

@ -84,10 +84,8 @@ int spi_xfer(int fd, char* tx, char* rx, int length) {
}
*/
import "C"
import (
"log"
"unsafe"
)
import "unsafe"
import "errors"
// SPIDevice device
@ -110,9 +108,9 @@ func NewSPIDevice() (*SPIDevice, error) {
func (d *SPIDevice) Xfer(tx []byte) ([]byte, error) {
length := len(tx)
rx := make([]byte, length)
log.Print("sending", tx)
//log.Print("sending", tx)
ret := C.spi_xfer(d.fd, (*C.char)(unsafe.Pointer(&tx[0])), (*C.char)(unsafe.Pointer(&rx[0])), C.int(length))
log.Print("got", rx)
//log.Print("got", rx)
if ret < 0 {
return nil, errors.New("could not xfer")
}

Loading…
Cancel
Save