comparison rust/src/fridge.rs @ 603:b45b8b4cf0f5 rust

get rid of lazy_static, config is passed around better use of threadpool for sensors readings are no longer options
author Matt Johnston <matt@ucc.asn.au>
date Thu, 16 Feb 2017 23:19:12 +0800
parents 8c21df3711e2
children 3c1d37d78415
comparison
equal deleted inserted replaced
602:613f114feb4b 603:b45b8b4cf0f5
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;
13 use types::*; 14 use types::*;
14
15 use ::rigid_config;
16 15
17 #[derive(Debug)] 16 #[derive(Debug)]
18 pub enum Message { 17 pub enum Message {
19 Sensor {wort: Option<f32>, fridge: Option<f32>}, 18 Sensor {wort: Option<f32>, fridge: Option<f32>},
20 Params (Params), 19 Params (Params),
21 Tick(u64), 20 Tick(u64),
22 } 21 }
23 22
24 pub struct Fridge { 23 pub struct Fridge {
25 params: Params, 24 params: Params,
25 config: Config,
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
30 handle: Handle, 30 handle: Handle,
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(nowait: bool, p: Params, handle: &Handle) -> Fridge { 54 pub fn new(config: &Config, 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(),
57 params: p, 58 params: p,
58 temp_wort: None, 59 temp_wort: None,
59 temp_fridge: None, 60 temp_fridge: None,
60 61
61 handle: handle.clone(), 62 handle: handle.clone(),
63 timeout_r: Some(r), 64 timeout_r: Some(r),
64 ticker: 0, 65 ticker: 0,
65 last_off_time: Instant::now(), 66 last_off_time: Instant::now(),
66 }; 67 };
67 if nowait { 68 if nowait {
68 f.last_off_time -= Duration::new(rigid_config.FRIDGE_DELAY, 100); 69 f.last_off_time -= Duration::new(config.FRIDGE_DELAY, 100);
69 } 70 }
70 f.tick(); 71 f.tick();
71 f 72 f
72 } 73 }
73 74