[SX127x] Fixed order of ISR functions in examples
This commit is contained in:
parent
a579eed780
commit
17bcfcd0bb
5 changed files with 99 additions and 99 deletions
|
@ -34,6 +34,36 @@ SX1278 radio = new Module(10, 2, 9, 3);
|
||||||
Radio radio = new RadioModule();
|
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() {
|
void setup() {
|
||||||
// Serial port speed must be high enough for this example
|
// Serial port speed must be high enough for this example
|
||||||
Serial.begin(115200);
|
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() {
|
void loop() {
|
||||||
// check if we need to restart channel activity detection
|
// check if we need to restart channel activity detection
|
||||||
if(detectedFlag || timeoutFlag) {
|
if(detectedFlag || timeoutFlag) {
|
||||||
|
|
|
@ -39,6 +39,39 @@ SX1278 radio = new Module(10, 2, 9, 3);
|
||||||
Radio radio = new RadioModule();
|
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() {
|
void setup() {
|
||||||
// Serial port speed must be high enough for this example
|
// Serial port speed must be high enough for this example
|
||||||
Serial.begin(115200);
|
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() {
|
void loop() {
|
||||||
// check if we need to restart channel activity detection
|
// check if we need to restart channel activity detection
|
||||||
if(detectedFlag || timeoutFlag) {
|
if(detectedFlag || timeoutFlag) {
|
||||||
|
|
|
@ -32,6 +32,12 @@ const int pin = 5;
|
||||||
Radio radio = new RadioModule();
|
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() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
@ -59,12 +65,6 @@ void setup() {
|
||||||
radio.receiveDirect();
|
radio.receiveDirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
// this function is called when a new bit is received
|
|
||||||
void readBit(void) {
|
|
||||||
// read the data bit
|
|
||||||
radio.readBit(pin);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// we expect the packet to contain the string "Hello World!",
|
// we expect the packet to contain the string "Hello World!",
|
||||||
// a length byte and 2 CRC bytes, that's 15 bytes in total
|
// a length byte and 2 CRC bytes, that's 15 bytes in total
|
||||||
|
|
|
@ -39,6 +39,21 @@ SX1278 radio = new Module(10, 2, 9, 3);
|
||||||
Radio radio = new RadioModule();
|
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() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
@ -78,21 +93,6 @@ void setup() {
|
||||||
// radio.scanChannel();
|
// 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() {
|
void loop() {
|
||||||
// check if the flag is set
|
// check if the flag is set
|
||||||
if(receivedFlag) {
|
if(receivedFlag) {
|
||||||
|
|
|
@ -38,6 +38,21 @@ Radio radio = new RadioModule();
|
||||||
// save transmission state between loops
|
// save transmission state between loops
|
||||||
int transmissionState = RADIOLIB_ERR_NONE;
|
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() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
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
|
// counter to keep track of transmitted packets
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue