Commit e5058734 authored by Daniel Friesel's avatar Daniel Friesel
Browse files

RF24: toggles, add setPayloadSize

parent f0ad73ff
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -272,12 +272,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()
   *
   * @warning This MUST be called prior to attempting single write NOACK calls
@@ -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
+6 −6
Original line number Diff line number Diff line
@@ -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();
+26 −16
Original line number Diff line number Diff line
@@ -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,28 +332,33 @@ uint8_t Nrf24l01::writeRegister(uint8_t reg, uint8_t value)
	return rxbuf[0];
}

void Nrf24l01::enableDynamicPayloads(void)
void Nrf24l01::enableDynamicPayloads(const bool enabled)
{
	if (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));
	}
	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)
{
	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)
{