From 9ac2ea4c4f9106e7dc6c60766d5f9510837a57a8 Mon Sep 17 00:00:00 2001 From: Bastian Bloessl Date: Sun, 27 Oct 2024 23:08:21 +0100 Subject: [PATCH] clippy and deps --- Cargo.toml | 8 ++++---- examples/rtl_test.rs | 12 ++++++------ examples/simple_fm.rs | 13 ++++++------- src/rtlsdr.rs | 16 +++++----------- src/tuners/r820t.rs | 4 +++- 5 files changed, 24 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2e91b78..1cc59ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,14 +16,14 @@ rtl_sdr_blog = [] [dependencies] byteorder = "1" log = "0.4" -mockall = "0.11" -parking_lot = "0.12.1" +mockall = "0.13" +parking_lot = "0.12" rusb = "0.9" thiserror = "1.0" [dev-dependencies] rusb = "0.9" byteorder = "1" -ctrlc = "3.2.3" +ctrlc = "3.4" num-complex = "0.4" -stderrlog = "0.5" +stderrlog = "0.6" diff --git a/examples/rtl_test.rs b/examples/rtl_test.rs index 85edaf9..25d5935 100644 --- a/examples/rtl_test.rs +++ b/examples/rtl_test.rs @@ -1,4 +1,4 @@ -use rtlsdr_rs::{error::Result, RtlSdr}; +use seify_rtlsdr::{error::Result, RtlSdr}; use std::sync::atomic::{AtomicBool, Ordering}; const DEFAULT_BUF_LENGTH: usize = 16 * 16384; @@ -6,13 +6,13 @@ const DEFAULT_BUF_LENGTH: usize = 16 * 16384; const SAMPLE_RATE: u32 = 2_048_000; fn main() -> Result<()> { - let devices = rtlsdr_rs::enumerate()?; + let devices = seify_rtlsdr::enumerate()?; println!("devices: {devices:?}"); // Create shutdown flag and set it when ctrl-c signal caught - static shutdown: AtomicBool = AtomicBool::new(false); - ctrlc::set_handler(|| { - shutdown.swap(true, Ordering::Relaxed); + static SHUTDOWN: AtomicBool = AtomicBool::new(false); + let _ = ctrlc::set_handler(|| { + SHUTDOWN.swap(true, Ordering::Relaxed); }); // Open device @@ -44,7 +44,7 @@ fn main() -> Result<()> { println!("Reading samples in sync mode..."); let mut buf: [u8; DEFAULT_BUF_LENGTH] = [0; DEFAULT_BUF_LENGTH]; loop { - if shutdown.load(Ordering::Relaxed) { + if SHUTDOWN.load(Ordering::Relaxed) { break; } let n = sdr.read_sync(&mut buf); diff --git a/examples/simple_fm.rs b/examples/simple_fm.rs index 38d6f72..f4e2611 100644 --- a/examples/simple_fm.rs +++ b/examples/simple_fm.rs @@ -273,8 +273,8 @@ impl Demod { /// Applies a low-pass filter on a vector of complex values fn low_pass_complex(&mut self, buf: Vec>) -> Vec> { let mut res = vec![]; - for orig in 0..buf.len() { - self.lp_now += buf[orig]; + for orig in buf { + self.lp_now += orig; self.prev_index += 1; if self.prev_index < self.config.downsample as usize { @@ -329,12 +329,11 @@ impl Demod { if yabs < 0 { yabs = -yabs; } - let angle; - if x >= 0 { - angle = pi4 - (pi4 as i64 * (x - yabs) as i64) as i32 / (x + yabs); + let angle = if x >= 0 { + pi4 - (pi4 as i64 * (x - yabs) as i64) as i32 / (x + yabs) } else { - angle = pi34 - (pi4 as i64 * (x + yabs) as i64) as i32 / (yabs - x); - } + pi34 - (pi4 as i64 * (x + yabs) as i64) as i32 / (yabs - x) + }; if y < 0 { return -angle; } diff --git a/src/rtlsdr.rs b/src/rtlsdr.rs index 6e6c5d2..8ecf7ab 100644 --- a/src/rtlsdr.rs +++ b/src/rtlsdr.rs @@ -114,17 +114,10 @@ impl RtlSdr { // Hack to force the Bias T to always be on if we set the IR-Endpoint bit in the EEPROM to 0. Default on EEPROM is 1. let buf: [u8; EEPROM_SIZE] = [0; EEPROM_SIZE]; self.handle.read_eeprom(&buf, 0, EEPROM_SIZE)?; - if buf[7] & 0x02 != 0 { - inner.deref().borrow_mut().force_bt = false; - } else { - inner.deref().borrow_mut().force_bt = true; - } + + inner.deref().borrow_mut().force_bt = buf[7] & 0x02 == 0; // Hack to force direct sampling mode to always be on if we set the remote-enabled bit in the EEPROM to 1. Default on EEPROM is 0. - if buf[7] & 0x01 != 0 { - inner.deref().borrow_mut().force_ds = true; - } else { - inner.deref().borrow_mut().force_ds = false; - } + inner.deref().borrow_mut().force_ds = buf[7] & 0x01 != 0; // TODO: if(force_ds){tuner_type = TUNER_UNKNOWN} info!("Init tuner"); inner.deref().borrow_mut().tuner.init(&self.handle)?; @@ -400,7 +393,8 @@ impl RtlSdr { Ok(()) } - pub fn set_offset_tuning(&self, _enable: bool) -> Result<()> { + #[allow(unused_variables)] + pub fn set_offset_tuning(&self, enable: bool) -> Result<()> { // RTL-SDR-BLOG Hack, enables us to turn on the bias tee by clicking on "offset tuning" // in software that doesn't have specified bias tee support. // Offset tuning is not used for R820T devices so it is no problem. diff --git a/src/tuners/r820t.rs b/src/tuners/r820t.rs index 022a157..3020217 100644 --- a/src/tuners/r820t.rs +++ b/src/tuners/r820t.rs @@ -682,6 +682,7 @@ impl R820T { Ok(()) } + #[allow(unused_variables, unused_assignments)] fn sysfreq_sel( &mut self, handle: &Device, @@ -692,7 +693,8 @@ impl R820T { let mixer_top; let lna_top; let cp_cur; - let div_buf_cur; + #[allow(unused_mut)] + let mut div_buf_cur; let lna_vth_l; let mixer_vth_l; let air_cable1_in;