Mercurial > templog
comparison 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 |
comparison
equal
deleted
inserted
replaced
591:4a944663fa8d | 592:03b48ec0bb03 |
---|---|
5 use tokio_core::reactor::Core; | 5 use tokio_core::reactor::Core; |
6 use futures::{Future,Stream}; | 6 use futures::{Future,Stream}; |
7 use rustc_serialize::json; | 7 use rustc_serialize::json; |
8 | 8 |
9 mod sensor; | 9 mod sensor; |
10 mod fridge; | |
11 mod types; | |
12 mod configwaiter; | |
10 | 13 |
11 #[derive(RustcDecodable, RustcEncodable)] | 14 use types::*; |
12 struct Params { | |
13 fridge_setpoint: f32, | |
14 fridge_difference: f32, | |
15 overshoot_delay: u32, | |
16 overshoot_factor: f32, | |
17 disabled: bool, | |
18 nowort: bool, | |
19 fridge_range_lower: f32, | |
20 fridge_range_upper: f32, | |
21 } | |
22 | |
23 struct ParamHolder { | |
24 p: Params, | |
25 epoch: String, // XXX or a byte array? | |
26 } | |
27 | |
28 impl ParamHolder { | |
29 fn new() -> ParamHolder { | |
30 ParamHolder { | |
31 p: Params { | |
32 fridge_setpoint: 16.0, | |
33 fridge_difference: 0.2, | |
34 overshoot_delay: 720, // 12 minutes | |
35 overshoot_factor: 1.0, | |
36 disabled: false, | |
37 nowort: false, | |
38 fridge_range_lower: 3.0, | |
39 fridge_range_upper: 3.0, | |
40 }, | |
41 epoch: String::new(), | |
42 } | |
43 } | |
44 } | |
45 | |
46 struct Readings { | |
47 temps: Vec<Vec<sensor::Reading>>, | |
48 } | |
49 | |
50 impl Readings { | |
51 fn new() -> Readings { | |
52 Readings { | |
53 temps: Vec::new(), | |
54 } | |
55 } | |
56 fn fridge() -> Option<f32> { | |
57 unimplemented!(); | |
58 } | |
59 | |
60 fn wort() -> Option<f32> { | |
61 unimplemented!(); | |
62 } | |
63 } | |
64 | 15 |
65 fn main() { | 16 fn main() { |
66 println!("Wort Templog"); | 17 println!("Wort Templog"); |
67 | 18 |
68 let param = ParamHolder::new(); | 19 let paramh = ParamHolder::new(); |
69 let mut readings = Readings::new(); | 20 let mut readings = Readings::new(); |
21 let mut fridge = fridge::Fridge::new(¶mh.p); | |
70 | 22 |
71 let mut core = Core::new().unwrap(); | 23 let mut core = Core::new().unwrap(); |
72 let handle = core.handle(); | 24 let handle = core.handle(); |
73 | 25 |
74 let s = sensor::Sensor::run(&handle, 400, "sens1".to_string()); | 26 let s = sensor::Sensor::run(&handle, 400, "sens1".to_string()); |
75 let t = sensor::Sensor::run(&handle, 747, "frid".to_string()); | 27 let t = sensor::Sensor::run(&handle, 747, "frid".to_string()); |
28 let w = configwaiter::ConfigWaiter::run(&handle, 3000); | |
76 | 29 |
77 let h = s.for_each(|r| { | 30 let h = s.for_each(|r| { |
31 fridge.set_params(¶mh.p); | |
78 println!("readings {:?}", r); | 32 println!("readings {:?}", r); |
79 Ok(()) | 33 Ok(()) |
80 }); | 34 }); |
81 | 35 |
82 let i = t.for_each(|r| { | 36 let i = t.for_each(|r| { |
83 println!("fridgereadings {:?}", r); | 37 println!("fridgereadings {:?}", r); |
84 Ok(()) | 38 Ok(()) |
85 }); | 39 }); |
86 | 40 |
87 let all = h.select(i); | 41 let j = w.for_each(move |ph| { |
42 let paramh = ph; | |
43 fridge.set_params(&ph.p); | |
44 Ok(()) | |
45 }); | |
46 | |
47 let all = h.select(j); | |
88 | 48 |
89 core.run(all); | 49 core.run(all); |
90 } | 50 } |
91 | 51 |