]> git.tnoah.ca Git - lora-radio.git/commitdiff
Store SX127X tx power in variable, attempt to fix #39
authorjacob.eva <x00010@disroot.org>
Sat, 12 Oct 2024 21:26:42 +0000 (22:26 +0100)
committerjacob.eva <x00010@disroot.org>
Sat, 12 Oct 2024 21:26:42 +0000 (22:26 +0100)
Radio.cpp
Radio.hpp

index 0f34c5ced2f982aa07f881b7066f002c818646ad..07485cef4573f1ebb8cf0439933326a51f155a24 100644 (file)
--- a/Radio.cpp
+++ b/Radio.cpp
@@ -119,7 +119,7 @@ sx126x::sx126x(uint8_t index, SPIClass* spi, bool tcxo, bool dio2_as_rf_switch,
   RadioInterface(index),
     _spiSettings(8E6, MSBFIRST, SPI_MODE0), _spiModem(spi), _ss(ss),
     _sclk(sclk), _mosi(mosi), _miso(miso), _reset(reset), _dio0(dio0),
-    _busy(busy), _rxen(rxen), _frequency(0), _txp(0), _sf(0x07), _bw(0x04),
+    _busy(busy), _rxen(rxen), _frequency(0), _sf(0x07), _bw(0x04),
     _cr(0x01), _ldro(0x00), _packetIndex(0), _implicitHeaderMode(0),
     _payloadLength(255), _crcMode(1), _fifo_tx_addr_ptr(0),
     _fifo_rx_addr_ptr(0), _preinit_done(false), _tcxo(tcxo),
@@ -793,7 +793,7 @@ void sx126x::setTxPower(int level, int outputPin) {
     executeOpcode(OP_TX_PARAMS_6X, tx_buf, 2);
 }
 
-uint8_t sx126x::getTxPower() {
+int8_t sx126x::getTxPower() {
     return _txp;
 }
 
@@ -1384,9 +1384,10 @@ void sx127x::setTxPower(int level, int outputPin) {
     writeRegister(REG_PA_DAC_7X, 0x84);
     writeRegister(REG_PA_CONFIG_7X, PA_BOOST_7X | (level - 2));
   }
+  _txp = level;
 }
 
-uint8_t sx127x::getTxPower() { byte txp = readRegister(REG_PA_CONFIG_7X); return txp; }
+int8_t sx127x::getTxPower() { return _txp; }
 
 void sx127x::setFrequency(uint32_t frequency) {
   _frequency = frequency;
@@ -1617,7 +1618,7 @@ sx128x::sx128x(uint8_t index, SPIClass* spi, bool tcxo, int ss, int sclk, int mo
     _spiSettings(8E6, MSBFIRST, SPI_MODE0),
     _spiModem(spi),
   _ss(ss), _sclk(sclk), _mosi(mosi), _miso(miso), _reset(reset), _dio0(dio0),
-  _busy(busy), _rxen(rxen), _txen(txen), _frequency(0), _txp(0), _sf(0x05),
+  _busy(busy), _rxen(rxen), _txen(txen), _frequency(0), _sf(0x05),
   _bw(0x34), _cr(0x01), _packetIndex(0), _implicitHeaderMode(0),
   _payloadLength(255), _crcMode(0), _fifo_tx_addr_ptr(0), _fifo_rx_addr_ptr(0),
   _rxPacketLength(0), _preinit_done(false),
@@ -2445,7 +2446,7 @@ void sx128x::setTxPower(int level, int outputPin) {
     executeOpcode(OP_TX_PARAMS_8X, tx_buf, 2);
 }
 
-uint8_t sx128x::getTxPower() {
+int8_t sx128x::getTxPower() {
       return _txp;
 }
 
index 43abef306fdd6ff6a05d8afbb62e54c79ee93668..8413ebc2a5cf19860e8259b928b88f41b5d520e8 100644 (file)
--- a/Radio.hpp
+++ b/Radio.hpp
@@ -76,7 +76,7 @@ public:
     _post_tx_yield_timeout(0), _csma_slot_ms(50), _csma_p(85), _csma_p_min(0.15),
     _csma_p_max(0.333), _csma_b_speed(0.15), _preambleLength(6), _lora_symbol_time_ms(0.0),
     _lora_symbol_rate(0.0), _lora_us_per_byte(0.0), _bitrate(0),
-     _packet{0}, _onReceive(NULL) {};
+     _packet{0}, _onReceive(NULL), _txp(0) {};
     virtual int begin() = 0;
     virtual void end() = 0;
 
@@ -108,7 +108,7 @@ public:
     virtual void sleep() = 0;
 
     virtual bool preInit() = 0;
-    virtual uint8_t getTxPower() = 0;
+    virtual int8_t getTxPower() = 0;
     virtual void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN) = 0;
     virtual uint32_t getFrequency() = 0;
     virtual void setFrequency(uint32_t frequency) = 0;
@@ -296,6 +296,7 @@ protected:
     virtual void implicitHeaderMode() = 0;
 
     uint8_t _index;
+    int8_t _txp;
     bool _radio_locked;
     bool _radio_online;
     float _st_airtime_limit;
@@ -371,7 +372,7 @@ public:
   void sleep();
 
   bool preInit();
-  uint8_t getTxPower();
+  int8_t getTxPower();
   void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN);
   uint32_t getFrequency();
   void setFrequency(uint32_t frequency);
@@ -439,7 +440,6 @@ private:
   int _rxen;
   int _busy;
   uint32_t _frequency;
-  int _txp;
   uint8_t _sf;
   uint8_t _bw;
   uint8_t _cr;
@@ -491,7 +491,7 @@ public:
   void sleep();
 
   bool preInit();
-  uint8_t getTxPower();
+  int8_t getTxPower();
   void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN);
   uint32_t getFrequency();
   void setFrequency(uint32_t frequency);
@@ -585,7 +585,7 @@ public:
   void sleep();
 
   bool preInit();
-  uint8_t getTxPower();
+  int8_t getTxPower();
   void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN);
   uint32_t getFrequency();
   void setFrequency(uint32_t frequency);
@@ -653,7 +653,6 @@ private:
   int _busy;
   int _modem;
   uint32_t _frequency;
-  int _txp;
   uint8_t _sf;
   uint8_t _bw;
   uint8_t _cr;