diff --git a/sx126x/sx126x.go b/sx126x/sx126x.go index db814a0..0cee91b 100644 --- a/sx126x/sx126x.go +++ b/sx126x/sx126x.go @@ -702,25 +702,33 @@ func (d *Device) HandleInterrupt() { d.ClearIrqStatus(SX126X_IRQ_ALL) if (st & SX126X_IRQ_RX_DONE) > 0 { - e := lora.RadioEvent{lora.RadioEventRxDone, uint16(st), nil} - d.radioEventChan <- e + select { + case d.radioEventChan <- lora.RadioEvent{lora.RadioEventRxDone, uint16(st), nil}: + default: + } } if (st & SX126X_IRQ_TX_DONE) > 0 { - e := lora.RadioEvent{lora.RadioEventTxDone, uint16(st), nil} - d.radioEventChan <- e + select { + case d.radioEventChan <- lora.RadioEvent{lora.RadioEventTxDone, uint16(st), nil}: + default: + } } if (st & SX126X_IRQ_TIMEOUT) > 0 { - e := lora.RadioEvent{lora.RadioEventTimeout, uint16(st), nil} - d.radioEventChan <- e + select { + case d.radioEventChan <- lora.RadioEvent{lora.RadioEventTimeout, uint16(st), nil}: + default: + } } if (st & SX126X_IRQ_CRC_ERR) > 0 { - e := lora.RadioEvent{lora.RadioEventCrcError, uint16(st), nil} - d.radioEventChan <- e + select { + case d.radioEventChan <- lora.RadioEvent{lora.RadioEventCrcError, uint16(st), nil}: + default: + } } } diff --git a/sx127x/sx127x.go b/sx127x/sx127x.go index 60d5b44..bced11a 100644 --- a/sx127x/sx127x.go +++ b/sx127x/sx127x.go @@ -16,7 +16,7 @@ import ( // So we can keep track of the origin of interruption const ( RADIOEVENTCHAN_SIZE = 1 - SPI_BUFFER_SIZE = 256 + SPI_BUFFER_SIZE = 5 ) // Device wraps an SPI connection to a SX127x device. @@ -86,13 +86,10 @@ func (d *Device) ReadRegister(reg uint8) uint8 { //d.spiTxBuf = []byte{reg & 0x7f} d.spiTxBuf = d.spiTxBuf[:0] d.spiTxBuf = append(d.spiTxBuf, byte(reg&0x7f)) - //println("R1 : ", len(d.spiTxBuf)) d.spi.Tx(d.spiTxBuf, nil) // Read value - //d.spiRxBuf = []byte{reg & 0x00} d.spiRxBuf = d.spiRxBuf[:0] d.spiRxBuf = append(d.spiRxBuf, 0) - //println("R2 : ", len(d.spiTxBuf)) d.spi.Tx(nil, d.spiRxBuf) d.controller.SetNss(true) return d.spiRxBuf[0] @@ -529,27 +526,29 @@ func (d *Device) HandleInterrupt() { d.WriteRegister(SX127X_REG_IRQ_FLAGS, 0xFF) if (st & SX127X_IRQ_LORA_RXDONE_MASK) > 0 { - e := lora.RadioEvent{lora.RadioEventRxDone, uint16(st), nil} - d.radioEventChan <- e + select { + case d.radioEventChan <- lora.RadioEvent{lora.RadioEventRxDone, uint16(st), nil}: + default: + } } if (st & SX127X_IRQ_LORA_TXDONE_MASK) > 0 { - e := lora.RadioEvent{lora.RadioEventTxDone, uint16(st), nil} - d.radioEventChan <- e + select { + case d.radioEventChan <- lora.RadioEvent{lora.RadioEventTxDone, uint16(st), nil}: + default: + } } if (st & SX127X_IRQ_LORA_RXTOUT_MASK) > 0 { - e := lora.RadioEvent{lora.RadioEventTimeout, uint16(st), nil} select { - case d.radioEventChan <- e: + case d.radioEventChan <- lora.RadioEvent{lora.RadioEventTimeout, uint16(st), nil}: default: } } if (st & SX127X_IRQ_LORA_CRCERR_MASK) > 0 { - e := lora.RadioEvent{lora.RadioEventCrcError, uint16(st), nil} select { - case d.radioEventChan <- e: + case d.radioEventChan <- lora.RadioEvent{lora.RadioEventCrcError, uint16(st), nil}: default: } }