annotate rust/src/types.rs @ 593:bf138339d20a rust

fiddling with timeouts and closures
author Matt Johnston <matt@ucc.asn.au>
date Tue, 27 Dec 2016 00:51:28 +0800
parents 03b48ec0bb03
children aff50ee77252
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
593
bf138339d20a fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents: 592
diff changeset
1 #[derive(RustcDecodable, RustcEncodable, Debug, Clone)]
592
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 pub struct Params {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 pub fridge_setpoint: f32,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 pub fridge_difference: f32,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 pub overshoot_delay: u32,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 pub overshoot_factor: f32,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 pub disabled: bool,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 pub nowort: bool,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 pub fridge_range_lower: f32,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 pub fridge_range_upper: f32,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 impl Params {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 pub fn defaults() -> Params {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 Params {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 fridge_setpoint: 16.0,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 fridge_difference: 0.2,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 overshoot_delay: 720, // 12 minutes
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 overshoot_factor: 1.0,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 disabled: false,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 nowort: false,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 fridge_range_lower: 3.0,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 fridge_range_upper: 3.0,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 #[derive(Debug)]
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 pub struct ParamHolder {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 pub p: Params,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 epoch: String, // XXX or a byte array?
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 impl ParamHolder {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 pub fn new() -> ParamHolder {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 ParamHolder {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 p: Params::defaults(),
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 epoch: String::new(),
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 #[derive(Debug)]
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 pub struct Reading {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 name: String,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 value: Option<f32>,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 impl Reading {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 pub fn new(name: String, value: f32) -> Reading {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 Reading { name: name, value: Some(value) }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53 pub fn new_none(name: String) -> Reading {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 Reading { name: name, value: None }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57
593
bf138339d20a fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents: 592
diff changeset
58 #[derive(Debug)]
592
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 pub struct Readings {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 temps: Vec<Vec<Reading>>,
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 impl Readings {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 pub fn new() -> Readings {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 Readings {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 temps: Vec::new(),
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 }
593
bf138339d20a fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents: 592
diff changeset
69
bf138339d20a fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents: 592
diff changeset
70 pub fn push(&mut self, vals: Vec<Reading>) {
bf138339d20a fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents: 592
diff changeset
71 self.temps.push(vals);
bf138339d20a fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents: 592
diff changeset
72 }
bf138339d20a fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents: 592
diff changeset
73
592
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 pub fn fridge(&self) -> Option<f32> {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 unimplemented!();
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 pub fn wort(&self) -> Option<f32> {
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 unimplemented!();
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 }
03b48ec0bb03 fridge, types, configwaiter
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82