summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2018-07-29 17:27:27 +0300
committerYuval Adam <_@yuv.al>2018-07-29 17:27:27 +0300
commit59e2ae68353648364ba128ca6079157794eae1fc (patch)
treefff5326a2e567aad5a1e8bba2bc85d1d2640bb1f /src
parente3f2a44ed678bc8de6748fc0af3540f881871e1f (diff)
Refactor DeviceInfo struct and impls
Diffstat (limited to 'src')
-rw-r--r--src/devices/fc0013.rs23
-rw-r--r--src/devices/mod.rs6
-rw-r--r--src/devices/r820t.rs23
-rw-r--r--src/lib.rs6
4 files changed, 50 insertions, 8 deletions
diff --git a/src/devices/fc0013.rs b/src/devices/fc0013.rs
index 6482eee..2af58fb 100644
--- a/src/devices/fc0013.rs
+++ b/src/devices/fc0013.rs
@@ -1,8 +1,27 @@
-use super::Device;
+use super::{DeviceInfo, Actions};
-pub const FC0013: Device = Device {
+pub struct FC0013 {
+ device: DeviceInfo
+}
+
+pub const DEVICE_INFO: DeviceInfo = DeviceInfo {
+ id: "fc0013",
name: "Fitipower FC0013",
i2c_addr: 0xc6,
check_addr: 0x00,
check_val: 0xa3
};
+
+impl FC0013 {
+ fn new() -> FC0013 {
+ FC0013 {
+ device: DEVICE_INFO
+ }
+ }
+}
+
+impl Actions for FC0013 {
+ fn init(&self) {
+ println!("Init {}", self.device.name);
+ }
+}
diff --git a/src/devices/mod.rs b/src/devices/mod.rs
index 3290f72..450957d 100644
--- a/src/devices/mod.rs
+++ b/src/devices/mod.rs
@@ -1,10 +1,14 @@
pub mod fc0013;
pub mod r820t;
-pub struct Device {
+pub struct DeviceInfo {
+ pub id: &'static str,
pub name: &'static str,
pub i2c_addr: u8,
pub check_addr: u8,
pub check_val: u8
}
+pub trait Actions {
+ fn init(&self);
+}
diff --git a/src/devices/r820t.rs b/src/devices/r820t.rs
index 70fad38..ffea7a0 100644
--- a/src/devices/r820t.rs
+++ b/src/devices/r820t.rs
@@ -1,8 +1,27 @@
-use super::Device;
+use super::{DeviceInfo, Actions};
-pub const R820T: Device = Device {
+pub struct R820T {
+ device: DeviceInfo
+}
+
+pub const DEVICE_INFO: DeviceInfo = DeviceInfo {
+ id: "r820t",
name: "Rafael Micro R820T",
i2c_addr: 0x34,
check_addr: 0x00,
check_val: 0x69
};
+
+impl R820T {
+ fn new() -> R820T {
+ R820T {
+ device: DEVICE_INFO
+ }
+ }
+}
+
+impl Actions for R820T {
+ fn init(&self) {
+ println!("Init {}", self.device.name);
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index 719f481..f1537e2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -27,9 +27,9 @@ const INTERFACE_ID: u8 = 0;
use devices::*;
-const DEVICES: [Device; 2] = [
- fc0013::FC0013,
- r820t::R820T
+const DEVICES: [DeviceInfo; 2] = [
+ fc0013::DEVICE_INFO,
+ r820t::DEVICE_INFO
];
const CTRL_TIMEOUT: Duration = Duration::from_millis(300);