mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
sx127x: fix typos, provide corrections
This commit is contained in:
committed by
deadprogram
parent
07ba9ec0fd
commit
d57d9b6c74
@@ -343,10 +343,8 @@ func lw(setting string) error {
|
||||
if param == "NET" {
|
||||
if val == "ON" {
|
||||
lorawan.SetPublicNetwork(true)
|
||||
println("SET PUBLIC NET")
|
||||
} else {
|
||||
lorawan.SetPublicNetwork(false)
|
||||
println("SET PRIVATE NET")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -82,4 +82,4 @@ const (
|
||||
MHz_868_5 = 868500000
|
||||
MHz_916_8 = 916800000
|
||||
MHz_923_3 = 923300000
|
||||
)
|
||||
)
|
||||
|
||||
+25
-7
@@ -346,14 +346,15 @@ func (d *Device) SetIqMode(val uint8) {
|
||||
d.WriteRegister(SX127X_REG_INVERTIQ2, 0x19)
|
||||
}
|
||||
}
|
||||
|
||||
// SetPublicNetwork changes Sync Word to match network type
|
||||
func (d *Device) SetPublicNetwork(enabled bool) {
|
||||
func (d *Device) SetPublicNetwork(enabled bool) {
|
||||
if enabled {
|
||||
d.SetSyncWord(SX127X_LORA_MAC_PUBLIC_SYNCWORD)
|
||||
} else {
|
||||
d.SetSyncWord(SX127X_LORA_MAC_PRIVATE_SYNCWORD)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Tx sends a lora packet, (with timeout)
|
||||
func (d *Device) Tx(pkt []uint8, timeoutMs uint32) error {
|
||||
@@ -374,7 +375,7 @@ func (d *Device) Tx(pkt []uint8, timeoutMs uint32) error {
|
||||
d.SetCodingRate(d.loraConf.Cr)
|
||||
d.SetCrc(d.loraConf.Crc == lora.CRCOn)
|
||||
d.SetTxPower(d.loraConf.LoraTxPowerDBm)
|
||||
d.SetHeaderMode(d.loraConf.HeaderType)
|
||||
d.SetHeaderType(d.loraConf.HeaderType)
|
||||
d.SetAgcAuto(SX127X_AGC_AUTO_ON)
|
||||
|
||||
// set the IRQ mapping DIO0=TxDone DIO1=NOP DIO2=NOP
|
||||
@@ -430,21 +431,32 @@ func (d *Device) Rx(timeoutMs uint32) ([]uint8, error) {
|
||||
d.SetCodingRate(d.loraConf.Cr)
|
||||
d.SetCrc(d.loraConf.Crc == lora.CRCOn)
|
||||
d.SetTxPower(d.loraConf.LoraTxPowerDBm)
|
||||
d.SetHeaderMode(d.loraConf.HeaderType)
|
||||
d.SetHeaderType(d.loraConf.HeaderType)
|
||||
d.SetAgcAuto(SX127X_AGC_AUTO_ON)
|
||||
|
||||
//d.SetRxTimeout(200)
|
||||
|
||||
// set the IRQ mapping DIO0=RxDone DIO1=RxTimeout DIO2=NOP
|
||||
d.WriteRegister(SX127X_REG_DIO_MAPPING_1, SX127X_MAP_DIO0_LORA_RXDONE|SX127X_MAP_DIO1_LORA_RXTOUT|SX127X_MAP_DIO2_LORA_NOP)
|
||||
// Clear all radio IRQ Flags
|
||||
d.WriteRegister(SX127X_REG_IRQ_FLAGS, 0xFF)
|
||||
// Mask all but RxDone
|
||||
d.WriteRegister(SX127X_REG_IRQ_FLAGS_MASK, ^(SX127X_IRQ_LORA_RXDONE_MASK | SX127X_IRQ_LORA_RXTOUT_MASK))
|
||||
// Switch to RX Mode
|
||||
d.SetOpMode(SX127X_OPMODE_RX_SINGLE) //
|
||||
// Wait for Radio Event
|
||||
|
||||
// Get Radio Event Channel
|
||||
radioCh := d.GetRadioEventChan()
|
||||
|
||||
// Single RX mode don't properly handle Timeouts on sx127x, so we use Continuous RX
|
||||
// Go routine is a workaround to stop the Continuous RX and fire a timeout Event
|
||||
d.SetOpMode(SX127X_OPMODE_RX)
|
||||
|
||||
go func() {
|
||||
time.Sleep(time.Millisecond * time.Duration(timeoutMs))
|
||||
d.SetOpMode(SX127X_OPMODE_STANDBY) //Go standby
|
||||
radioCh <- lora.NewRadioEvent(lora.RadioEventTimeout, 0, nil)
|
||||
}()
|
||||
|
||||
// Now the channel can receive either a Timeout or a RxDone:
|
||||
msg := <-radioCh
|
||||
if msg.EventType == lora.RadioEventTimeout {
|
||||
return nil, nil
|
||||
@@ -452,6 +464,7 @@ func (d *Device) Rx(timeoutMs uint32) ([]uint8, error) {
|
||||
return nil, errors.New("Unexpected Radio Event while RX " + string(0x30+msg.EventType))
|
||||
}
|
||||
|
||||
// Get the received payload
|
||||
d.WriteRegister(SX127X_REG_FIFO_RX_BASE_ADDR, 0)
|
||||
d.WriteRegister(SX127X_REG_FIFO_ADDR_PTR, 0)
|
||||
|
||||
@@ -546,4 +559,9 @@ func bandwidth(bw uint8) uint8 {
|
||||
}
|
||||
}
|
||||
|
||||
func syncword(sw int) uint16 {
|
||||
if sw == lora.SyncPublic {
|
||||
return SX127X_LORA_MAC_PUBLIC_SYNCWORD
|
||||
}
|
||||
return SX127X_LORA_MAC_PRIVATE_SYNCWORD
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user