Skip to content

Commit 39d8287

Browse files
committed
style: remove _ prefix from private members
Field and variable names prefixed with `_` tells the rust linter ("clippy" tool) that unused dead code shall be explicitly ignored. This does not bode well for static analysis on production code. Coming from Arduino, this isn't the case. Arduino lib convention suggests to prefix private members with a `_` for readability. Many C++ linters don't treat the `_` prefix of member/variable/parameter names in any special way (excluding `#include` guards).
1 parent 3085709 commit 39d8287

19 files changed

Lines changed: 174 additions & 174 deletions

File tree

bindings/node/src/radio/config.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use napi::{bindgen_prelude::Buffer, JsNumber, Result};
88
#[derive(Debug, Clone, Copy)]
99
pub struct RadioConfig {
1010
inner: rf24::radio::RadioConfig,
11-
_addr_buf: [u8; 5],
11+
addr_buf: [u8; 5],
1212
}
1313

1414
#[napi]
@@ -53,7 +53,7 @@ impl RadioConfig {
5353
pub fn new() -> Self {
5454
Self {
5555
inner: rf24::radio::RadioConfig::default(),
56-
_addr_buf: [0u8; 5],
56+
addr_buf: [0u8; 5],
5757
}
5858
}
5959

@@ -344,8 +344,8 @@ impl RadioConfig {
344344
/// Get the address for a specified `pipe` set by {@link RadioConfig.setRxAddress}.
345345
#[napi]
346346
pub fn get_rx_address(&mut self, pipe: u8) -> Buffer {
347-
self.inner.rx_address(pipe, &mut self._addr_buf);
348-
Buffer::from(self._addr_buf.to_vec())
347+
self.inner.rx_address(pipe, &mut self.addr_buf);
348+
Buffer::from(self.addr_buf.to_vec())
349349
}
350350

351351
/// Set the TX address.
@@ -359,8 +359,8 @@ impl RadioConfig {
359359

360360
#[napi(getter, js_name = "txAddress")]
361361
pub fn get_tx_address(&mut self) -> Buffer {
362-
self.inner.tx_address(&mut self._addr_buf);
363-
Buffer::from(self._addr_buf.to_vec())
362+
self.inner.tx_address(&mut self.addr_buf);
363+
Buffer::from(self.addr_buf.to_vec())
364364
}
365365

366366
/// Close a RX pipe from receiving data.
@@ -381,7 +381,7 @@ impl RadioConfig {
381381
pub fn from_inner(config: rf24::radio::RadioConfig) -> Self {
382382
Self {
383383
inner: config,
384-
_addr_buf: [0u8; 5],
384+
addr_buf: [0u8; 5],
385385
}
386386
}
387387
}

bindings/python/src/radio/config.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use std::borrow::Cow;
4444
#[derive(Debug, Clone, Copy)]
4545
pub struct RadioConfig {
4646
inner: rf24::radio::RadioConfig,
47-
_addr_buf: [u8; 5],
47+
addr_buf: [u8; 5],
4848
}
4949

5050
#[pymethods]
@@ -53,7 +53,7 @@ impl RadioConfig {
5353
pub fn new() -> Self {
5454
Self {
5555
inner: rf24::radio::RadioConfig::default(),
56-
_addr_buf: [0u8; 5],
56+
addr_buf: [0u8; 5],
5757
}
5858
}
5959

@@ -305,17 +305,17 @@ impl RadioConfig {
305305

306306
/// Get the address for a specified `pipe` set by [`RadioConfig.set_rx_address()`][rf24_py.RadioConfig.set_rx_address].
307307
pub fn get_rx_address(&mut self, pipe: u8) -> Cow<[u8]> {
308-
self.inner.rx_address(pipe, &mut self._addr_buf);
309-
Cow::from(&self._addr_buf)
308+
self.inner.rx_address(pipe, &mut self.addr_buf);
309+
Cow::from(&self.addr_buf)
310310
}
311311

312312
/// Set the TX address.
313313
///
314314
/// Only pipe 0 can be used for TX operations (including auto-ACK packets during RX operations).
315315
#[getter]
316316
pub fn get_tx_address(&mut self) -> Cow<[u8]> {
317-
self.inner.tx_address(&mut self._addr_buf);
318-
Cow::from(&self._addr_buf)
317+
self.inner.tx_address(&mut self.addr_buf);
318+
Cow::from(&self.addr_buf)
319319
}
320320

321321
#[setter]
@@ -339,7 +339,7 @@ impl RadioConfig {
339339
pub fn from_inner(config: rf24::radio::RadioConfig) -> Self {
340340
Self {
341341
inner: config,
342-
_addr_buf: [0u8; 5],
342+
addr_buf: [0u8; 5],
343343
}
344344
}
345345
}

crates/rf24-rs/src/radio/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::radio::rf24::bit_fields::{Config, Feature, SetupRetry, SetupRfAw};
1+
use crate::radio::rf24::bit_fields::{ConfigReg, Feature, SetupRetry, SetupRfAw};
22
use crate::{CrcLength, DataRate, PaLevel};
33

44
/// A struct to contain configuration about pipe addresses.
@@ -95,7 +95,7 @@ impl EsbPipeConfig {
9595
/// ```
9696
#[derive(Debug, Clone, Copy)]
9797
pub struct RadioConfig {
98-
pub(crate) config_reg: Config,
98+
pub(crate) config_reg: ConfigReg,
9999
pub(crate) auto_retries: SetupRetry,
100100
pub(crate) setup_rf_aw: SetupRfAw,
101101
pub(crate) feature: Feature,
@@ -150,7 +150,7 @@ impl Default for RadioConfig {
150150
- powered down
151151
- inactive TX (StandBy-I) mode
152152
*/
153-
config_reg: Config::default(),
153+
config_reg: ConfigReg::default(),
154154
/*
155155
- 5 * 250 + 250 = 1500 us delay between attempts
156156
- 15 max attempts

crates/rf24-rs/src/radio/prelude.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ pub trait EsbAutoAck: EsbPayloadLength {
336336
/// Both parameters are clamped to range [0, 15].
337337
/// - `delay`: How long to wait between each retry, in multiples of
338338
/// 250 us (microseconds). The minimum value of 0 means 250 us, and
339-
/// the maximum valueof 15 means 4000 us.
339+
/// the maximum value of 15 means 4000 us.
340340
/// The default value of 5 means 1500us (`5 * 250 + 250`).
341341
/// - `count`: How many retries before giving up. The default/maximum is 15. Use
342342
/// 0 to disable the auto-retry feature.

crates/rf24-rs/src/radio/rf24/auto_ack.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ where
1313
type AutoAckErrorType = Nrf24Error<SPI::Error, DO::Error>;
1414

1515
fn set_ack_payloads(&mut self, enable: bool) -> Result<(), Self::AutoAckErrorType> {
16-
if self._feature.ack_payloads() != enable {
16+
if self.feature.ack_payloads() != enable {
1717
self.spi_read(1, registers::FEATURE)?;
18-
self._feature =
19-
Feature::from_bits(self._feature.into_bits() & !Feature::REG_MASK | self._buf[1])
18+
self.feature =
19+
Feature::from_bits(self.feature.into_bits() & !Feature::REG_MASK | self.buf[1])
2020
.with_ack_payloads(enable);
2121
self.spi_write_byte(
2222
registers::FEATURE,
23-
self._feature.into_bits() & Feature::REG_MASK,
23+
self.feature.into_bits() & Feature::REG_MASK,
2424
)?;
2525

2626
if enable {
@@ -33,13 +33,13 @@ where
3333
}
3434

3535
fn get_ack_payloads(&self) -> bool {
36-
self._feature.ack_payloads()
36+
self.feature.ack_payloads()
3737
}
3838

3939
fn set_auto_ack(&mut self, enable: bool) -> Result<(), Self::AutoAckErrorType> {
4040
self.spi_write_byte(registers::EN_AA, 0x3F * enable as u8)?;
4141
// accommodate ACK payloads feature
42-
if !enable && self._feature.ack_payloads() {
42+
if !enable && self.feature.ack_payloads() {
4343
self.set_ack_payloads(false)?;
4444
}
4545
Ok(())
@@ -51,23 +51,23 @@ where
5151
}
5252
self.spi_read(1, registers::EN_AA)?;
5353
let mask = 1 << pipe;
54-
let reg_val = self._buf[1];
55-
if !enable && self._feature.ack_payloads() && pipe == 0 {
54+
let reg_val = self.buf[1];
55+
if !enable && self.feature.ack_payloads() && pipe == 0 {
5656
self.set_ack_payloads(enable)?;
5757
}
5858
self.spi_write_byte(registers::EN_AA, reg_val & !mask | (mask * enable as u8))
5959
}
6060

6161
fn allow_ask_no_ack(&mut self, enable: bool) -> Result<(), Self::AutoAckErrorType> {
6262
self.spi_read(1, registers::FEATURE)?;
63-
self.spi_write_byte(registers::FEATURE, self._buf[1] & !1 | enable as u8)
63+
self.spi_write_byte(registers::FEATURE, self.buf[1] & !1 | enable as u8)
6464
}
6565

6666
fn write_ack_payload(&mut self, pipe: u8, buf: &[u8]) -> Result<bool, Self::AutoAckErrorType> {
67-
if self._feature.ack_payloads() && pipe <= 5 {
67+
if self.feature.ack_payloads() && pipe <= 5 {
6868
let len = buf.len().min(32);
6969
self.spi_write_buf(commands::W_ACK_PAYLOAD | pipe, &buf[..len])?;
70-
return Ok(!self._status.tx_full());
70+
return Ok(!self.status.tx_full());
7171
}
7272
Ok(false)
7373
}

crates/rf24-rs/src/radio/rf24/bit_fields.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{CrcLength, DataRate, PaLevel};
55
use super::mnemonics;
66

77
#[bitfield(u8, order = Msb)]
8-
pub(crate) struct Config {
8+
pub(crate) struct ConfigReg {
99
#[bits(1)]
1010
_padding: u8,
1111

@@ -29,7 +29,7 @@ pub(crate) struct Config {
2929
pub is_rx: bool,
3030
}
3131

32-
impl Config {
32+
impl ConfigReg {
3333
pub(crate) const CRC_MASK: u8 = 0b1100;
3434

3535
pub const fn crc_length(&self) -> CrcLength {

crates/rf24-rs/src/radio/rf24/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ where
1919
/// See also [`RF24::set_channel()`].
2020
fn get_channel(&mut self) -> Result<u8, Self::ChannelErrorType> {
2121
self.spi_read(1, registers::RF_CH)?;
22-
Ok(self._buf[1])
22+
Ok(self.buf[1])
2323
}
2424
}
2525

crates/rf24-rs/src/radio/rf24/crc_length.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use embedded_hal::{delay::DelayNs, digital::OutputPin, spi::SpiDevice};
22

3-
use super::{registers, Config};
3+
use super::{registers, ConfigReg};
44
use crate::radio::{prelude::EsbCrcLength, Nrf24Error, RF24};
55
use crate::CrcLength;
66

@@ -14,17 +14,17 @@ where
1414

1515
fn get_crc_length(&mut self) -> Result<CrcLength, Self::CrcLengthErrorType> {
1616
self.spi_read(1, registers::CONFIG)?;
17-
if self._buf[1] & Config::CRC_MASK == 4 {
17+
if self.buf[1] & ConfigReg::CRC_MASK == 4 {
1818
return Err(Nrf24Error::BinaryCorruption);
1919
}
20-
self._config_reg = Config::from_bits(self._buf[1]);
21-
Ok(self._config_reg.crc_length())
20+
self.config_reg = ConfigReg::from_bits(self.buf[1]);
21+
Ok(self.config_reg.crc_length())
2222
}
2323

2424
fn set_crc_length(&mut self, crc_length: CrcLength) -> Result<(), Self::CrcLengthErrorType> {
2525
self.spi_read(1, registers::CONFIG)?;
26-
self._config_reg = self._config_reg.with_crc_length(crc_length);
27-
self.spi_write_byte(registers::CONFIG, self._config_reg.into_bits())
26+
self.config_reg = self.config_reg.with_crc_length(crc_length);
27+
self.spi_write_byte(registers::CONFIG, self.config_reg.into_bits())
2828
}
2929
}
3030

crates/rf24-rs/src/radio/rf24/data_rate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ where
2525

2626
fn get_data_rate(&mut self) -> Result<DataRate, Self::DataRateErrorType> {
2727
self.spi_read(1, registers::RF_SETUP)?;
28-
let da_bin = self._buf[1] & DataRate::MASK;
28+
let da_bin = self.buf[1] & DataRate::MASK;
2929
if da_bin == DataRate::MASK {
3030
return Err(Nrf24Error::BinaryCorruption);
3131
}
@@ -36,7 +36,7 @@ where
3636
self.tx_delay = set_tx_delay(data_rate);
3737
self.spi_read(1, registers::RF_SETUP)?;
3838
let da_bin = data_rate.into_bits();
39-
let out = self._buf[1] & !DataRate::MASK | da_bin;
39+
let out = self.buf[1] & !DataRate::MASK | da_bin;
4040
self.spi_write_byte(registers::RF_SETUP, out)
4141
}
4242
}

crates/rf24-rs/src/radio/rf24/details.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ where
164164
#[cfg(not(target_os = "none"))]
165165
#[cfg(feature = "std")]
166166
fn print_details(&mut self) -> Result<(), Self::DetailsErrorType> {
167-
use crate::radio::rf24::Config;
167+
use crate::radio::rf24::ConfigReg;
168168

169169
std::println!("Is a plus variant_________{}", self.is_plus_variant());
170170

@@ -178,7 +178,7 @@ where
178178
std::println!("RF Power Amplifier________{}", self.get_pa_level()?);
179179

180180
self.spi_read(1, registers::RF_SETUP)?;
181-
let rf_setup = self._buf[1];
181+
let rf_setup = self.buf[1];
182182
std::println!("RF LNA enabled____________{}", rf_setup & 1 > 0);
183183

184184
std::println!("CRC Length________________{}", self.get_crc_length()?);
@@ -194,70 +194,70 @@ where
194194
);
195195

196196
self.spi_read(1, registers::SETUP_RETR)?;
197-
let retry_setup = self._buf[1];
197+
let retry_setup = self.buf[1];
198198
std::println!(
199199
"Auto retry delay__________{} microseconds",
200200
(retry_setup >> 4) as u16 * 250 + 250
201201
);
202202
std::println!("Auto retry attempts_______{} maximum", retry_setup & 0x0F);
203203

204204
self.spi_read(1, registers::FIFO_STATUS)?;
205-
std::println!("Re-use TX FIFO____________{}", (self._buf[1] & 0x80) > 0);
205+
std::println!("Re-use TX FIFO____________{}", (self.buf[1] & 0x80) > 0);
206206

207207
self.spi_read(1, registers::OBSERVE_TX)?;
208-
let observer = self._buf[1];
208+
let observer = self.buf[1];
209209
std::println!("Packets lost\n on current channel____{}", observer >> 4);
210210
std::println!(
211211
"Retry attempts made\n for last transmission_{}",
212212
observer & 0xF
213213
);
214214

215215
self.spi_read(1, registers::CONFIG)?;
216-
self._config_reg = Config::from_bits(self._buf[1]);
217-
std::println!("IRQ on Data Ready_________{}", self._config_reg.rx_dr());
218-
std::println!(" Data Ready triggered__{}", self._status.rx_dr());
219-
std::println!("IRQ on Data Sent__________{}", self._config_reg.tx_ds());
220-
std::println!(" Data Sent triggered___{}", self._status.tx_ds());
221-
std::println!("IRQ on Data Fail__________{}", self._config_reg.tx_df());
222-
std::println!(" Data Fail triggered___{}", self._status.tx_df());
216+
self.config_reg = ConfigReg::from_bits(self.buf[1]);
217+
std::println!("IRQ on Data Ready_________{}", self.config_reg.rx_dr());
218+
std::println!(" Data Ready triggered__{}", self.status.rx_dr());
219+
std::println!("IRQ on Data Sent__________{}", self.config_reg.tx_ds());
220+
std::println!(" Data Sent triggered___{}", self.status.tx_ds());
221+
std::println!("IRQ on Data Fail__________{}", self.config_reg.tx_df());
222+
std::println!(" Data Fail triggered___{}", self.status.tx_df());
223223

224224
let fifo = self.get_fifo_state(true)?;
225225
std::println!("TX FIFO___________________{}", fifo);
226226
let fifo = self.get_fifo_state(false)?;
227227
std::println!("RX FIFO___________________{}", fifo);
228228

229229
self.spi_read(1, registers::FEATURE)?;
230-
let features = self._buf[1];
230+
let features = self.buf[1];
231231
std::println!("Ask no ACK allowed________{}", features & 1 > 0);
232232
std::println!("ACK Payload enabled_______{}", features & 2 > 0);
233233

234234
self.spi_read(1, registers::DYNPD)?;
235-
std::println!("Dynamic Payloads__________{:#010b}", self._buf[1]);
235+
std::println!("Dynamic Payloads__________{:#010b}", self.buf[1]);
236236

237237
self.spi_read(1, registers::EN_AA)?;
238-
std::println!("Auto Acknowledgment_______{:#010b}", self._buf[1]);
238+
std::println!("Auto Acknowledgment_______{:#010b}", self.buf[1]);
239239

240240
std::println!(
241241
"Primary Mode______________{}X",
242-
if self._config_reg.is_rx() { "R" } else { "T" }
242+
if self.config_reg.is_rx() { "R" } else { "T" }
243243
);
244244
std::println!("Powered Up________________{}", self.is_powered());
245245

246246
// print pipe addresses
247247
self.spi_read(5, registers::TX_ADDR)?;
248248
let mut address = [0u8; 4];
249-
address.copy_from_slice(&self._buf[2..6]);
249+
address.copy_from_slice(&self.buf[2..6]);
250250
std::println!(
251251
"TX address_______________{:#08X}{:02X}",
252252
u32::from_le_bytes(address),
253-
self._buf[1]
253+
self.buf[1]
254254
);
255255
self.spi_read(1, registers::EN_RXADDR)?;
256-
let open_pipes = self._buf[1];
256+
let open_pipes = self.buf[1];
257257
for pipe in 0..=5 {
258258
self.spi_read(if pipe < 2 { 5 } else { 1 }, registers::RX_ADDR_P0 + pipe)?;
259259
if pipe < 2 {
260-
address.copy_from_slice(&self._buf[2..6]);
260+
address.copy_from_slice(&self.buf[2..6]);
261261
}
262262
std::println!(
263263
"Pipe {pipe} ({}) bound to {:#08X}{:02X}",
@@ -268,7 +268,7 @@ where
268268
},
269269
// reverse the bytes read to represent how memory is stored
270270
u32::from_le_bytes(address),
271-
self._buf[1],
271+
self.buf[1],
272272
);
273273
}
274274
Ok(())

0 commit comments

Comments
 (0)