diff options
-rw-r--r-- | include/driver/nrf24l01.h | 8 | ||||
-rw-r--r-- | src/app/nrf24l01test/main.cc | 12 | ||||
-rw-r--r-- | src/driver/nrf24l01.cc | 42 |
3 files changed, 38 insertions, 24 deletions
diff --git a/include/driver/nrf24l01.h b/include/driver/nrf24l01.h index 82297bd..ae88640 100644 --- a/include/driver/nrf24l01.h +++ b/include/driver/nrf24l01.h @@ -271,12 +271,16 @@ public: * * This way you don't always have to send large packets just to send them * once in a while. This enables dynamic payloads on ALL pipes. + * + * @param enable desired DynamicPayloads status * */ - void enableDynamicPayloads(void); + void enableDynamicPayloads(bool enabled); /** * Enable dynamic ACKs (single write multicast or unicast) for chosen messages + * + * @param enable desired DynamicAck status * * @note To enable full multicast or per-pipe multicast, use setAutoAck() * @@ -287,7 +291,7 @@ public: * radio.write(&data,32,0); // Sends a payload using auto-retry/autoACK * @endcode */ - void enableDynamicAck(); + void enableDynamicAck(bool enabled); /** * Be sure to call openWritingPipe() first to set the destination diff --git a/src/app/nrf24l01test/main.cc b/src/app/nrf24l01test/main.cc index 187a9c1..9dddb58 100644 --- a/src/app/nrf24l01test/main.cc +++ b/src/app/nrf24l01test/main.cc @@ -35,12 +35,12 @@ void loop(void) kout << "write: "; nrf24l01.setRetries(0, 0); - nrf24l01.enableDynamicPayloads(); - nrf24l01.enableDynamicAck(); - TIMEIT("blocking write(3)", nrf24l01.write("foo", 3, false, true)); - TIMEIT("blocking write(10)", nrf24l01.write("123456789", 10, false, true)); - TIMEIT("blocking write(20)", nrf24l01.write("123456789123456789", 20, false, true)); - TIMEIT("blocking write(30)", nrf24l01.write("123456789123456789123456789", 30, false, true)); + nrf24l01.enableDynamicPayloads(false); + nrf24l01.enableDynamicAck(false); + TIMEIT("blocking write(3)", nrf24l01.write("foo", 3, true, true)); + TIMEIT("blocking write(10)", nrf24l01.write("123456789", 10, true, true)); + TIMEIT("blocking write(20)", nrf24l01.write("123456789123456789", 20, true, true)); + //TIMEIT("blocking write(30)", nrf24l01.write("123456789123456789123456789", 30, true, true)); nrf24l01.startListening(); arch.delay_ms(10); nrf24l01.stopListening(); diff --git a/src/driver/nrf24l01.cc b/src/driver/nrf24l01.cc index a678655..0bb4656 100644 --- a/src/driver/nrf24l01.cc +++ b/src/driver/nrf24l01.cc @@ -100,6 +100,11 @@ void Nrf24l01::setRetries(uint8_t delay, uint8_t count) writeRegister(SETUP_RETR, (delay & 0xf) << ARD | (count & 0xf) << ARC); } +void Nrf24l01::setPayloadSize(uint8_t size) +{ + payload_size = rf24_min(size, 32); +} + void Nrf24l01::setPALevel(uint8_t level) { uint8_t setup = readRegister(RF_SETUP) & 0b11111000; @@ -327,27 +332,32 @@ uint8_t Nrf24l01::writeRegister(uint8_t reg, uint8_t value) return rxbuf[0]; } -void Nrf24l01::enableDynamicPayloads(void) +void Nrf24l01::enableDynamicPayloads(const bool enabled) { - // Enable dynamic payload throughout the system - - //toggle_features(); - writeRegister(FEATURE, readRegister(FEATURE) | (1 << EN_DPL)); - - //IF_SERIAL_DEBUG(printf("FEATURE=%i\r\n",read_register(FEATURE))); - - // Enable dynamic payload on all pipes - // - // Not sure the use case of only having dynamic payload on certain - // pipes, so the library does not support it. - writeRegister(DYNPD, readRegister(DYNPD) | (1 << DPL_P5) | (1 << DPL_P4) | (1 << DPL_P3) | (1 << DPL_P2) | (1 << DPL_P1) | (1 << DPL_P0)); + if (enabled) + { + writeRegister(FEATURE, readRegister(FEATURE) | (1 << EN_DPL)); + writeRegister(DYNPD, readRegister(DYNPD) | (1 << DPL_P5) | (1 << DPL_P4) | (1 << DPL_P3) | (1 << DPL_P2) | (1 << DPL_P1) | (1 << DPL_P0)); + } + else + { + writeRegister(FEATURE, readRegister(FEATURE) & ~(1 << EN_DPL)); + writeRegister(DYNPD, readRegister(DYNPD) & ~((1 << DPL_P5) | (1 << DPL_P4) | (1 << DPL_P3) | (1 << DPL_P2) | (1 << DPL_P1) | (1 << DPL_P0))); + } - dynamic_payloads_enabled = true; + dynamic_payloads_enabled = enabled; } -void Nrf24l01::enableDynamicAck(void) +void Nrf24l01::enableDynamicAck(const bool enabled) { - writeRegister(FEATURE, readRegister(FEATURE) | (1 << EN_DYN_ACK)); + if (enabled) + { + writeRegister(FEATURE, readRegister(FEATURE) | (1 << EN_DYN_ACK)); + } + else + { + writeRegister(FEATURE, readRegister(FEATURE) & ~(1 << EN_DYN_ACK)); + } } uint8_t Nrf24l01::writePayload(const void *buf, uint8_t data_len, const uint8_t writeType) |