Mercurial > templog
comparison rust/src/main.rs @ 591:4a944663fa8d rust
more skeleton
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 23 Dec 2016 00:33:19 +0800 |
parents | dccd8504aa38 |
children | 03b48ec0bb03 |
comparison
equal
deleted
inserted
replaced
590:dccd8504aa38 | 591:4a944663fa8d |
---|---|
1 extern crate tokio_core; | 1 extern crate tokio_core; |
2 extern crate futures; | 2 extern crate futures; |
3 extern crate rustc_serialize; | |
3 | 4 |
4 use tokio_core::reactor::Core; | 5 use tokio_core::reactor::Core; |
5 use futures::Stream; | 6 use futures::{Future,Stream}; |
7 use rustc_serialize::json; | |
6 | 8 |
7 mod sensor; | 9 mod sensor; |
10 | |
11 #[derive(RustcDecodable, RustcEncodable)] | |
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 } | |
8 | 64 |
9 fn main() { | 65 fn main() { |
10 println!("Wort Templog"); | 66 println!("Wort Templog"); |
11 | 67 |
68 let param = ParamHolder::new(); | |
69 let mut readings = Readings::new(); | |
70 | |
12 let mut core = Core::new().unwrap(); | 71 let mut core = Core::new().unwrap(); |
13 let handle = core.handle(); | 72 let handle = core.handle(); |
14 | 73 |
15 let s = sensor::Sensor::run(&handle); | 74 let s = sensor::Sensor::run(&handle, 400, "sens1".to_string()); |
75 let t = sensor::Sensor::run(&handle, 747, "frid".to_string()); | |
16 | 76 |
17 let h = s.for_each(|r| { | 77 let h = s.for_each(|r| { |
18 println!("readings {:?}", r); | 78 println!("readings {:?}", r); |
19 Ok(()) | 79 Ok(()) |
20 }); | 80 }); |
21 | 81 |
22 core.run(h); | 82 let i = t.for_each(|r| { |
83 println!("fridgereadings {:?}", r); | |
84 Ok(()) | |
85 }); | |
86 | |
87 let all = h.select(i); | |
88 | |
89 core.run(all); | |
23 } | 90 } |
24 | 91 |