From 17bcfcd0bb94a5a1b11a1299476ecd7d234187ff Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 19 Nov 2024 18:52:21 +0100 Subject: [PATCH] [SX127x] Fixed order of ISR functions in examples --- ...x_Channel_Activity_Detection_Interrupt.ino | 60 ++++++++--------- ...27x_Channel_Activity_Detection_Receive.ino | 66 +++++++++---------- .../SX127x_Receive_Direct.ino | 12 ++-- .../SX127x_Receive_Interrupt.ino | 30 ++++----- .../SX127x_Transmit_Interrupt.ino | 30 ++++----- 5 files changed, 99 insertions(+), 99 deletions(-) diff --git a/examples/SX127x/SX127x_Channel_Activity_Detection_Interrupt/SX127x_Channel_Activity_Detection_Interrupt.ino b/examples/SX127x/SX127x_Channel_Activity_Detection_Interrupt/SX127x_Channel_Activity_Detection_Interrupt.ino index 95070e0e..4efbf4a2 100644 --- a/examples/SX127x/SX127x_Channel_Activity_Detection_Interrupt/SX127x_Channel_Activity_Detection_Interrupt.ino +++ b/examples/SX127x/SX127x_Channel_Activity_Detection_Interrupt/SX127x_Channel_Activity_Detection_Interrupt.ino @@ -34,6 +34,36 @@ SX1278 radio = new Module(10, 2, 9, 3); Radio radio = new RadioModule(); */ +// flag to indicate that a preamble was not detected +volatile bool timeoutFlag = false; + +// flag to indicate that a preamble was detected +volatile bool detectedFlag = false; + +// this function is called when no preamble +// is detected within timeout period +// IMPORTANT: this function MUST be 'void' type +// and MUST NOT have any arguments! +#if defined(ESP8266) || defined(ESP32) + ICACHE_RAM_ATTR +#endif +void setFlagTimeout(void) { + // we timed out, set the flag + timeoutFlag = true; +} + +// this function is called when LoRa preamble +// is detected within timeout period +// IMPORTANT: this function MUST be 'void' type +// and MUST NOT have any arguments! +#if defined(ESP8266) || defined(ESP32) + ICACHE_RAM_ATTR +#endif +void setFlagDetected(void) { + // we got a preamble, set the flag + detectedFlag = true; +} + void setup() { // Serial port speed must be high enough for this example Serial.begin(115200); @@ -68,36 +98,6 @@ void setup() { } } -// flag to indicate that a preamble was not detected -volatile bool timeoutFlag = false; - -// flag to indicate that a preamble was detected -volatile bool detectedFlag = false; - -// this function is called when no preamble -// is detected within timeout period -// IMPORTANT: this function MUST be 'void' type -// and MUST NOT have any arguments! -#if defined(ESP8266) || defined(ESP32) - ICACHE_RAM_ATTR -#endif -void setFlagTimeout(void) { - // we timed out, set the flag - timeoutFlag = true; -} - -// this function is called when LoRa preamble -// is detected within timeout period -// IMPORTANT: this function MUST be 'void' type -// and MUST NOT have any arguments! -#if defined(ESP8266) || defined(ESP32) - ICACHE_RAM_ATTR -#endif -void setFlagDetected(void) { - // we got a preamble, set the flag - detectedFlag = true; -} - void loop() { // check if we need to restart channel activity detection if(detectedFlag || timeoutFlag) { diff --git a/examples/SX127x/SX127x_Channel_Activity_Detection_Receive/SX127x_Channel_Activity_Detection_Receive.ino b/examples/SX127x/SX127x_Channel_Activity_Detection_Receive/SX127x_Channel_Activity_Detection_Receive.ino index 9b03d2e2..0e5670e8 100644 --- a/examples/SX127x/SX127x_Channel_Activity_Detection_Receive/SX127x_Channel_Activity_Detection_Receive.ino +++ b/examples/SX127x/SX127x_Channel_Activity_Detection_Receive/SX127x_Channel_Activity_Detection_Receive.ino @@ -39,6 +39,39 @@ SX1278 radio = new Module(10, 2, 9, 3); Radio radio = new RadioModule(); */ +// flag to indicate that a preamble was not detected +volatile bool timeoutFlag = false; + +// flag to indicate that a preamble was detected +volatile bool detectedFlag = false; + +// flag to indicate if we are currently receiving +bool receiving = false; + +// this function is called when no preamble +// is detected within timeout period +// IMPORTANT: this function MUST be 'void' type +// and MUST NOT have any arguments! +#if defined(ESP8266) || defined(ESP32) + ICACHE_RAM_ATTR +#endif +void setFlagTimeout(void) { + // we timed out, set the flag + timeoutFlag = true; +} + +// this function is called when LoRa preamble +// is detected within timeout period +// IMPORTANT: this function MUST be 'void' type +// and MUST NOT have any arguments! +#if defined(ESP8266) || defined(ESP32) + ICACHE_RAM_ATTR +#endif +void setFlagDetected(void) { + // we got a preamble, set the flag + detectedFlag = true; +} + void setup() { // Serial port speed must be high enough for this example Serial.begin(115200); @@ -74,39 +107,6 @@ void setup() { } } -// flag to indicate that a preamble was not detected -volatile bool timeoutFlag = false; - -// flag to indicate that a preamble was detected -volatile bool detectedFlag = false; - -// flag to indicate if we are currently receiving -bool receiving = false; - -// this function is called when no preamble -// is detected within timeout period -// IMPORTANT: this function MUST be 'void' type -// and MUST NOT have any arguments! -#if defined(ESP8266) || defined(ESP32) - ICACHE_RAM_ATTR -#endif -void setFlagTimeout(void) { - // we timed out, set the flag - timeoutFlag = true; -} - -// this function is called when LoRa preamble -// is detected within timeout period -// IMPORTANT: this function MUST be 'void' type -// and MUST NOT have any arguments! -#if defined(ESP8266) || defined(ESP32) - ICACHE_RAM_ATTR -#endif -void setFlagDetected(void) { - // we got a preamble, set the flag - detectedFlag = true; -} - void loop() { // check if we need to restart channel activity detection if(detectedFlag || timeoutFlag) { diff --git a/examples/SX127x/SX127x_Receive_Direct/SX127x_Receive_Direct.ino b/examples/SX127x/SX127x_Receive_Direct/SX127x_Receive_Direct.ino index f41493b2..ff9c443c 100644 --- a/examples/SX127x/SX127x_Receive_Direct/SX127x_Receive_Direct.ino +++ b/examples/SX127x/SX127x_Receive_Direct/SX127x_Receive_Direct.ino @@ -32,6 +32,12 @@ const int pin = 5; Radio radio = new RadioModule(); */ +// this function is called when a new bit is received +void readBit(void) { + // read the data bit + radio.readBit(pin); +} + void setup() { Serial.begin(9600); @@ -59,12 +65,6 @@ void setup() { radio.receiveDirect(); } -// this function is called when a new bit is received -void readBit(void) { - // read the data bit - radio.readBit(pin); -} - void loop() { // we expect the packet to contain the string "Hello World!", // a length byte and 2 CRC bytes, that's 15 bytes in total diff --git a/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino b/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino index 451e4192..ebb04832 100644 --- a/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino +++ b/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino @@ -39,6 +39,21 @@ SX1278 radio = new Module(10, 2, 9, 3); Radio radio = new RadioModule(); */ +// flag to indicate that a packet was received +volatile bool receivedFlag = false; + +// this function is called when a complete packet +// is received by the module +// IMPORTANT: this function MUST be 'void' type +// and MUST NOT have any arguments! +#if defined(ESP8266) || defined(ESP32) + ICACHE_RAM_ATTR +#endif +void setFlag(void) { + // we got a packet, set the flag + receivedFlag = true; +} + void setup() { Serial.begin(9600); @@ -78,21 +93,6 @@ void setup() { // radio.scanChannel(); } -// flag to indicate that a packet was received -volatile bool receivedFlag = false; - -// this function is called when a complete packet -// is received by the module -// IMPORTANT: this function MUST be 'void' type -// and MUST NOT have any arguments! -#if defined(ESP8266) || defined(ESP32) - ICACHE_RAM_ATTR -#endif -void setFlag(void) { - // we got a packet, set the flag - receivedFlag = true; -} - void loop() { // check if the flag is set if(receivedFlag) { diff --git a/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino b/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino index 22785d76..04385bc1 100644 --- a/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino +++ b/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino @@ -38,6 +38,21 @@ Radio radio = new RadioModule(); // save transmission state between loops int transmissionState = RADIOLIB_ERR_NONE; +// flag to indicate that a packet was sent +volatile bool transmittedFlag = false; + +// this function is called when a complete packet +// is transmitted by the module +// IMPORTANT: this function MUST be 'void' type +// and MUST NOT have any arguments! +#if defined(ESP8266) || defined(ESP32) + ICACHE_RAM_ATTR +#endif +void setFlag(void) { + // we sent a packet, set the flag + transmittedFlag = true; +} + void setup() { Serial.begin(9600); @@ -71,21 +86,6 @@ void setup() { */ } -// flag to indicate that a packet was sent -volatile bool transmittedFlag = false; - -// this function is called when a complete packet -// is transmitted by the module -// IMPORTANT: this function MUST be 'void' type -// and MUST NOT have any arguments! -#if defined(ESP8266) || defined(ESP32) - ICACHE_RAM_ATTR -#endif -void setFlag(void) { - // we sent a packet, set the flag - transmittedFlag = true; -} - // counter to keep track of transmitted packets int count = 0;