Unify comment style and whitespace
Use 'git diff --ignore-space-change --word-diff=plain' to verify.
This commit is contained in:
parent
0999c802eb
commit
bfa5dd8afd
34
RFM69.cpp
34
RFM69.cpp
|
|
@ -39,7 +39,7 @@ volatile byte RFM69::SENDERID;
|
||||||
volatile byte RFM69::TARGETID; // should match _address
|
volatile byte RFM69::TARGETID; // should match _address
|
||||||
volatile byte RFM69::PAYLOADLEN;
|
volatile byte RFM69::PAYLOADLEN;
|
||||||
volatile byte RFM69::ACK_REQUESTED;
|
volatile byte RFM69::ACK_REQUESTED;
|
||||||
volatile byte RFM69::ACK_RECEIVED; /// Should be polled immediately after sending a packet with ACK request
|
volatile byte RFM69::ACK_RECEIVED; // should be polled immediately after sending a packet with ACK request
|
||||||
volatile int RFM69::RSSI; // most accurate RSSI during reception (closest to the reception)
|
volatile int RFM69::RSSI; // most accurate RSSI during reception (closest to the reception)
|
||||||
RFM69* RFM69::selfPointer;
|
RFM69* RFM69::selfPointer;
|
||||||
|
|
||||||
|
|
@ -68,7 +68,7 @@ bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID)
|
||||||
|
|
||||||
// RXBW defaults are { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_24 | RF_RXBW_EXP_5} (RxBw: 10.4khz)
|
// RXBW defaults are { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_24 | RF_RXBW_EXP_5} (RxBw: 10.4khz)
|
||||||
/* 0x19 */ { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_16 | RF_RXBW_EXP_2 }, // (BitRate < 2 * RxBw)
|
/* 0x19 */ { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_16 | RF_RXBW_EXP_2 }, // (BitRate < 2 * RxBw)
|
||||||
//for BR-19200: //* 0x19 */ { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_24 | RF_RXBW_EXP_3 },
|
//for BR-19200: /* 0x19 */ { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_24 | RF_RXBW_EXP_3 },
|
||||||
/* 0x25 */ { REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_01 }, // DIO0 is the only IRQ we're using
|
/* 0x25 */ { REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_01 }, // DIO0 is the only IRQ we're using
|
||||||
/* 0x29 */ { REG_RSSITHRESH, 220 }, // must be set to dBm = (-Sensitivity / 2) - default is 0xE4=228 so -114dBm
|
/* 0x29 */ { REG_RSSITHRESH, 220 }, // must be set to dBm = (-Sensitivity / 2) - default is 0xE4=228 so -114dBm
|
||||||
///* 0x2d */ { REG_PREAMBLELSB, RF_PREAMBLESIZE_LSB_VALUE } // default 3 preamble bytes 0xAAAAAA
|
///* 0x2d */ { REG_PREAMBLELSB, RF_PREAMBLESIZE_LSB_VALUE } // default 3 preamble bytes 0xAAAAAA
|
||||||
|
|
@ -77,11 +77,11 @@ bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID)
|
||||||
/* 0x30 */ { REG_SYNCVALUE2, networkID }, // NETWORK ID
|
/* 0x30 */ { REG_SYNCVALUE2, networkID }, // NETWORK ID
|
||||||
/* 0x37 */ { REG_PACKETCONFIG1, RF_PACKET1_FORMAT_VARIABLE | RF_PACKET1_DCFREE_OFF | RF_PACKET1_CRC_ON | RF_PACKET1_CRCAUTOCLEAR_ON | RF_PACKET1_ADRSFILTERING_OFF },
|
/* 0x37 */ { REG_PACKETCONFIG1, RF_PACKET1_FORMAT_VARIABLE | RF_PACKET1_DCFREE_OFF | RF_PACKET1_CRC_ON | RF_PACKET1_CRCAUTOCLEAR_ON | RF_PACKET1_ADRSFILTERING_OFF },
|
||||||
/* 0x38 */ { REG_PAYLOADLENGTH, 66 }, // in variable length mode: the max frame size, not used in TX
|
/* 0x38 */ { REG_PAYLOADLENGTH, 66 }, // in variable length mode: the max frame size, not used in TX
|
||||||
//* 0x39 */ { REG_NODEADRS, nodeID }, //turned off because we're not using address filtering
|
///* 0x39 */ { REG_NODEADRS, nodeID }, // turned off because we're not using address filtering
|
||||||
/* 0x3C */ { REG_FIFOTHRESH, RF_FIFOTHRESH_TXSTART_FIFONOTEMPTY | RF_FIFOTHRESH_VALUE }, // TX on FIFO not empty
|
/* 0x3C */ { REG_FIFOTHRESH, RF_FIFOTHRESH_TXSTART_FIFONOTEMPTY | RF_FIFOTHRESH_VALUE }, // TX on FIFO not empty
|
||||||
/* 0x3d */ { REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_2BITS | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_OFF }, // RXRESTARTDELAY must match transmitter PA ramp-down time (bitrate dependent)
|
/* 0x3d */ { REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_2BITS | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_OFF }, // RXRESTARTDELAY must match transmitter PA ramp-down time (bitrate dependent)
|
||||||
//for BR-19200: //* 0x3d */ { REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_NONE | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_OFF }, //RXRESTARTDELAY must match transmitter PA ramp-down time (bitrate dependent)
|
//for BR-19200: /* 0x3d */ { REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_NONE | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_OFF }, // RXRESTARTDELAY must match transmitter PA ramp-down time (bitrate dependent)
|
||||||
//* 0x6F */ { REG_TESTDAGC, RF_DAGC_CONTINUOUS }, // run DAGC continuously in RX mode
|
///* 0x6F */ { REG_TESTDAGC, RF_DAGC_CONTINUOUS }, // run DAGC continuously in RX mode
|
||||||
/* 0x6F */ { REG_TESTDAGC, RF_DAGC_IMPROVED_LOWBETA0 }, // run DAGC continuously in RX mode, recommended default for AfcLowBetaOn=0
|
/* 0x6F */ { REG_TESTDAGC, RF_DAGC_IMPROVED_LOWBETA0 }, // run DAGC continuously in RX mode, recommended default for AfcLowBetaOn=0
|
||||||
{255, 0}
|
{255, 0}
|
||||||
};
|
};
|
||||||
|
|
@ -101,7 +101,7 @@ bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID)
|
||||||
|
|
||||||
setHighPower(_isRFM69HW); // called regardless if it's a RFM69W or RFM69HW
|
setHighPower(_isRFM69HW); // called regardless if it's a RFM69W or RFM69HW
|
||||||
setMode(RF69_MODE_STANDBY);
|
setMode(RF69_MODE_STANDBY);
|
||||||
while ((readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady
|
while ((readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // wait for ModeReady
|
||||||
attachInterrupt(_interruptNum, RFM69::isr0, RISING);
|
attachInterrupt(_interruptNum, RFM69::isr0, RISING);
|
||||||
|
|
||||||
selfPointer = this;
|
selfPointer = this;
|
||||||
|
|
@ -152,7 +152,7 @@ void RFM69::setMode(byte newMode)
|
||||||
|
|
||||||
// we are using packet mode, so this check is not really needed
|
// we are using packet mode, so this check is not really needed
|
||||||
// but waiting for mode ready is necessary when going from sleep because the FIFO may not be immediately available from previous mode
|
// but waiting for mode ready is necessary when going from sleep because the FIFO may not be immediately available from previous mode
|
||||||
while (_mode == RF69_MODE_SLEEP && (readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady
|
while (_mode == RF69_MODE_SLEEP && (readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // wait for ModeReady
|
||||||
|
|
||||||
_mode = newMode;
|
_mode = newMode;
|
||||||
}
|
}
|
||||||
|
|
@ -201,7 +201,7 @@ void RFM69::send(byte toAddress, const void* buffer, byte bufferSize, bool reque
|
||||||
// to increase the chance of getting a packet across, call this function instead of send
|
// to increase the chance of getting a packet across, call this function instead of send
|
||||||
// and it handles all the ACK requesting/retrying for you :)
|
// and it handles all the ACK requesting/retrying for you :)
|
||||||
// The only twist is that you have to manually listen to ACK requests on the other side and send back the ACKs
|
// The only twist is that you have to manually listen to ACK requests on the other side and send back the ACKs
|
||||||
// The reason for the semi-automaton is that the lib is ingterrupt driven and
|
// The reason for the semi-automaton is that the lib is interrupt driven and
|
||||||
// requires user action to read the received data and decide what to do with it
|
// requires user action to read the received data and decide what to do with it
|
||||||
// replies usually take only 5-8ms at 50kbps@915Mhz
|
// replies usually take only 5-8ms at 50kbps@915Mhz
|
||||||
bool RFM69::sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, byte retries, byte retryWaitTime) {
|
bool RFM69::sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, byte retries, byte retryWaitTime) {
|
||||||
|
|
@ -223,7 +223,7 @@ bool RFM69::sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, b
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Should be polled immediately after sending a packet with ACK request
|
// should be polled immediately after sending a packet with ACK request
|
||||||
bool RFM69::ACKReceived(byte fromNodeID) {
|
bool RFM69::ACKReceived(byte fromNodeID) {
|
||||||
if (receiveDone())
|
if (receiveDone())
|
||||||
return (SENDERID == fromNodeID || fromNodeID == RF69_BROADCAST_ADDR) && ACK_RECEIVED;
|
return (SENDERID == fromNodeID || fromNodeID == RF69_BROADCAST_ADDR) && ACK_RECEIVED;
|
||||||
|
|
@ -235,7 +235,7 @@ bool RFM69::ACKRequested() {
|
||||||
return ACK_REQUESTED && (TARGETID != RF69_BROADCAST_ADDR);
|
return ACK_REQUESTED && (TARGETID != RF69_BROADCAST_ADDR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Should be called immediately after reception in case sender wants ACK
|
// should be called immediately after reception in case sender wants ACK
|
||||||
void RFM69::sendACK(const void* buffer, byte bufferSize) {
|
void RFM69::sendACK(const void* buffer, byte bufferSize) {
|
||||||
byte sender = SENDERID;
|
byte sender = SENDERID;
|
||||||
int _RSSI = RSSI; // save payload received RSSI value
|
int _RSSI = RSSI; // save payload received RSSI value
|
||||||
|
|
@ -249,7 +249,7 @@ void RFM69::sendACK(const void* buffer, byte bufferSize) {
|
||||||
void RFM69::sendFrame(byte toAddress, const void* buffer, byte bufferSize, bool requestACK, bool sendACK)
|
void RFM69::sendFrame(byte toAddress, const void* buffer, byte bufferSize, bool requestACK, bool sendACK)
|
||||||
{
|
{
|
||||||
setMode(RF69_MODE_STANDBY); // turn off receiver to prevent reception while filling fifo
|
setMode(RF69_MODE_STANDBY); // turn off receiver to prevent reception while filling fifo
|
||||||
while ((readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady
|
while ((readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // wait for ModeReady
|
||||||
writeReg(REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_00); // DIO0 is "Packet Sent"
|
writeReg(REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_00); // DIO0 is "Packet Sent"
|
||||||
if (bufferSize > RF69_MAX_DATA_LEN) bufferSize = RF69_MAX_DATA_LEN;
|
if (bufferSize > RF69_MAX_DATA_LEN) bufferSize = RF69_MAX_DATA_LEN;
|
||||||
|
|
||||||
|
|
@ -275,7 +275,7 @@ void RFM69::sendFrame(byte toAddress, const void* buffer, byte bufferSize, bool
|
||||||
setMode(RF69_MODE_TX);
|
setMode(RF69_MODE_TX);
|
||||||
unsigned long txStart = millis();
|
unsigned long txStart = millis();
|
||||||
while (digitalRead(_interruptPin) == 0 && millis()-txStart < RF69_TX_LIMIT_MS); // wait for DIO0 to turn HIGH signalling transmission finish
|
while (digitalRead(_interruptPin) == 0 && millis()-txStart < RF69_TX_LIMIT_MS); // wait for DIO0 to turn HIGH signalling transmission finish
|
||||||
//while (readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PACKETSENT == 0x00); // Wait for ModeReady
|
//while (readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PACKETSENT == 0x00); // wait for ModeReady
|
||||||
setMode(RF69_MODE_STANDBY);
|
setMode(RF69_MODE_STANDBY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -305,8 +305,8 @@ void RFM69::interruptHandler() {
|
||||||
SENDERID = SPI.transfer(0);
|
SENDERID = SPI.transfer(0);
|
||||||
byte CTLbyte = SPI.transfer(0);
|
byte CTLbyte = SPI.transfer(0);
|
||||||
|
|
||||||
ACK_RECEIVED = CTLbyte & 0x80; //extract ACK-requested flag
|
ACK_RECEIVED = CTLbyte & 0x80; // extract ACK-received flag
|
||||||
ACK_REQUESTED = CTLbyte & 0x40; //extract ACK-received flag
|
ACK_REQUESTED = CTLbyte & 0x40; // extract ACK-requested flag
|
||||||
|
|
||||||
for (byte i = 0; i < DATALEN; i++)
|
for (byte i = 0; i < DATALEN; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -377,7 +377,7 @@ int RFM69::readRSSI(bool forceTrigger) {
|
||||||
{
|
{
|
||||||
// RSSI trigger not needed if DAGC is in continuous mode
|
// RSSI trigger not needed if DAGC is in continuous mode
|
||||||
writeReg(REG_RSSICONFIG, RF_RSSI_START);
|
writeReg(REG_RSSICONFIG, RF_RSSI_START);
|
||||||
while ((readReg(REG_RSSICONFIG) & RF_RSSI_DONE) == 0x00); // Wait for RSSI_Ready
|
while ((readReg(REG_RSSICONFIG) & RF_RSSI_DONE) == 0x00); // wait for RSSI_Ready
|
||||||
}
|
}
|
||||||
rssi = -readReg(REG_RSSIVALUE);
|
rssi = -readReg(REG_RSSIVALUE);
|
||||||
rssi >>= 1;
|
rssi >>= 1;
|
||||||
|
|
@ -401,7 +401,7 @@ void RFM69::writeReg(byte addr, byte value)
|
||||||
unselect();
|
unselect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Select the transceiver
|
// select the transceiver
|
||||||
void RFM69::select() {
|
void RFM69::select() {
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
// save current SPI settings
|
// save current SPI settings
|
||||||
|
|
@ -414,7 +414,7 @@ void RFM69::select() {
|
||||||
digitalWrite(_slaveSelectPin, LOW);
|
digitalWrite(_slaveSelectPin, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// UNselect the transceiver chip
|
// UNselect the transceiver chip
|
||||||
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
|
||||||
|
|
|
||||||
2
RFM69.h
2
RFM69.h
|
|
@ -76,7 +76,7 @@ class RFM69 {
|
||||||
static volatile byte TARGETID; // should match _address
|
static volatile byte TARGETID; // should match _address
|
||||||
static volatile byte PAYLOADLEN;
|
static volatile byte PAYLOADLEN;
|
||||||
static volatile byte ACK_REQUESTED;
|
static volatile byte ACK_REQUESTED;
|
||||||
static volatile byte ACK_RECEIVED; /// Should be polled immediately after sending a packet with ACK request
|
static volatile byte ACK_RECEIVED; // Should be polled immediately after sending a packet with ACK request
|
||||||
static volatile int RSSI; // most accurate RSSI during reception (closest to the reception)
|
static volatile int RSSI; // most accurate RSSI during reception (closest to the reception)
|
||||||
static volatile byte _mode; // should be protected?
|
static volatile byte _mode; // should be protected?
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1066,4 +1066,3 @@
|
||||||
#define RF_DAGC_NORMAL 0x00 // Reset value
|
#define RF_DAGC_NORMAL 0x00 // Reset value
|
||||||
#define RF_DAGC_IMPROVED_LOWBETA1 0x20 //
|
#define RF_DAGC_IMPROVED_LOWBETA1 0x20 //
|
||||||
#define RF_DAGC_IMPROVED_LOWBETA0 0x30 // Recommended default
|
#define RF_DAGC_IMPROVED_LOWBETA0 0x30 // Recommended default
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue