nRF24 / RF24

OSI Layer 2 driver for nRF24L01 on Arduino & Raspberry Pi/Linux Devices
https://nrf24.github.io/RF24
GNU General Public License v2.0
2.23k stars 1.02k forks source link

[Request] Enable dynamic payloads by default #660

Closed 2bndy5 closed 4 years ago

2bndy5 commented 4 years ago

According to the datasheet, dynamic payloads take less time to transmit. This library doesn't seem to like using them. I imagine that keeping dynamic payloads disabled by default increases cohesion with the nature of not-so-dynamically-sized arrays in C++. Although the examples for dynamic payloads appropriately use an array that allocates 33 bytes (32 for nRF24L01's maximum payload size + 1 NULL terminating character for "easy printing" as a C-string). Most other nRF24L01 libraries take advantage of this basic dynamic payloads feature.

Suggested changes

in RF24::begin(), change

write_register(DYNPD, 0);
dynamic_payloads_enabled = false;

to

write_register(DYNPD, 0x3F);
dynamic_payloads_enabled = true;

and also set dynamic_payloads_enabled private member to true in RF24::RF24() constructor.

Additional context

Enabling this would also reduce the need for a separate example on how to use dynamic payloads. The only difference at that point would be to add a comment that notes using getPayloadSize() instead of getDynamicPayloadSize() when dynamic payloads are disabled. This library already appends statically sized payloads with zeros to fill the TX FIFO levels accordingly. Of course setPayloadSize() would also need to be mentioned when dynamic payloads are disabled (which is rarely used in the current examples).

RF24Network also uses dynamic payloads, but I found this vague comment:

Enable dynamic payloads - If using different types of NRF24L01 modules, some may be incompatible when using this feature

@TMRh20 I have no idea what modules this could be referring to.

2bndy5 commented 4 years ago

turns out this idea breaks default compatibility with the Si24R1