diff rust/src/main.rs @ 592:03b48ec0bb03 rust

fridge, types, configwaiter
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Dec 2016 00:14:58 +0800
parents 4a944663fa8d
children bf138339d20a
line wrap: on
line diff
--- a/rust/src/main.rs	Fri Dec 23 00:33:19 2016 +0800
+++ b/rust/src/main.rs	Sat Dec 24 00:14:58 2016 +0800
@@ -7,74 +7,28 @@
 use rustc_serialize::json;
 
 mod sensor;
-
-#[derive(RustcDecodable, RustcEncodable)]
-struct Params {
-    fridge_setpoint: f32,
-    fridge_difference: f32,
-    overshoot_delay: u32,
-    overshoot_factor: f32,
-    disabled: bool,
-    nowort: bool,
-    fridge_range_lower: f32,
-    fridge_range_upper: f32,
-}
-
-struct ParamHolder {
-    p: Params,
-    epoch: String, // XXX or a byte array?
-}
+mod fridge;
+mod types;
+mod configwaiter;
 
-impl ParamHolder {
-    fn new() -> ParamHolder {
-        ParamHolder {
-            p: Params {
-                fridge_setpoint: 16.0,
-                fridge_difference: 0.2,
-                overshoot_delay: 720, // 12 minutes
-                overshoot_factor: 1.0,
-                disabled: false,
-                nowort: false,
-                fridge_range_lower: 3.0,
-                fridge_range_upper: 3.0,
-            },
-            epoch: String::new(),
-        }
-    }
-}
-
-struct Readings {
-    temps: Vec<Vec<sensor::Reading>>,
-}
-
-impl Readings {
-    fn new() -> Readings {
-        Readings {
-            temps: Vec::new(),
-        }
-    }
-    fn fridge() -> Option<f32> {
-        unimplemented!();
-    }
-
-    fn wort() -> Option<f32> {
-        unimplemented!();
-    }
-}
+use types::*;
 
 fn main() {
     println!("Wort Templog");
 
-    let param = ParamHolder::new();
+    let paramh = ParamHolder::new();
     let mut readings = Readings::new();
+    let mut fridge = fridge::Fridge::new(&paramh.p);
 
     let mut core = Core::new().unwrap();
     let handle = core.handle();
 
     let s = sensor::Sensor::run(&handle, 400, "sens1".to_string());
     let t = sensor::Sensor::run(&handle, 747, "frid".to_string());
+    let w = configwaiter::ConfigWaiter::run(&handle, 3000);
 
     let h = s.for_each(|r| {
+        fridge.set_params(&paramh.p);
         println!("readings {:?}", r);
         Ok(())
     });
@@ -84,7 +38,13 @@
         Ok(())
     });
 
-    let all = h.select(i);
+    let j = w.for_each(move |ph| {
+        let paramh = ph;
+        fridge.set_params(&ph.p);
+        Ok(())
+    });
+
+    let all = h.select(j);
 
     core.run(all);
 }