Skip to content

Commit a73831b

Browse files
author
Lang, Samuel
committed
non blocking functions added
1 parent 4857e1b commit a73831b

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <SPI.h>
2+
#include <LoRa.h>
3+
4+
int counter = 0;
5+
6+
void setup()
7+
{
8+
Serial.begin(9600);
9+
while (!Serial)
10+
;
11+
12+
Serial.println("LoRa Sender");
13+
14+
if (!LoRa.begin(915E6))
15+
{
16+
Serial.println("Starting LoRa failed!");
17+
while (1)
18+
;
19+
}
20+
}
21+
22+
void loop()
23+
{
24+
if (LoRa.isTransmitting())
25+
{
26+
delay(100);
27+
Serial.print('w');
28+
return;
29+
}
30+
Serial.print("\nSending packet: ");
31+
Serial.println(counter);
32+
33+
// send packet
34+
LoRa.beginPacket();
35+
LoRa.print("hello ");
36+
LoRa.print(counter);
37+
LoRa.endPacketasync();
38+
39+
counter++;
40+
}

src/LoRa.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,26 @@ int LoRaClass::endPacket()
152152
return 1;
153153
}
154154

155+
void LoRaClass::endPacketasync()
156+
{
157+
// put in TX mode
158+
writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_TX);
159+
// apparently this grace time is required for the radio
160+
delayMicroseconds(150);
161+
}
162+
163+
bool LoRaClass::isTransmitting()
164+
{
165+
if ((readRegister(REG_OP_MODE) & MODE_TX) == MODE_TX)
166+
return true;
167+
168+
if (!(readRegister(REG_IRQ_FLAGS) & IRQ_TX_DONE_MASK) == 0)
169+
// clear IRQ's
170+
writeRegister(REG_IRQ_FLAGS, IRQ_TX_DONE_MASK);
171+
172+
return false;
173+
}
174+
155175
int LoRaClass::parsePacket(int size)
156176
{
157177
int packetLength = 0;

src/LoRa.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class LoRaClass : public Stream {
2323

2424
int beginPacket(int implicitHeader = false);
2525
int endPacket();
26+
void endPacketasync();
27+
bool isTransmitting();
2628

2729
int parsePacket(int size = 0);
2830
int packetRssi();

0 commit comments

Comments
 (0)