File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed
examples/LoRaSenderNonBlocking Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
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 (" \n Sending 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
+ }
Original file line number Diff line number Diff line change @@ -152,6 +152,26 @@ int LoRaClass::endPacket()
152
152
return 1 ;
153
153
}
154
154
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
+
155
175
int LoRaClass::parsePacket (int size)
156
176
{
157
177
int packetLength = 0 ;
Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ class LoRaClass : public Stream {
23
23
24
24
int beginPacket (int implicitHeader = false );
25
25
int endPacket ();
26
+ void endPacketasync ();
27
+ bool isTransmitting ();
26
28
27
29
int parsePacket (int size = 0 );
28
30
int packetRssi ();
You can’t perform that action at this time.
0 commit comments