Mercurial > templog
annotate rust/src/types.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 | ca8102feaca6 |
children | 278f1002b5c7 |
rev | line source |
---|---|
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
1 use std::collections::HashMap; |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
2 use std::time::Duration; |
595 | 3 use serde::{Deserialize,Serialize}; |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
4 |
596
ca8102feaca6
sensor takes config parameter
Matt Johnston <matt@ucc.asn.au>
parents:
595
diff
changeset
|
5 #[derive(Deserialize, Serialize, Debug)] |
592 | 6 pub struct Params { |
7 pub fridge_setpoint: f32, | |
8 pub fridge_difference: f32, | |
9 pub overshoot_delay: u32, | |
10 pub overshoot_factor: f32, | |
11 pub disabled: bool, | |
12 pub nowort: bool, | |
13 pub fridge_range_lower: f32, | |
14 pub fridge_range_upper: f32, | |
15 } | |
16 | |
17 impl Params { | |
18 pub fn defaults() -> Params { | |
19 Params { | |
20 fridge_setpoint: 16.0, | |
21 fridge_difference: 0.2, | |
22 overshoot_delay: 720, // 12 minutes | |
23 overshoot_factor: 1.0, | |
24 disabled: false, | |
25 nowort: false, | |
26 fridge_range_lower: 3.0, | |
27 fridge_range_upper: 3.0, | |
28 } | |
29 } | |
30 } | |
31 | |
32 #[derive(Debug)] | |
33 pub struct ParamHolder { | |
34 pub p: Params, | |
35 epoch: String, // XXX or a byte array? | |
36 } | |
37 | |
38 impl ParamHolder { | |
39 pub fn new() -> ParamHolder { | |
40 ParamHolder { | |
41 p: Params::defaults(), | |
42 epoch: String::new(), | |
43 } | |
44 } | |
45 } | |
46 | |
47 #[derive(Debug)] | |
48 pub struct Readings { | |
603
b45b8b4cf0f5
get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents:
596
diff
changeset
|
49 pub temps: HashMap<String, f32>, |
592 | 50 } |
51 | |
52 impl Readings { | |
53 pub fn new() -> Readings { | |
54 Readings { | |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
55 temps: HashMap::new(), |
592 | 56 } |
57 } | |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
58 |
603
b45b8b4cf0f5
get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents:
596
diff
changeset
|
59 pub fn add(&mut self, name: &str, v: f32) { |
b45b8b4cf0f5
get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents:
596
diff
changeset
|
60 self.temps.insert(name.to_string(), v); |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
61 } |
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
62 |
603
b45b8b4cf0f5
get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents:
596
diff
changeset
|
63 pub fn get_temp(&self, name: &str) -> Option<f32> { |
b45b8b4cf0f5
get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents:
596
diff
changeset
|
64 self.temps.get(name).map(|f| *f) |
592 | 65 } |
66 } | |
67 |