From f0d0fb284c302c8a46b10d34c64f5862806a4aac Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Thu, 1 Aug 2024 16:08:04 -0700 Subject: [PATCH] review write() --- src/radio/rf24/constants.rs | 1 + src/radio/rf24/radio.rs | 15 ++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/radio/rf24/constants.rs b/src/radio/rf24/constants.rs index 41b0652..16ec235 100644 --- a/src/radio/rf24/constants.rs +++ b/src/radio/rf24/constants.rs @@ -25,6 +25,7 @@ pub mod commands { pub const R_RX_PL_WID: u8 = 0x60; pub const R_RX_PAYLOAD: u8 = 0x61; pub const W_TX_PAYLOAD: u8 = 0xA0; + pub const W_TX_PAYLOAD_NO_ACK: u8 = 0xB0; pub const W_ACK_PAYLOAD: u8 = 0xA8; pub const FLUSH_TX: u8 = 0xE1; pub const FLUSH_RX: u8 = 0xE2; diff --git a/src/radio/rf24/radio.rs b/src/radio/rf24/radio.rs index a66ab23..d233efd 100644 --- a/src/radio/rf24/radio.rs +++ b/src/radio/rf24/radio.rs @@ -168,16 +168,13 @@ where // TX FIFO is full already return Ok(false); } - let mut buf_len = { - let len = buf.len(); - if len > 32 { - 32 - } else { - len - } - }; + let mut buf_len = buf.len().min(32); // to avoid resizing the given buf, we'll have to use self._buf directly - self._buf[0] = commands::W_TX_PAYLOAD | ((ask_no_ack as u8) << 4); + self._buf[0] = if !ask_no_ack { + commands::W_TX_PAYLOAD + } else { + commands::W_TX_PAYLOAD_NO_ACK + }; self._buf[1..(buf_len + 1)].copy_from_slice(&buf[..buf_len]); // ensure payload_length setting is respected if !self._dynamic_payloads_enabled && buf_len < self._payload_length as usize {