Mercurial > templog
comparison rust/src/fridge.rs @ 601:8c21df3711e2 rust
rigid_config
more on sensors
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 15 Feb 2017 23:58:02 +0800 |
parents | a440eafa84a9 |
children | b45b8b4cf0f5 |
comparison
equal
deleted
inserted
replaced
600:9c76f3cf01ea | 601:8c21df3711e2 |
---|---|
8 | 8 |
9 use futures::{Future,future,Sink,Stream}; | 9 use futures::{Future,future,Sink,Stream}; |
10 use tokio_core::reactor::{Timeout,Handle}; | 10 use tokio_core::reactor::{Timeout,Handle}; |
11 use futures::sync::{mpsc}; | 11 use futures::sync::{mpsc}; |
12 | 12 |
13 use config::Config; | |
14 use types::*; | 13 use types::*; |
14 | |
15 use ::rigid_config; | |
15 | 16 |
16 #[derive(Debug)] | 17 #[derive(Debug)] |
17 pub enum Message { | 18 pub enum Message { |
18 Sensor {wort: Option<f32>, fridge: Option<f32>}, | 19 Sensor {wort: Option<f32>, fridge: Option<f32>}, |
19 Params (Params), | 20 Params (Params), |
20 Tick(u64), | 21 Tick(u64), |
21 } | 22 } |
22 | 23 |
23 pub struct Fridge { | 24 pub struct Fridge { |
24 config: Config, | |
25 params: Params, | 25 params: Params, |
26 temp_wort: Option<f32>, | 26 temp_wort: Option<f32>, |
27 temp_fridge: Option<f32>, | 27 temp_fridge: Option<f32>, |
28 | 28 |
29 // Timeouts to wake ourselves up again | 29 // Timeouts to wake ourselves up again |
49 Ok(futures::Async::Ready(())) | 49 Ok(futures::Async::Ready(())) |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 impl Fridge { | 53 impl Fridge { |
54 pub fn new(config: &Config, nowait: bool, p: Params, handle: &Handle) -> Fridge { | 54 pub fn new(nowait: bool, p: Params, handle: &Handle) -> Fridge { |
55 let (s, r) = mpsc::channel(1); | 55 let (s, r) = mpsc::channel(1); |
56 let mut f = Fridge { | 56 let mut f = Fridge { |
57 config: config.clone(), | |
58 params: p, | 57 params: p, |
59 temp_wort: None, | 58 temp_wort: None, |
60 temp_fridge: None, | 59 temp_fridge: None, |
61 | 60 |
62 handle: handle.clone(), | 61 handle: handle.clone(), |
64 timeout_r: Some(r), | 63 timeout_r: Some(r), |
65 ticker: 0, | 64 ticker: 0, |
66 last_off_time: Instant::now(), | 65 last_off_time: Instant::now(), |
67 }; | 66 }; |
68 if nowait { | 67 if nowait { |
69 f.last_off_time -= Duration::new(config.FRIDGE_DELAY, 100); | 68 f.last_off_time -= Duration::new(rigid_config.FRIDGE_DELAY, 100); |
70 } | 69 } |
71 f.tick(); | 70 f.tick(); |
72 f | 71 f |
73 } | 72 } |
74 | 73 |