begin adding working version

This commit is contained in:
soypat
2023-06-07 01:02:10 -03:00
parent c20a7a3d40
commit 100e51ae3a
2 changed files with 77 additions and 8 deletions
+11 -2
View File
@@ -2,6 +2,7 @@ package sx127x
import (
"errors"
"time"
"github.com/soypat/lora"
)
@@ -11,14 +12,18 @@ type DeviceLoRaBare struct {
}
func (d *DeviceLoRaBare) Configure(c lora.Config) (err error) {
err = d.DL.InitLoRaMode()
d.DL.Reset()
// Seems to take just under ~6ms. Wait 20ms.
err = d.DL.rxFSKChainCalibration(20 * time.Millisecond)
if err != nil {
return err
}
err = d.DL.SetOpMode(OpSleep)
err = d.SetOpModeBare(OpSleep)
// err = d.DL.InitLoRaMode()
if err != nil {
return err
}
// Set up FIFO
// We configure so that we can use the entire 256 byte FIFO for either receive
// or transmit, but not both at the same time
@@ -69,6 +74,10 @@ func (d *DeviceLoRaBare) crappySetTxPower(power int8, useRFO bool) (err error) {
return err
}
func (d *DeviceLoRaBare) SetOpModeBare(mode OpMode) (err error) {
return d.DL.writeMasked8(regOP_MODE, uint8(mode), 0x07)
}
func (d *DeviceLoRaBare) Send(packet []byte) (err error) {
if len(packet) > 251 {
return errors.New("too long")