Mercurial > templog
comparison rust/src/config.rs @ 595:e87655ed8429 rust
add config
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 05 Jan 2017 23:26:00 +0800 |
parents | |
children | ca8102feaca6 |
comparison
equal
deleted
inserted
replaced
594:aff50ee77252 | 595:e87655ed8429 |
---|---|
1 extern crate toml; | |
2 | |
3 use toml::{Encoder,Decoder}; | |
4 use serde::Serializer; | |
5 use serde::Serialize; | |
6 | |
7 #[derive(Deserialize,Serialize,Debug)] | |
8 #[allow(non_snake_case)] | |
9 pub struct Config { | |
10 FRIDGE_SLEEP: u32, | |
11 SENSOR_SLEEP: u32, | |
12 UPLOAD_SLEEP: u32, | |
13 | |
14 FRIDGE_DELAY: u32, | |
15 FRIDGE_WORT_INVALID_TIME: u32, | |
16 | |
17 MAX_READINGS: u32, | |
18 | |
19 PARAMS_FILE: String, | |
20 | |
21 SENSOR_BASE_DIR: String, | |
22 FRIDGE_GPIO_PIN: u32, | |
23 | |
24 AMBIENT_NAME: String, | |
25 FRIDGE_NAME: String, | |
26 WORT_NAME: String, | |
27 INTERNAL_TEMPERATURE: String, | |
28 | |
29 HMAC_KEY: String, | |
30 SERVER_URL: String, | |
31 UPDATE_URL: String, | |
32 SETTINGS_URL: String, | |
33 } | |
34 | |
35 impl Config { | |
36 | |
37 pub fn new() -> Self { | |
38 Config { | |
39 FRIDGE_SLEEP: 60, // this value works. may affect the algorithm | |
40 SENSOR_SLEEP: 15, // same for this. | |
41 UPLOAD_SLEEP: 83, // nice and prime | |
42 | |
43 FRIDGE_DELAY: 600, // 10 mins, to avoid fridge damage from frequent cycling off/on | |
44 FRIDGE_WORT_INVALID_TIME: 300, // 5 mins | |
45 | |
46 // 12 hours of "offline" readings stored | |
47 MAX_READINGS: 12*60*60 / 15, // 15 is SENSOR_SLEEP | |
48 | |
49 //PARAMS_FILE: os.path.join(os.path.dirname(__file__), "tempserver.conf") | |
50 PARAMS_FILE: "tempserver.conf".to_string(), | |
51 | |
52 SENSOR_BASE_DIR: "/sys/devices/w1_bus_master2".to_string(), | |
53 FRIDGE_GPIO_PIN: 17, | |
54 //WORT_NAME: "28-0000042cf4dd".to_string(), | |
55 //FRIDGE_NAME: "28-0000042cccc4".to_string(), | |
56 //AMBIENT_NAME: "28-0000042c6dbb".to_string(), | |
57 AMBIENT_NAME: "missingambient".to_string(), | |
58 FRIDGE_NAME: "28-0000042c6dbb".to_string(), | |
59 WORT_NAME: "28-0000042cccc4".to_string(), // was fridge | |
60 INTERNAL_TEMPERATURE: "/sys/class/thermal/thermal_zone0/temp".to_string(), | |
61 | |
62 HMAC_KEY: "a key".to_string(), | |
63 SERVER_URL: "https://evil.ucc.asn.au/~matt/templog".to_string(), | |
64 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(), | |
66 } | |
67 } | |
68 | |
69 pub fn to_toml_string(self) -> String { | |
70 let mut e = toml::Encoder::new(); | |
71 self.serialize(&mut e).unwrap(); | |
72 toml::Value::Table(e.toml).to_string() | |
73 } | |
74 } |