comparison rust/src/sensor.rs @ 635:4424a8b30f9c rust

config crate wants everything to be lower case
author Matt Johnston <matt@ucc.asn.au>
date Sun, 22 Sep 2019 22:06:46 +0800
parents a5721c02d3ee
children a9f353f488d0
comparison
equal deleted inserted replaced
634:a5721c02d3ee 635:4424a8b30f9c
35 self.chan.as_ref().unwrap().tell(Publish{msg: self.get_readings(), topic: "readings".into()}, None); 35 self.chan.as_ref().unwrap().tell(Publish{msg: self.get_readings(), topic: "readings".into()}, None);
36 } 36 }
37 37
38 fn pre_start(&mut self, ctx: &Context<Self::Msg>) { 38 fn pre_start(&mut self, ctx: &Context<Self::Msg>) {
39 self.chan = Some(channel("readings", &ctx.system).unwrap()); 39 self.chan = Some(channel("readings", &ctx.system).unwrap());
40 let dur = Duration::new(self.config.SENSOR_SLEEP,0); 40 let dur = Duration::new(self.config.sensor_sleep,0);
41 ctx.schedule(Duration::from_millis(0), dur, ctx.myself(), None, SendReading); 41 ctx.schedule(Duration::from_millis(0), dur, ctx.myself(), None, SendReading);
42 } 42 }
43 } 43 }
44 44
45 impl OneWireSensor { 45 impl OneWireSensor {
69 fn read_sensor(&self, n: &str) -> Result<f32, TemplogError> { 69 fn read_sensor(&self, n: &str) -> Result<f32, TemplogError> {
70 lazy_static! { 70 lazy_static! {
71 // multiline 71 // multiline
72 static ref THERM_RE: regex::Regex = regex::Regex::new("(?m).* YES\n.*t=(.*)\n").unwrap(); 72 static ref THERM_RE: regex::Regex = regex::Regex::new("(?m).* YES\n.*t=(.*)\n").unwrap();
73 } 73 }
74 let mut path = PathBuf::from(&self.config.SENSOR_BASE_DIR); 74 let mut path = PathBuf::from(&self.config.sensor_base_dir);
75 path.push(n); 75 path.push(n);
76 path.push("w1_slave"); 76 path.push("w1_slave");
77 let mut s = String::new(); 77 let mut s = String::new();
78 File::open(path)?.read_to_string(&mut s)?; 78 File::open(path)?.read_to_string(&mut s)?;
79 let caps = THERM_RE.captures(&s).ok_or_else(|| { 79 let caps = THERM_RE.captures(&s).ok_or_else(|| {
86 Ok(f32::from_str(v)?) 86 Ok(f32::from_str(v)?)
87 } 87 }
88 88
89 fn sensor_names(&self) -> Result<Vec<String>, TemplogError> { 89 fn sensor_names(&self) -> Result<Vec<String>, TemplogError> {
90 // TODO: needs to handle multiple busses. 90 // TODO: needs to handle multiple busses.
91 let mut path = PathBuf::from(&self.config.SENSOR_BASE_DIR); 91 let mut path = PathBuf::from(&self.config.sensor_base_dir);
92 path.push("w1_master_slaves"); 92 path.push("w1_master_slaves");
93 93
94 let f = BufReader::new(File::open(path)?); 94 let f = BufReader::new(File::open(path)?);
95 let s = f.lines().collect::<Result<Vec<String>, io::Error>>()?; 95 let s = f.lines().collect::<Result<Vec<String>, io::Error>>()?;
96 Ok(s) 96 Ok(s)
107 self.chan.as_ref().unwrap().tell(Publish{msg: self.get_readings(), topic: "readings".into()}, None); 107 self.chan.as_ref().unwrap().tell(Publish{msg: self.get_readings(), topic: "readings".into()}, None);
108 } 108 }
109 109
110 fn pre_start(&mut self, ctx: &Context<Self::Msg>) { 110 fn pre_start(&mut self, ctx: &Context<Self::Msg>) {
111 self.chan = Some(channel("readings", &ctx.system).unwrap()); 111 self.chan = Some(channel("readings", &ctx.system).unwrap());
112 let dur = Duration::new(self.config.SENSOR_SLEEP,0); 112 let dur = Duration::new(self.config.sensor_sleep,0);
113 ctx.schedule(Duration::from_millis(0), dur, ctx.myself(), None, SendReading); 113 ctx.schedule(Duration::from_millis(0), dur, ctx.myself(), None, SendReading);
114 } 114 }
115 } 115 }
116 116
117 impl TestSensor { 117 impl TestSensor {