diff options
| author | Yuval Adam <_@yuv.al> | 2018-07-30 21:49:15 +0300 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2018-07-30 21:49:15 +0300 |
| commit | d1fe53b99a44d9ffa4f1b21b13e8a686c30ceff8 (patch) | |
| tree | 3cda76b4def8d00b8f0bca71279e5e7deb4123d0 | |
| parent | 59e2ae68353648364ba128ca6079157794eae1fc (diff) | |
Duplicate all teh codez
| -rw-r--r-- | src/devices/fc0013.rs | 8 | ||||
| -rw-r--r-- | src/devices/mod.rs | 2 | ||||
| -rw-r--r-- | src/devices/r820t.rs | 8 | ||||
| -rw-r--r-- | src/lib.rs | 36 |
4 files changed, 33 insertions, 21 deletions
diff --git a/src/devices/fc0013.rs b/src/devices/fc0013.rs index 2af58fb..028c36b 100644 --- a/src/devices/fc0013.rs +++ b/src/devices/fc0013.rs @@ -1,7 +1,7 @@ -use super::{DeviceInfo, Actions}; +use super::{DeviceInfo, Device}; pub struct FC0013 { - device: DeviceInfo + pub device: DeviceInfo } pub const DEVICE_INFO: DeviceInfo = DeviceInfo { @@ -13,14 +13,14 @@ pub const DEVICE_INFO: DeviceInfo = DeviceInfo { }; impl FC0013 { - fn new() -> FC0013 { + pub fn new() -> FC0013 { FC0013 { device: DEVICE_INFO } } } -impl Actions for FC0013 { +impl Device for FC0013 { fn init(&self) { println!("Init {}", self.device.name); } diff --git a/src/devices/mod.rs b/src/devices/mod.rs index 450957d..05dd2a3 100644 --- a/src/devices/mod.rs +++ b/src/devices/mod.rs @@ -9,6 +9,6 @@ pub struct DeviceInfo { pub check_val: u8 } -pub trait Actions { +pub trait Device { fn init(&self); } diff --git a/src/devices/r820t.rs b/src/devices/r820t.rs index ffea7a0..fec572c 100644 --- a/src/devices/r820t.rs +++ b/src/devices/r820t.rs @@ -1,7 +1,7 @@ -use super::{DeviceInfo, Actions}; +use super::{DeviceInfo, Device}; pub struct R820T { - device: DeviceInfo + pub device: DeviceInfo } pub const DEVICE_INFO: DeviceInfo = DeviceInfo { @@ -13,14 +13,14 @@ pub const DEVICE_INFO: DeviceInfo = DeviceInfo { }; impl R820T { - fn new() -> R820T { + pub fn new() -> R820T { R820T { device: DEVICE_INFO } } } -impl Actions for R820T { +impl Device for R820T { fn init(&self) { println!("Init {}", self.device.name); } @@ -4,6 +4,7 @@ mod devices; use std::time::Duration; use libusb::{Direction, RequestType, Recipient}; +use devices::*; // const BLOCK_DEMODB: u16 = 0; const BLOCK_USBB: u16 = 1; @@ -25,13 +26,6 @@ const ADDR_SYS_DEMOD_CTL_1: u16 = 0x300b; const INTERFACE_ID: u8 = 0; -use devices::*; - -const DEVICES: [DeviceInfo; 2] = [ - fc0013::DEVICE_INFO, - r820t::DEVICE_INFO -]; - const CTRL_TIMEOUT: Duration = Duration::from_millis(300); const KNOWN_DEVICES: [(u16, u16, &str); 2] = [ (0x0bda, 0x2832, "Generic RTL2832U"), @@ -222,14 +216,32 @@ impl<'a> RtlSdr<'a> { self.init_baseband(&handle); self.set_i2c_repeater(&handle, true); - for d in &DEVICES { - match self.i2c_read_reg(&handle, d.i2c_addr, d.check_addr) { + let d = r820t::R820T::new(); + let found = match self.i2c_read_reg(&handle, d.device.i2c_addr, d.device.check_addr) { + Ok(reg) => { + if reg == d.device.check_val { + println!("Found {} tuner\n", d.device.name); + true + } + else { + false + } + }, + Err(_) => false + }; + if !found { + let d = fc0013::FC0013::new(); + let _found = match self.i2c_read_reg(&handle, d.device.i2c_addr, d.device.check_addr) { Ok(reg) => { - if reg == d.check_val { - println!("Found {} tuner\n", d.name); + if reg == d.device.check_val { + println!("Found {} tuner\n", d.device.name); + true + } + else { + false } }, - Err(_) => {} + Err(_) => false }; } |
