Mercurial > templog
view rust/src/types.rs @ 594:aff50ee77252 rust
rust working better now with streams and sinks.
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 04 Jan 2017 17:18:44 +0800 |
parents | bf138339d20a |
children | e87655ed8429 |
line wrap: on
line source
use std::collections::HashMap; use std::time::Duration; #[derive(RustcDecodable, RustcEncodable, Debug, Clone)] pub struct Params { pub fridge_setpoint: f32, pub fridge_difference: f32, pub overshoot_delay: u32, pub overshoot_factor: f32, pub disabled: bool, pub nowort: bool, pub fridge_range_lower: f32, pub fridge_range_upper: f32, } impl Params { pub fn defaults() -> Params { Params { fridge_setpoint: 16.0, fridge_difference: 0.2, overshoot_delay: 720, // 12 minutes overshoot_factor: 1.0, disabled: false, nowort: false, fridge_range_lower: 3.0, fridge_range_upper: 3.0, } } } #[derive(Debug)] pub struct ParamHolder { pub p: Params, epoch: String, // XXX or a byte array? } impl ParamHolder { pub fn new() -> ParamHolder { ParamHolder { p: Params::defaults(), epoch: String::new(), } } } #[derive(Debug)] pub struct Readings { temps: HashMap<String, Option<f32>>, } impl Readings { pub fn new() -> Readings { Readings { temps: HashMap::new(), } } pub fn add(&mut self, name: &str, v: Option<f32>) { if let Some(prev) = self.temps.insert(name.to_string(), v) { warn!("Replaced existing reading '{}' {:?} -> {:?}", name, prev, v); } } pub fn fridge(&self) -> Option<f32> { if let Some(t) = self.temps.get("fridge") { t.clone() } else { warn!("No fridge reading was added"); None } } pub fn wort(&self) -> Option<f32> { if let Some(t) = self.temps.get("wort") { t.clone() } else { warn!("No wort reading was added"); None } } }