[SX127x] Fixed CAD interrupt example
This commit is contained in:
parent
1316a805f3
commit
c3fa027108
1 changed files with 21 additions and 16 deletions
|
@ -30,11 +30,9 @@ SX1278 radio = new Module(10, 2, 9, 3);
|
||||||
// https://github.com/jgromes/RadioShield
|
// https://github.com/jgromes/RadioShield
|
||||||
//SX1278 radio = RadioShield.ModuleA;
|
//SX1278 radio = RadioShield.ModuleA;
|
||||||
|
|
||||||
// save state between loops
|
|
||||||
int scanState = RADIOLIB_ERR_NONE;
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
// Serial port speed must be high enough for this example
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
// initialize SX1278 with default settings
|
// initialize SX1278 with default settings
|
||||||
Serial.print(F("[SX1278] Initializing ... "));
|
Serial.print(F("[SX1278] Initializing ... "));
|
||||||
|
@ -110,22 +108,21 @@ void setFlagDetected(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// check if we got a preamble
|
// check if we need to restart channel activity detection
|
||||||
if(detectedFlag) {
|
if(detectedFlag || timeoutFlag) {
|
||||||
// disable the interrupt service routine while
|
// disable the interrupt service routine while
|
||||||
// processing the data
|
// processing the data
|
||||||
enableInterrupt = false;
|
enableInterrupt = false;
|
||||||
|
|
||||||
// reset flag
|
// check if we got a preamble
|
||||||
detectedFlag = false;
|
if(detectedFlag) {
|
||||||
|
// LoRa preamble was detected
|
||||||
|
Serial.println(F("[SX1278] Preamble detected!"));
|
||||||
|
} else {
|
||||||
|
// nothing was detected
|
||||||
|
Serial.println(F("[SX1278] Channel free!"));
|
||||||
|
}
|
||||||
|
|
||||||
// LoRa preamble was detected
|
|
||||||
Serial.print(F("[SX1278] Preamble detected!"));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if we need to restart channel activity detection
|
|
||||||
if(detectedFlag || timeoutFlag) {
|
|
||||||
// start scanning the channel
|
// start scanning the channel
|
||||||
Serial.print(F("[SX1278] Starting scan for LoRa preamble ... "));
|
Serial.print(F("[SX1278] Starting scan for LoRa preamble ... "));
|
||||||
|
|
||||||
|
@ -138,5 +135,13 @@ void loop() {
|
||||||
Serial.println(state);
|
Serial.println(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reset flags
|
||||||
|
timeoutFlag = false;
|
||||||
|
detectedFlag = false;
|
||||||
|
|
||||||
|
// enable interrupts again
|
||||||
|
enableInterrupt = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue