From 47934e3c7ca64bfb82fbcede47491084a9e9f266 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Sun, 25 Apr 2021 09:28:58 +0300 Subject: Restore dynamic trait polymorphism with handles in functions --- src/usb.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/usb.rs') diff --git a/src/usb.rs b/src/usb.rs index 6b7577c..7924ad3 100644 --- a/src/usb.rs +++ b/src/usb.rs @@ -40,7 +40,7 @@ const CTRL_TIMEOUT: Duration = Duration::from_millis(300); pub struct RtlSdrDeviceHandle { handle: DeviceHandle, - // tuner: Option, // when we go abstract: Option>, + tuner: Option>, iface_id: u8, kernel_driver_active: bool, } @@ -51,7 +51,7 @@ impl RtlSdrDeviceHandle { pub fn new(handle: DeviceHandle, iface_id: u8) -> RtlSdrDeviceHandle { let mut handle = RtlSdrDeviceHandle { handle, - // tuner: None, + tuner: None, iface_id, kernel_driver_active: false, }; @@ -60,7 +60,7 @@ impl RtlSdrDeviceHandle { handle } - pub fn init_tuner(self) { + pub fn init_tuner(&mut self) { let tuner_id: &str = match self.search_tuner() { Some(tid) => { trace!("Found tuner ID {}", tid); @@ -69,16 +69,16 @@ impl RtlSdrDeviceHandle { None => "", }; - let tuner: Option = match tuner_id { - r820t::TUNER_ID => Some(r820t::R820T::new(self)), - // fc0013::TUNER_ID => Some(Box::new(fc0013::FC0013::new(&self))), + let tuner: Option> = match tuner_id { + r820t::TUNER_ID => Some(Box::new(r820t::R820T::new(&self))), + fc0013::TUNER_ID => Some(Box::new(fc0013::FC0013::new(&self))), _ => { error!("Could not find any valid tuner."); None } }; - // self.tuner = tuner; + self.tuner = tuner; info!("Found tuner r820t"); } @@ -226,12 +226,13 @@ impl RtlSdrDeviceHandle { } pub fn i2c_write(&self, i2c_addr: u8, buf: &[u8]) { - self.write_array(BLOCK_IICB, i2c_addr as u16, buf); + self.write_array(BLOCK_IICB, i2c_addr as u16, buf).unwrap(); } pub fn i2c_write_reg(&self, i2c_addr: u8, reg: u8, val: u8) { let data: [u8; 2] = [reg, val]; - self.write_array(BLOCK_IICB, i2c_addr as u16, &data); + self.write_array(BLOCK_IICB, i2c_addr as u16, &data) + .unwrap(); } pub fn set_i2c_repeater(&self, on: bool) { -- cgit v1.3.1