diff rust/src/fridge.rs @ 597:a440eafa84a9 rust

progress for debug
author Matt Johnston <matt@ucc.asn.au>
date Sat, 07 Jan 2017 00:56:39 +0800
parents e87655ed8429
children 8c21df3711e2
line wrap: on
line diff
--- a/rust/src/fridge.rs	Fri Jan 06 22:04:10 2017 +0800
+++ b/rust/src/fridge.rs	Sat Jan 07 00:56:39 2017 +0800
@@ -4,12 +4,13 @@
 use std;
 use std::io;
 use std::mem;
-use std::time::Duration;
+use std::time::{Duration,Instant};
 
 use futures::{Future,future,Sink,Stream};
 use tokio_core::reactor::{Timeout,Handle};
 use futures::sync::{mpsc};
 
+use config::Config;
 use types::*;
 
 #[derive(Debug)]
@@ -20,6 +21,7 @@
 }
 
 pub struct Fridge {
+    config: Config,
     params: Params,
     temp_wort: Option<f32>,
     temp_fridge: Option<f32>,
@@ -29,6 +31,7 @@
     timeout_s: mpsc::Sender<u64>,
     timeout_r: Option<mpsc::Receiver<u64>>,
     ticker: u64,
+    last_off_time: Instant,
 }
 
 impl Sink for Fridge {
@@ -48,9 +51,10 @@
 }
 
 impl Fridge {
-    pub fn new(p: Params, handle: &Handle) -> Fridge {
+    pub fn new(config: &Config, nowait: bool, p: Params, handle: &Handle) -> Fridge {
         let (s, r) = mpsc::channel(1);
         let mut f = Fridge { 
+            config: config.clone(),
             params: p,
             temp_wort: None,
             temp_fridge: None,
@@ -59,13 +63,23 @@
             timeout_s: s,
             timeout_r: Some(r),
             ticker: 0,
+            last_off_time: Instant::now(),
         };
+        if nowait {
+            f.last_off_time -= Duration::new(config.FRIDGE_DELAY, 100);
+        }
         f.tick();
         f
     }
 
-    /// Returns a stream of timeouts for fridge, waking when next necessary
-    pub fn timeouts(&mut self)
+    /// The fridge needs to periodically wake itself up, the returned
+    // stream of Tick messages does so.
+    /// Examples of wakeups events are
+    /// 
+    ///  * overshoot calculation
+    ///  * minimum fridge-off time
+    ///  * invalid wort timeout
+    pub fn wakeups(&mut self)
             -> Box<Stream<Item=Message, Error=io::Error>> {
         mem::replace(&mut self.timeout_r, None)
             .expect("NumberWatcher::timeouts() can only be called once")