pub fn write<D: DelayUs<u8>>(
        &mut self,
        delay: &mut D,
        buf: &[u8],
    ) -> Result<(), TransferError<SPIErr, PinErr>> {
        let send_count = if let PayloadSize::Static(n) = self.payload_size {
            let n = n as usize;
            // we have to send `n` bytes
            let len = core::cmp::min(buf.len(), n);
            self.tx_buf[1..=len].copy_from_slice(&buf[..len]);
            if len < MAX_PAYLOAD_SIZE as usize {
                self.tx_buf[len + 1..=n].fill(0);
            }
            // now our tx_buf is guarantueed to have `n` bytes filled
            n
        } else {
            // In dynamic payload mode, max payload_size is the limit
            core::cmp::min(buf.len(), MAX_PAYLOAD_SIZE as usize)
        };

        // Add instruction to buffer
        self.tx_buf[0] = Instruction::WTX.opcode();
        // Write to spi
        self.set_ncs_low()?;
        let r = self.spi_transfer_tx_buf(send_count)?;
        let status = Status::from(r[0]);
        self.set_ncs_high()?;

        // Start transmission:
        // pulse CE pin to signal transmission start
        self.set_ce_high()?;
        delay.delay_us(10);
        self.set_ce_low()?;

        // Clear interrupt flags
        self.write_register(Register::STATUS, Status::flags().value())?;

        // Max retries exceeded
        if status.reached_max_retries() {
            self.flush_tx()?;
            return Err(TransferError::MaximumRetries);
        }

        Ok(())
    }
/// Writes data to the opened channel.
///
/// # Examples
/// ```rust
/// // We will be sending float values
/// // Set the payload size to 4 bytes, the size of an f32
/// let config = NrfConfig::default().payload_size(PayloadSize::Static(4));
/// let chip = Nrf24l01::new(spi, ce, ncs, &mut delay, config).unwrap();
/// // Put the chip in transmission mode
/// chip.open_writing_pipe(b"Node1");
/// chip.stop_listening();
///
/// // The buffer where we will write data into before sending
/// let mut buffer = [0u8; 4];
/// loop {
///     let f = get_reading(); // data from some sensor
///     // reinterpret float to bytes and put into buffer
///     buffer.copy_from_slice(&f.to_le_bytes());
///
///     match chip.write(&mut delay, &buffer) {
///         Err(e) => eprintln!("Error while sending data {:?}", e),
///         Ok(_) => {
///             println!("Successfully wrote the data!");
///         },
///     }
///     // Wait some time before trying again
///     delay.delay_us(50u16);
/// }
/// ```
///
/// Will clear all interrupt flags after write.
/// Returns an error when max retries have been reached.
Writes data to the opened channel.
Writes data to the opened channel .
pub fn write<D: DelayUs<u8>>(
        &mut self,
        delay: &mut D,
        buf: &[u8],
    ) -> Result<(), TransferError<SPIErr, PinErr>> {
        let send_count = if let PayloadSize::Static(n) = self.payload_size {
            let n = n as usize;
            // we have to send `n` bytes
            let len = core::cmp::min(buf.len(), n);
            self.tx_buf[1..=len].copy_from_slice(&buf[..len]);
            if len < MAX_PAYLOAD_SIZE as usize {
                self.tx_buf[len + 1..=n].fill(0);
            }
            // now our tx_buf is guarantueed to have `n` bytes filled
            n
        } else {
            // In dynamic payload mode, max payload_size is the limit
            core::cmp::min(buf.len(), MAX_PAYLOAD_SIZE as usize)
        };
        // Add instruction to buffer
        self.tx_buf[0] = Instruction::WTX.opcode();
        // Write to spi
        self.set_ncs_low()?;
        let r = self.spi_transfer_tx_buf(send_count)?;
        let status = Status::from(r[0]);
        self.set_ncs_high()?;
        // Start transmission:
        // pulse CE pin to signal transmission start
        self.set_ce_high()?;
        delay.delay_us(10);
        self.set_ce_low()?;
        // Clear interrupt flags
        self.write_register(Register::STATUS, Status::flags().value())?;
        // Max retries exceeded
        if status.reached_max_retries() {
            self.flush_tx()?;
            return Err(TransferError::MaximumRetries);
        }
        Ok(())
    }
