comparison rust/src/config.rs @ 596:ca8102feaca6 rust

sensor takes config parameter
author Matt Johnston <matt@ucc.asn.au>
date Fri, 06 Jan 2017 22:04:10 +0800
parents e87655ed8429
children a440eafa84a9
comparison
equal deleted inserted replaced
595:e87655ed8429 596:ca8102feaca6
1 extern crate toml; 1 extern crate toml;
2 2
3 use toml::{Encoder,Decoder};
4 use serde::Serializer;
5 use serde::Serialize; 3 use serde::Serialize;
6 4
7 #[derive(Deserialize,Serialize,Debug)] 5 #[derive(Deserialize,Serialize,Debug,Clone)]
8 #[allow(non_snake_case)] 6 #[allow(non_snake_case)]
9 pub struct Config { 7 pub struct Config {
10 FRIDGE_SLEEP: u32, 8 pub FRIDGE_SLEEP: u64,
11 SENSOR_SLEEP: u32, 9 pub SENSOR_SLEEP: u64,
12 UPLOAD_SLEEP: u32, 10 pub UPLOAD_SLEEP: u64,
13 11
14 FRIDGE_DELAY: u32, 12 pub FRIDGE_DELAY: u64,
15 FRIDGE_WORT_INVALID_TIME: u32, 13 pub FRIDGE_WORT_INVALID_TIME: u64,
16 14
17 MAX_READINGS: u32, 15 pub MAX_READINGS: u32,
18 16
19 PARAMS_FILE: String, 17 pub PARAMS_FILE: String,
20 18
21 SENSOR_BASE_DIR: String, 19 pub SENSOR_BASE_DIR: String,
22 FRIDGE_GPIO_PIN: u32, 20 pub FRIDGE_GPIO_PIN: u32,
23 21
24 AMBIENT_NAME: String, 22 pub AMBIENT_NAME: String,
25 FRIDGE_NAME: String, 23 pub FRIDGE_NAME: String,
26 WORT_NAME: String, 24 pub WORT_NAME: String,
27 INTERNAL_TEMPERATURE: String, 25 pub INTERNAL_TEMPERATURE: String,
28 26
29 HMAC_KEY: String, 27 pub HMAC_KEY: String,
30 SERVER_URL: String, 28 pub SERVER_URL: String,
31 UPDATE_URL: String, 29 pub UPDATE_URL: String,
32 SETTINGS_URL: String, 30 pub SETTINGS_URL: String,
33 } 31 }
34 32
35 impl Config { 33 impl Config {
36 34
37 pub fn new() -> Self { 35 pub fn new() -> Self {
38 Config { 36 Config {
39 FRIDGE_SLEEP: 60, // this value works. may affect the algorithm 37 SENSOR_SLEEP: 5,
40 SENSOR_SLEEP: 15, // same for this. 38 UPLOAD_SLEEP: 83,
41 UPLOAD_SLEEP: 83, // nice and prime
42 39
43 FRIDGE_DELAY: 600, // 10 mins, to avoid fridge damage from frequent cycling off/on 40 FRIDGE_DELAY: 600, // 10 mins, to avoid fridge damage from frequent cycling off/on
44 FRIDGE_WORT_INVALID_TIME: 300, // 5 mins 41 FRIDGE_WORT_INVALID_TIME: 300, // 5 mins
45 42
46 // 12 hours of "offline" readings stored 43 // 12 hours of "offline" readings stored
64 UPDATE_URL: "https://evil.ucc.asn.au/~matt/templog/update".to_string(), 61 UPDATE_URL: "https://evil.ucc.asn.au/~matt/templog/update".to_string(),
65 SETTINGS_URL: "https://evil.ucc.asn.au/~matt/templog/get_settings".to_string(), 62 SETTINGS_URL: "https://evil.ucc.asn.au/~matt/templog/get_settings".to_string(),
66 } 63 }
67 } 64 }
68 65
69 pub fn to_toml_string(self) -> String { 66 pub fn to_toml_string(&self) -> String {
70 let mut e = toml::Encoder::new(); 67 let mut e = toml::Encoder::new();
71 self.serialize(&mut e).unwrap(); 68 self.serialize(&mut e).unwrap();
72 toml::Value::Table(e.toml).to_string() 69 toml::Value::Table(e.toml).to_string()
73 } 70 }
74 } 71 }