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

addsetautoack

parent a73f21f7
Loading
Loading
Loading
Loading
+24 −3
Original line number Diff line number Diff line
@@ -275,7 +275,7 @@ public:
   * @param enable desired DynamicPayloads status
   *
   */
	void enableDynamicPayloads(bool enabled);
	void setDynamicPayloads(bool enabled);

	/**
   * Enable dynamic ACKs (single write multicast or unicast) for chosen messages
@@ -286,12 +286,33 @@ public:
   *
   * @warning This MUST be called prior to attempting single write NOACK calls
   * @code
   * radio.enableDynamicAck();
   * radio.setDynamicAck();
   * radio.write(&data,32,1);  // Sends a payload with no acknowledgement requested
   * radio.write(&data,32,0);  // Sends a payload using auto-retry/autoACK
   * @endcode
   */
  void enableDynamicAck(bool enabled);
	void setDynamicAck(bool enabled);

	/**
   * Enable or disable auto-acknowlede packets
   *
   * This is enabled by default, so it's only needed if you want to turn
   * it off for some reason.
   *
   * @param enable Whether to enable (true) or disable (false) auto-acks
   */
	void setAutoAck(bool enable);

	/**
   * Enable or disable auto-acknowlede packets on a per pipeline basis.
   *
   * AA is enabled by default, so it's only needed if you want to turn
   * it off/on for some reason on a per pipeline basis.
   *
   * @param pipe Which pipeline to modify
   * @param enable Whether to enable (true) or disable (false) auto-acks
   */
	void setAutoAck(uint8_t pipe, bool enable);

	/**
   * Be sure to call openWritingPipe() first to set the destination
+2 −2
Original line number Diff line number Diff line
@@ -35,8 +35,8 @@ void loop(void)

	kout << "write: ";
	nrf24l01.setRetries(0, 0);
	nrf24l01.enableDynamicPayloads(false);
	nrf24l01.enableDynamicAck(false);
	nrf24l01.setDynamicPayloads(false);
	nrf24l01.setDynamicAck(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));
+27 −2
Original line number Diff line number Diff line
@@ -338,7 +338,7 @@ uint8_t Nrf24l01::writeRegister(uint8_t reg, uint8_t value)
	return rxbuf[0];
}

void Nrf24l01::enableDynamicPayloads(const bool enabled)
void Nrf24l01::setDynamicPayloads(const bool enabled)
{
	if (enabled)
	{
@@ -354,7 +354,7 @@ void Nrf24l01::enableDynamicPayloads(const bool enabled)
	dynamic_payloads_enabled = enabled;
}

void Nrf24l01::enableDynamicAck(const bool enabled)
void Nrf24l01::setDynamicAck(const bool enabled)
{
	if (enabled)
	{
@@ -366,6 +366,31 @@ void Nrf24l01::enableDynamicAck(const bool enabled)
	}
}

void Nrf24l01::setAutoAck(bool enable)
{
  if ( enable )
    writeRegister(EN_AA, 0b111111);
  else
    writeRegister(EN_AA, 0);
}

void Nrf24l01::setAutoAck( uint8_t pipe, bool enable )
{
  if ( pipe <= 6 )
  {
    uint8_t en_aa = readRegister( EN_AA ) ;
    if( enable )
    {
      en_aa |= (1<<pipe) ;
    }
    else
    {
      en_aa &= ~(1<<pipe) ;
    }
    writeRegister( EN_AA, en_aa ) ;
  }
}

uint8_t Nrf24l01::writePayload(const void *buf, uint8_t data_len, const uint8_t writeType)
{
	data_len = rf24_min(data_len, payload_size);