@@ -152,13 +152,6 @@ class RF24
152
152
*/
153
153
uint8_t flush_rx (void );
154
154
155
- /* *
156
- * Empty the transmit buffer
157
- *
158
- * @return Current value of status register
159
- */
160
- uint8_t flush_tx (void );
161
-
162
155
/* *
163
156
* Retrieve the current status of the chip
164
157
*
@@ -270,7 +263,7 @@ class RF24
270
263
void stopListening (void );
271
264
272
265
/* *
273
- * @note Optimization: Improved performance and reliability
266
+ * @note Optimization: Improved performance slightly
274
267
* Write to the open writing pipe
275
268
*
276
269
* Be sure to call openWritingPipe() first to set the destination
@@ -293,56 +286,57 @@ class RF24
293
286
bool write ( const void * buf, uint8_t len );
294
287
295
288
/* *
296
- * @note Optimization: New Command
297
- * Write to the open writing pipe filling up the FIFO buffers
298
- *
299
- * Be sure to call openWritingPipe() first to set the destination
300
- * of where to write to.
301
- *
289
+ * @note Optimization: New Command *
302
290
* This will not block until the 3 FIFO buffers are filled with data.
303
291
* Once the FIFOs are full, writeFast will simply wait for success or
304
292
* timeout, and return 1 or 0 respectively. From a user perspective, just
305
293
* keep trying to send the same data. The library will keep auto retrying
306
294
* the current payload using the built in functionality.
307
295
*
308
- * The maximum size of data written is the fixed payload size, see
309
- * getPayloadSize(). However, you can write less, and the remainder
310
- * will just be filled with zeroes.
311
- *
312
296
* ONLY max retry interrupt flags will be cleared when writeFast is called
313
297
*
298
+ * @code
299
+ * Example (Partial blocking):
300
+ *
301
+ * radio.writeFast(&buf,32); // Writes 1 payload to the buffers
302
+ * txStandBy(); // Returns 0 if failed. 1 if success. Blocks only until MAX_RT timeout or success. Data flushed on fail.
303
+ * @endcode
304
+ *
305
+ * @see txStandBy()
306
+ * @see write()
307
+ * @see writeBlocking()
308
+ *
314
309
* @param buf Pointer to the data to be sent
315
310
* @param len Number of bytes to be sent
316
311
* @return True if the payload was delivered successfully false if not
317
312
*/
318
313
bool writeFast ( const void * buf, uint8_t len );
319
314
320
- /* *
321
- * @note Optimization: New Command
322
- * Write to the open writing pipe
323
- *
324
- * Be sure to call openWritingPipe() first to set the destination
325
- * of where to write to.
326
- *
327
- * This will not block until the 3 FIFO buffers are filled with data or
328
- * a timeout is detected. If so the library will auto retry until a new
329
- * payload is written or the TX buffers are flushed. Interrupts can be
330
- * used to control the timeout period.
331
- *
332
- * This will never return a 0. It will not return until a packet is
333
- * loaded successfully into the FIFO and TX is complete.
334
- *
335
- * The maximum size of data written is the fixed payload size, see
336
- * getPayloadSize(). However, you can write less, and the remainder
337
- * will just be filled with zeroes.
338
- *
339
- * ONLY max retry interrupt flags will be cleared when writeBlocking is called
340
- *
341
- * @param buf Pointer to the data to be sent
342
- * @param len Number of bytes to be sent
343
- * @return True if the payload was delivered successfully false if not
344
- */
345
- bool writeBlocking ( const void * buf, uint8_t len );
315
+ /* *
316
+ * @note Optimization: New Command
317
+ * This function extends the auto-retry mechanism to any specified duration.
318
+ * It will not block until the 3 FIFO buffers are filled with data.
319
+ * If so the library will auto retry until a new payload is written
320
+ * or the user specified timeout period is reached.
321
+ *
322
+ * ONLY max retry interrupt flags will be cleared when writeBlocking is called
323
+ * @code
324
+ * Example (Full blocking):
325
+ *
326
+ * radio.writeBlocking(&buf,32,1000); //Writes 1 payload to the buffers with extended timeout of 1 second
327
+ * txStandBy(1000); //Returns 0 if failed after timeout period. 1 if success.
328
+ * //Blocks only until user timeout or success. Data flushed on fail.
329
+ * @endcode
330
+ * @see txStandBy()
331
+ * @see write()
332
+ * @see writeFast()
333
+ *
334
+ * @param buf Pointer to the data to be sent
335
+ * @param len Number of bytes to be sent
336
+ * @param timeout User defined timeout in milliseconds.
337
+ * @return True if the payload was delivered successfully false if not
338
+ */
339
+ bool writeBlocking ( const void * buf, uint8_t len, uint32_t timeout );
346
340
347
341
/* *
348
342
* @note Optimization: New Command
@@ -355,29 +349,42 @@ class RF24
355
349
* the manufacturer to drop the radio out of TX or STANDBY-II mode if there is
356
350
* time enough between sends for the FIFOs to empty.
357
351
*
358
- * @note This does NOT need to be called when using per-payload noACK commands,
359
- * or when using the regular write command since it is only capable of single
360
- * payload transmission..
361
- * Per the datasheet, the radio will automatically engage STANDBY-I mode when
362
- * using the W_TX_PAYLOAD_NOACK command.
352
+ * Relies on built-in auto retry functionality.
363
353
*
364
354
* @code
365
- * Example:
355
+ * Example (Partial blocking):
356
+ *
366
357
* radio.writeFast(&buf,32);
367
358
* radio.writeFast(&buf,32);
368
359
* radio.writeFast(&buf,32); //Fills the FIFO buffers up
369
- * bool ok = txStandBy(0); //Returns 0 if failed. 1 if success.
370
- * //Blocks only until timeout or success. Data flushed on fail.
360
+ * bool ok = txStandBy(); //Returns 0 if failed. 1 if success.
361
+ * //Blocks only until MAX_RT timeout or success. Data flushed on fail.
362
+ * @endcode
363
+ * @see txStandBy(unsigned long timeout)
364
+ * @return True if transmission is successful
371
365
*
372
- * Using txStandBy(1) will not return until the data is transmitted. It will never return 0.
366
+ */
367
+ bool txStandBy ();
368
+
369
+ /* *
370
+ * @note Optimization: New Command
373
371
*
372
+ * This function allows extended blocking and auto-retries per a user defined timeout
373
+ * @code
374
+ * Fully Blocking Example:
375
+ *
376
+ * radio.writeFast(&buf,32);
377
+ * radio.writeFast(&buf,32);
378
+ * radio.writeFast(&buf,32); //Fills the FIFO buffers up
379
+ * bool ok = txStandBy(1000); //Returns 0 if failed after 1 second of retries. 1 if success.
380
+ * //Blocks only until user defined timeout or success. Data flushed on fail.
374
381
* @endcode
375
382
*
383
+ * @param timeout Number of milliseconds to retry failed payloads
376
384
* @return True if transmission is successful
377
385
*
378
386
*/
379
- bool txStandBy ();
380
- bool txStandBy (bool block);
387
+ bool txStandBy (unsigned long timeout);
381
388
382
389
/* *
383
390
* Non-blocking write to the open writing pipe used for buffered writes
@@ -386,7 +393,9 @@ class RF24
386
393
* will remain in TX or STANDBY-II Mode until a txStandBy() command is issued.
387
394
* This allows the chip to be used to its full potential in TX mode.
388
395
*
396
+ * @see write()
389
397
* @see writeFast()
398
+ * @see startWrite()
390
399
* @see writeBlocking()
391
400
*
392
401
* @param buf Pointer to the data to be sent
@@ -401,9 +410,14 @@ class RF24
401
410
* @note Optimization: The available functino now checks the FIFO
402
411
* buffers directly for data instead of relying of interrupt flags.
403
412
*
404
- * @note: Interrupt flags will not be cleared until a payload is
413
+ * @note Interrupt flags will not be cleared until a payload is
405
414
* actually read from the FIFO
406
415
*
416
+ * @see txStandBy()
417
+ * @see startWrite()
418
+ * @see write()
419
+ * @see writeFast()
420
+ *
407
421
* @return True if there is a payload available, false if none is
408
422
*/
409
423
bool available (void );
@@ -422,7 +436,7 @@ class RF24
422
436
*
423
437
* @param buf Pointer to a buffer where the data should be written
424
438
* @param len Maximum number of bytes to read into the buffer
425
- * @return No return value. Use available.
439
+ * @return No return value. Use available() .
426
440
*/
427
441
void read ( void * buf, uint8_t len );
428
442
@@ -526,7 +540,7 @@ class RF24
526
540
* For dynamic payloads, this pulls the size of the payload off
527
541
* the chip
528
542
*
529
- * Optimization: Corrupt packets are now detected and flushed per the
543
+ * @note Optimization: Corrupt packets are now detected and flushed per the
530
544
* manufacturer.
531
545
*
532
546
* @return Payload length of last-received dynamic payload
@@ -663,7 +677,7 @@ class RF24
663
677
* To return to normal power mode, either write() some data or
664
678
* startListening, or powerUp().
665
679
*
666
- * Optimization: The radio will never enter power down unless instructed
680
+ * @note Optimization: The radio will never enter power down unless instructed
667
681
* by the MCU via this command.
668
682
*/
669
683
void powerDown (void );
@@ -681,10 +695,12 @@ class RF24
681
695
* Just like write(), but it returns immediately. To find out what happened
682
696
* to the send, catch the IRQ and then call whatHappened().
683
697
*
684
- * @note Optimization: This function again behaves as it did previously.
685
- * startFastWrite() has been moved to an internal function
698
+ * @note Optimization: This function again behaves as it did previously for backwards-compatibility.
699
+ * with user code. The library uses startFastWrite() internally.
700
+ * This is mainly used for single-payload transactions.
686
701
*
687
702
* @see write()
703
+ * @see writeFast()
688
704
* @see startFastWrite()
689
705
* @see whatHappened()
690
706
*
@@ -708,6 +724,8 @@ class RF24
708
724
*
709
725
* @note This is to be used AFTER auto-retry fails if wanting to resend
710
726
* using the built-in payload reuse features.
727
+ * After issuing reUseTX(), it will keep reending the same payload forever or until
728
+ * a payload is written to the FIFO, or a flush_tx command is given.
711
729
*/
712
730
void reUseTX ();
713
731
@@ -735,7 +753,7 @@ class RF24
735
753
*
736
754
* @note Optimization: Calling this function NO LONGER clears the interrupt
737
755
* flag. The new functionality checks the RX FIFO buffer for an ACK payload
738
- * instead of relying on interrupt flags.
756
+ * instead of relying on interrupt flags.Reading the payload will clear the flags.
739
757
*
740
758
* @return True if an ack payload is available.
741
759
*/
@@ -766,6 +784,13 @@ class RF24
766
784
*/
767
785
void whatHappened (bool & tx_ok,bool & tx_fail,bool & rx_ready);
768
786
787
+ /* *
788
+ * Empty the transmit buffer
789
+ *
790
+ * @return Current value of status register
791
+ */
792
+ uint8_t flush_tx (void );
793
+
769
794
/* *
770
795
* Test whether there was a carrier on the line for the
771
796
* previous listening period.
@@ -797,6 +822,11 @@ class RF24
797
822
*/
798
823
bool isValid () { return ce_pin != 0xff && csn_pin != 0xff ; }
799
824
825
+ /* *
826
+ * @see txStandBy()
827
+ */
828
+ bool txStandBy (bool block);
829
+
800
830
/* *@}*/
801
831
};
802
832
@@ -824,6 +854,18 @@ class RF24
824
854
* with the receiver displaying the payload count. (32Byte Payloads)
825
855
*/
826
856
857
+ /* *
858
+ * @example TransferTimeouts.ino
859
+ * Updated: TMRh20
860
+ * This example demonstrates the use of and extended timeout period and
861
+ * auto-retries/auto-reUse to increase reliability in noisy or low signal scenarios.
862
+ *
863
+ * Write this sketch to two different nodes. Put one of the nodes into 'transmit'
864
+ * mode by connecting with the serial monitor and sending a 'T'. The data
865
+ * transfer will begin, with the receiver displaying the payload count and the
866
+ * data transfer rate.
867
+ */
868
+
827
869
/* *
828
870
* @example nordic_fob.pde
829
871
*
0 commit comments