Mercurial > templog
annotate 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 |
rev | line source |
---|---|
588
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
1 extern crate tokio_core; |
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
2 extern crate futures; |
591 | 3 extern crate rustc_serialize; |
588
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
4 |
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
5 use tokio_core::reactor::Core; |
591 | 6 use futures::{Future,Stream}; |
7 use rustc_serialize::json; | |
589
f2508125adf1
Try using traits for periodic stream
Matt Johnston <matt@ucc.asn.au>
parents:
588
diff
changeset
|
8 |
590 | 9 mod sensor; |
587 | 10 |
591 | 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 } | |
64 | |
587 | 65 fn main() { |
66 println!("Wort Templog"); | |
588
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
67 |
591 | 68 let param = ParamHolder::new(); |
69 let mut readings = Readings::new(); | |
70 | |
588
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
71 let mut core = Core::new().unwrap(); |
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
72 let handle = core.handle(); |
587 | 73 |
591 | 74 let s = sensor::Sensor::run(&handle, 400, "sens1".to_string()); |
75 let t = sensor::Sensor::run(&handle, 747, "frid".to_string()); | |
587 | 76 |
588
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
77 let h = s.for_each(|r| { |
590 | 78 println!("readings {:?}", r); |
588
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
79 Ok(()) |
038734052b20
fiddling with futures-rs instead
Matt Johnston <matt@ucc.asn.au>
parents:
587
diff
changeset
|
80 }); |
587 | 81 |
591 | 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); | |
587 | 90 } |
91 |