minor tweaks & SPCR/SPSR filters
This commit is contained in:
parent
1472d9d475
commit
c24051e933
|
|
@ -268,6 +268,7 @@ void RFM69::sendACK(const void* buffer, uint8_t bufferSize) {
|
||||||
writeReg(REG_PACKETCONFIG2, (readReg(REG_PACKETCONFIG2) & 0xFB) | RF_PACKET2_RXRESTART); // avoid RX deadlocks
|
writeReg(REG_PACKETCONFIG2, (readReg(REG_PACKETCONFIG2) & 0xFB) | RF_PACKET2_RXRESTART); // avoid RX deadlocks
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
while (!canSend() && millis() - now < RF69_CSMA_LIMIT_MS) receiveDone();
|
while (!canSend() && millis() - now < RF69_CSMA_LIMIT_MS) receiveDone();
|
||||||
|
SENDERID = sender; // TWS: Restore SenderID after it gets wiped out by receiveDone()
|
||||||
sendFrame(sender, buffer, bufferSize, false, true);
|
sendFrame(sender, buffer, bufferSize, false, true);
|
||||||
RSSI = _RSSI; // restore payload RSSI
|
RSSI = _RSSI; // restore payload RSSI
|
||||||
}
|
}
|
||||||
|
|
@ -439,9 +440,11 @@ void RFM69::writeReg(uint8_t addr, uint8_t value)
|
||||||
// select the RFM69 transceiver (save SPI settings, set CS low)
|
// select the RFM69 transceiver (save SPI settings, set CS low)
|
||||||
void RFM69::select() {
|
void RFM69::select() {
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
|
#if defined (SPCR) && defined (SPSR)
|
||||||
// save current SPI settings
|
// save current SPI settings
|
||||||
_SPCR = SPCR;
|
_SPCR = SPCR;
|
||||||
_SPSR = SPSR;
|
_SPSR = SPSR;
|
||||||
|
#endif
|
||||||
// set RFM69 SPI settings
|
// set RFM69 SPI settings
|
||||||
SPI.setDataMode(SPI_MODE0);
|
SPI.setDataMode(SPI_MODE0);
|
||||||
SPI.setBitOrder(MSBFIRST);
|
SPI.setBitOrder(MSBFIRST);
|
||||||
|
|
@ -453,8 +456,10 @@ void RFM69::select() {
|
||||||
void RFM69::unselect() {
|
void RFM69::unselect() {
|
||||||
digitalWrite(_slaveSelectPin, HIGH);
|
digitalWrite(_slaveSelectPin, HIGH);
|
||||||
// restore SPI settings to what they were before talking to RFM69
|
// restore SPI settings to what they were before talking to RFM69
|
||||||
|
#if defined (SPCR) && defined (SPSR)
|
||||||
SPCR = _SPCR;
|
SPCR = _SPCR;
|
||||||
SPSR = _SPSR;
|
SPSR = _SPSR;
|
||||||
|
#endif
|
||||||
interrupts();
|
interrupts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2
RFM69.h
2
RFM69.h
|
|
@ -138,8 +138,10 @@ class RFM69 {
|
||||||
bool _promiscuousMode;
|
bool _promiscuousMode;
|
||||||
uint8_t _powerLevel;
|
uint8_t _powerLevel;
|
||||||
bool _isRFM69HW;
|
bool _isRFM69HW;
|
||||||
|
#if defined (SPCR) && defined (SPSR)
|
||||||
uint8_t _SPCR;
|
uint8_t _SPCR;
|
||||||
uint8_t _SPSR;
|
uint8_t _SPSR;
|
||||||
|
#endif
|
||||||
|
|
||||||
virtual void receiveBegin();
|
virtual void receiveBegin();
|
||||||
virtual void setMode(uint8_t mode);
|
virtual void setMode(uint8_t mode);
|
||||||
|
|
|
||||||
|
|
@ -232,14 +232,14 @@ void RFM69_ATC::receiveBegin() {
|
||||||
// enableAutoPower() - call with target RSSI, use 0 to disable (default), any other value with turn on autotransmit control.
|
// enableAutoPower() - call with target RSSI, use 0 to disable (default), any other value with turn on autotransmit control.
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
// TomWS1: New methods to address autoPower control
|
// TomWS1: New methods to address autoPower control
|
||||||
void RFM69_ATC::enableAutoPower(int targetRSSI){ // TomWS1: New method to enable/disable auto Power control
|
void RFM69_ATC::enableAutoPower(int16_t targetRSSI){ // TomWS1: New method to enable/disable auto Power control
|
||||||
_targetRSSI = targetRSSI; // no logic here, just set the value (if non-zero, then enabled), caller's responsibility to use a reasonable value
|
_targetRSSI = targetRSSI; // no logic here, just set the value (if non-zero, then enabled), caller's responsibility to use a reasonable value
|
||||||
}
|
}
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
// getAckRSSI() - returns the RSSI value ack'd by the far end.
|
// getAckRSSI() - returns the RSSI value ack'd by the far end.
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
int RFM69_ATC::getAckRSSI(void){ // TomWS1: New method to retrieve the ack'd RSSI (if any)
|
int16_t RFM69_ATC::getAckRSSI(void){ // TomWS1: New method to retrieve the ack'd RSSI (if any)
|
||||||
return (_targetRSSI==0?0:_ackRSSI);
|
return (_targetRSSI==0?0:_ackRSSI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ class RFM69_ATC: public RFM69 {
|
||||||
void sendACK(const void* buffer = "", uint8_t bufferSize=0);
|
void sendACK(const void* buffer = "", uint8_t bufferSize=0);
|
||||||
//void setHighPower(bool onOFF=true, uint8_t PA_ctl=0x60); //have to call it after initialize for RFM69HW
|
//void setHighPower(bool onOFF=true, uint8_t PA_ctl=0x60); //have to call it after initialize for RFM69HW
|
||||||
//void setPowerLevel(uint8_t level); // reduce/increase transmit power level
|
//void setPowerLevel(uint8_t level); // reduce/increase transmit power level
|
||||||
void enableAutoPower(int targetRSSI=-90); // TWS: New method to enable/disable auto Power control
|
void enableAutoPower(int16_t targetRSSI=-90); // TWS: New method to enable/disable auto Power control
|
||||||
void setMode(uint8_t mode); // TWS: moved from protected to try to build block()/unblock() wrapper
|
void setMode(uint8_t mode); // TWS: moved from protected to try to build block()/unblock() wrapper
|
||||||
|
|
||||||
int16_t getAckRSSI(void); // TWS: New method to retrieve the ack'd RSSI (if any)
|
int16_t getAckRSSI(void); // TWS: New method to retrieve the ack'd RSSI (if any)
|
||||||
|
|
@ -58,7 +58,7 @@ class RFM69_ATC: public RFM69 {
|
||||||
protected:
|
protected:
|
||||||
void interruptHook(uint8_t CTLbyte);
|
void interruptHook(uint8_t CTLbyte);
|
||||||
void sendFrame(uint8_t toAddress, const void* buffer, uint8_t size, bool requestACK=false, bool sendACK=false); // Need this one to match the RFM69 prototype.
|
void sendFrame(uint8_t toAddress, const void* buffer, uint8_t size, bool requestACK=false, bool sendACK=false); // Need this one to match the RFM69 prototype.
|
||||||
void sendFrame(uint8_t toAddress, const void* buffer, uint8_t size, bool requestACK, bool sendACK, bool sendRSSI, int lastRSSI);
|
void sendFrame(uint8_t toAddress, const void* buffer, uint8_t size, bool requestACK, bool sendACK, bool sendRSSI, int16_t lastRSSI);
|
||||||
void receiveBegin();
|
void receiveBegin();
|
||||||
//void setHighPowerRegs(bool onOff);
|
//void setHighPowerRegs(bool onOff);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue