Skip to content

Commit

Permalink
review write()
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Aug 1, 2024
1 parent f6df82a commit f0d0fb2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/radio/rf24/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 6 additions & 9 deletions src/radio/rf24/radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f0d0fb2

Please sign in to comment.