Update RadioLib
This commit is contained in:
+17
-34
@@ -30,11 +30,9 @@ SX1278 radio = new Module(10, 2, 9, 3);
|
||||
// https://github.com/jgromes/RadioShield
|
||||
//SX1278 radio = RadioShield.ModuleA;
|
||||
|
||||
// save state between loops
|
||||
int scanState = RADIOLIB_ERR_NONE;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
// Serial port speed must be high enough for this example
|
||||
Serial.begin(115200);
|
||||
|
||||
// initialize SX1278 with default settings
|
||||
Serial.print(F("[SX1278] Initializing ... "));
|
||||
@@ -44,16 +42,16 @@ void setup() {
|
||||
} else {
|
||||
Serial.print(F("failed, code "));
|
||||
Serial.println(state);
|
||||
while (true);
|
||||
while (true) { delay(10); }
|
||||
}
|
||||
|
||||
// set the function that will be called
|
||||
// when LoRa preamble is not detected within CAD timeout period
|
||||
radio.setDio0Action(setFlagTimeout);
|
||||
radio.setDio0Action(setFlagTimeout, RISING);
|
||||
|
||||
// set the function that will be called
|
||||
// when LoRa preamble is detected
|
||||
radio.setDio1Action(setFlagDetected);
|
||||
radio.setDio1Action(setFlagDetected, RISING);
|
||||
|
||||
// start scanning the channel
|
||||
Serial.print(F("[SX1278] Starting scan for LoRa preamble ... "));
|
||||
@@ -72,9 +70,6 @@ volatile bool timeoutFlag = false;
|
||||
// flag to indicate that a preamble was detected
|
||||
volatile bool detectedFlag = false;
|
||||
|
||||
// disable interrupt when it's not needed
|
||||
volatile bool enableInterrupt = true;
|
||||
|
||||
// this function is called when no preamble
|
||||
// is detected within timeout period
|
||||
// IMPORTANT: this function MUST be 'void' type
|
||||
@@ -83,11 +78,6 @@ volatile bool enableInterrupt = true;
|
||||
ICACHE_RAM_ATTR
|
||||
#endif
|
||||
void setFlagTimeout(void) {
|
||||
// check if the interrupt is enabled
|
||||
if(!enableInterrupt) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we timed out, set the flag
|
||||
timeoutFlag = true;
|
||||
}
|
||||
@@ -100,32 +90,22 @@ void setFlagTimeout(void) {
|
||||
ICACHE_RAM_ATTR
|
||||
#endif
|
||||
void setFlagDetected(void) {
|
||||
// check if the interrupt is enabled
|
||||
if(!enableInterrupt) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we got a preamble, set the flag
|
||||
detectedFlag = true;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check if we got a preamble
|
||||
if(detectedFlag) {
|
||||
// disable the interrupt service routine while
|
||||
// processing the data
|
||||
enableInterrupt = false;
|
||||
|
||||
// reset flag
|
||||
detectedFlag = false;
|
||||
|
||||
// LoRa preamble was detected
|
||||
Serial.print(F("[SX1278] Preamble detected!"));
|
||||
|
||||
}
|
||||
|
||||
// check if we need to restart channel activity detection
|
||||
if(detectedFlag || timeoutFlag) {
|
||||
// check if we got a preamble
|
||||
if(detectedFlag) {
|
||||
// LoRa preamble was detected
|
||||
Serial.println(F("[SX1278] Preamble detected!"));
|
||||
} else {
|
||||
// nothing was detected
|
||||
Serial.println(F("[SX1278] Channel free!"));
|
||||
}
|
||||
|
||||
// start scanning the channel
|
||||
Serial.print(F("[SX1278] Starting scan for LoRa preamble ... "));
|
||||
|
||||
@@ -138,5 +118,8 @@ void loop() {
|
||||
Serial.println(state);
|
||||
}
|
||||
|
||||
// reset flags
|
||||
timeoutFlag = false;
|
||||
detectedFlag = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user