pub fn write < D : DelayUs < u8 > > ( & mut self , delay : & mut D , buf : & [ u8 ] , ) -> Result < ( ) , TransferError < SPIErr , PinErr > > { let send_count = if let PayloadSize :: Static ( n ) = self . payload_size { let n = n as usize ; // we have to send `n` bytes let len = core :: cmp :: min ( buf . len ( ) , n ) ; self . tx_buf [ 1 ..= len ] . copy_from_slice ( & buf [ .. len ] ) ; if len < MAX_PAYLOAD_SIZE as usize { self . tx_buf [ len + 1 ..= n ] . fill ( 0 ) ; } // now our tx_buf is guarantueed to have `n` bytes filled n } else { // In dynamic payload mode, max payload_size is the limit core :: cmp :: min ( buf . len ( ) , MAX_PAYLOAD_SIZE as usize ) } ; // Add instruction to buffer self . tx_buf [ 0 ] = Instruction :: WTX . opcode ( ) ; // Write to spi self . set_ncs_low ( ) ? ; let r = self . spi_transfer_tx_buf ( send_count ) ? ; let status = Status :: from ( r [ 0 ] ) ; self . set_ncs_high ( ) ? ; // Start transmission: // pulse CE pin to signal transmission start self . set_ce_high ( ) ? ; delay . delay_us ( 10 ) ; self . set_ce_low ( ) ? ; // Clear interrupt flags self . write_register ( Register :: STATUS , Status :: flags ( ) . value ( ) ) ? ; // Max retries exceeded if status . reached_max_retries ( ) { self . flush_tx ( ) ? ; return Err ( TransferError :: MaximumRetries ) ; } Ok ( ( ) ) }
Writes data to the opened channel.
Writes data to the opened channel .
&mut self
delay
&mut D
buf
&[u8]
&mut self
delay
&mut D
buf
&[u8]
examples
```rust
We will be sending float values
Set the payload size to 4 bytes, the size of an f32
let config = NrfConfig::default().payload_size(PayloadSize::Static(4));
let chip = Nrf24l01::new(spi, ce, ncs, &mut delay, config).unwrap();
Put the chip in transmission mode
chip.open_writing_pipe(b"Node1");
chip.stop_listening().

The buffer where we will write data into before sending
let mut buffer = [0u8; 4];
loop {
let f = get_reading(); // data from some sensor
reinterpret float to bytes and put into buffer
buffer.copy_from_slice(&f.to_le_bytes()).

match chip.write(&mut delay, &buffer) {
Err(e) => eprintln!("Error while sending data {:?}", e),
Ok(_) => {
println!("Successfully wrote the data!");
},
}
Wait some time before trying again
delay.delay_us(50u16);
}
```

Will clear all interrupt flags after write.
Returns an error when max retries have been reached.
` ` ` rust We will be sending float values Set the payload size to 4 bytes the size of an f32 let config = NrfConfig :: default () . payload_size ( PayloadSize :: Static ( 4 )) ; let chip = Nrf24l01 :: new ( spi ce ncs &mut delay config ) . unwrap () ; Put the chip in transmission mode chip . open_writing_pipe ( b " Node1 " ) ; chip . stop_listening () . The buffer where we will write data into before sending let mut buffer = [ 0u8 ; 4 ] ; loop { let f = get_reading () ; // data from some sensor reinterpret float to bytes and put into buffer buffer . copy_from_slice ( &f . to_le_bytes () ) . match chip . write ( &mut delay &buffer ) { Err ( e ) = > eprintln! ( " Error while sending data { : ? } " e ) Ok ( _ ) = > { println! ( " Successfully wrote the data! " ) ; } } Wait some time before trying again delay . delay_us ( 50u16 ) ; } ` ` ` Will clear all interrupt flags after write . Returns an error when max retries have been reached .