Mercurial > templog
annotate rust/src/fridge.rs @ 631:c57821a60e51 rust
rust work in progress ?
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 06 Jul 2019 18:28:34 +0800 |
parents | e1b5938de122 |
children | bde302def78e |
rev | line source |
---|---|
626 | 1 #[cfg(target_os = "linux")] |
620 | 2 extern crate sysfs_gpio; |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
3 |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
4 use std; |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
5 use std::io; |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
6 use std::mem; |
611
f3e39e2107fd
still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents:
609
diff
changeset
|
7 use std::error::Error; |
597 | 8 use std::time::{Duration,Instant}; |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
9 |
631 | 10 use futures::{Future,Stream}; |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
11 use futures::sync::{mpsc}; |
621 | 12 |
13 #[cfg(target_os = "linux")] | |
626 | 14 use self::sysfs_gpio::{Direction, Pin}; |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
15 |
615 | 16 use config::Config; |
17 use params::Params; | |
592 | 18 use types::*; |
19 | |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
20 #[derive(Debug)] |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
21 pub enum Message { |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
22 Sensor {wort: Option<f32>, fridge: Option<f32>}, |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
23 Params (Params), |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
24 Tick(u64), |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
25 } |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
26 |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
27 pub struct Fridge { |
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
28 params: Params, |
603
b45b8b4cf0f5
get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents:
601
diff
changeset
|
29 config: Config, |
620 | 30 |
31 on: bool, | |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
32 temp_wort: Option<f32>, |
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
33 temp_fridge: Option<f32>, |
620 | 34 last_off_time: Instant, |
35 wort_valid_time: Instant, | |
36 integrator: StepIntegrator, | |
621 | 37 control: FridgeControl, |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
38 |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
39 // Timeouts to wake ourselves up again |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
40 handle: Handle, |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
41 timeout_s: mpsc::Sender<u64>, |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
42 timeout_r: Option<mpsc::Receiver<u64>>, |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
43 ticker: u64, |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
44 } |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
45 |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
46 impl Sink for Fridge { |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
47 |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
48 type SinkItem = Message; |
611
f3e39e2107fd
still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents:
609
diff
changeset
|
49 type SinkError = TemplogError; |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
50 |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
51 fn start_send(&mut self, msg: Message) |
628
e1b5938de122
futures sink? unsure what this was
Matt Johnston <matt@ucc.asn.au>
parents:
626
diff
changeset
|
52 -> Result<(), Self::SinkError> { |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
53 self.process_msg(msg); |
628
e1b5938de122
futures sink? unsure what this was
Matt Johnston <matt@ucc.asn.au>
parents:
626
diff
changeset
|
54 Ok() |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
55 } |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
56 |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
57 fn poll_complete(&mut self) -> futures::Poll<(), Self::SinkError> { |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
58 Ok(futures::Async::Ready(())) |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
59 } |
592 | 60 } |
61 | |
621 | 62 enum FridgeControl { |
63 #[cfg(target_os = "linux")] | |
64 Gpio(Pin), | |
65 Fake, | |
66 } | |
67 | |
68 struct TestControl {} | |
69 | |
620 | 70 impl Drop for Fridge { |
71 fn drop(&mut self) { | |
72 // safety fridge off | |
621 | 73 self.turn(false); |
620 | 74 } |
75 } | |
76 | |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
77 impl Fridge { |
603
b45b8b4cf0f5
get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents:
601
diff
changeset
|
78 pub fn new(config: &Config, nowait: bool, p: Params, handle: &Handle) -> Fridge { |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
79 let (s, r) = mpsc::channel(1); |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
80 let mut f = Fridge { |
603
b45b8b4cf0f5
get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents:
601
diff
changeset
|
81 config: config.clone(), |
615 | 82 params: p.clone(), |
620 | 83 on: false, |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
84 temp_wort: None, |
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
85 temp_fridge: None, |
620 | 86 last_off_time: Instant::now(), |
87 wort_valid_time: Instant::now() - Duration::new(config.FRIDGE_WORT_INVALID_TIME, 100), | |
621 | 88 integrator: StepIntegrator::new(Duration::new(p.overshoot_delay, 0)), |
89 control: Self::make_control(config), | |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
90 |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
91 handle: handle.clone(), |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
92 timeout_s: s, |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
93 timeout_r: Some(r), |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
94 ticker: 0, |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
95 }; |
620 | 96 |
597 | 97 if nowait { |
609
7bda01659426
not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents:
606
diff
changeset
|
98 f.last_off_time -= Duration::new(config.FRIDGE_DELAY, 1); |
597 | 99 } |
620 | 100 |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
101 f.tick(); |
620 | 102 |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
103 f |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
104 } |
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
105 |
621 | 106 #[cfg(target_os = "linux")] |
107 fn make_control(config: &Config) -> FridgeControl { | |
108 let mut pin = Pin(config.FRIDGE_GPIO_PIN); | |
109 // XXX better error handling? | |
110 pin.export().expect("Exporting fridge gpio failed"); | |
111 pin.set_direction(Direction::Low).expect("Fridge gpio direction failed"); | |
112 FridgeControl::Gpio(pin) | |
113 } | |
114 | |
115 #[cfg(not(target_os = "linux"))] | |
116 fn make_control(config: &Config) -> FridgeControl { | |
117 FridgeControl::Fake | |
118 } | |
119 | |
120 | |
121 | |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
122 fn next_wakeup(&self) -> Duration { |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
123 let millis = 400; |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
124 let dur = Duration::from_millis(millis); |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
125 dur |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
126 } |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
127 |
606 | 128 /// The fridge needs to periodically wake itself up, the returned |
129 /// stream of Tick messages does so. | |
130 /// Examples of wakeups events are | |
131 /// | |
132 /// * overshoot calculation | |
133 /// * minimum fridge-off time | |
134 /// * invalid wort timeout | |
135 /// All specified in next_wakeup() | |
136 pub fn wakeups(&mut self) | |
611
f3e39e2107fd
still doesn't compile, improvements to TemplogError and tokio curl though
Matt Johnston <matt@ucc.asn.au>
parents:
609
diff
changeset
|
137 -> Box<Stream<Item=Message, Error=TemplogError>> { |
626 | 138 Box::new(mem::replace(&mut self.timeout_r, None) |
606 | 139 .expect("Fridge::wakeups() can only be called once") |
140 .map(|v| Message::Tick(v)) | |
626 | 141 .map_err(|e| TemplogError::new("wakeups() receive failed"))) |
606 | 142 } |
143 | |
620 | 144 fn turn_off(&mut self) { |
621 | 145 info!("Turning fridge off"); |
620 | 146 self.turn(false); |
147 } | |
148 | |
149 fn turn_on(&mut self) { | |
621 | 150 info!("Turning fridge on"); |
620 | 151 self.turn(true); |
152 } | |
153 | |
154 fn turn(&mut self, on: bool) { | |
621 | 155 match self.control { |
156 #[cfg(target_os = "linux")] | |
157 Gpio(pin) => pin.set_value(on as u8), | |
158 FridgeControl::Fake => debug!("fridge turns {}", if on {"on"} else {"off"}), | |
159 } | |
620 | 160 self.on = on; |
161 } | |
162 | |
163 /// Turns the fridge off and on | |
164 fn compare_temperatures(&mut self) { | |
165 let fridge_min = self.params.fridge_setpoint - self.params.fridge_range_lower; | |
166 let fridge_max = self.params.fridge_setpoint - self.params.fridge_range_upper; | |
167 let wort_max = self.params.fridge_setpoint + self.params.fridge_difference; | |
168 let off_time = Instant::now() - self.last_off_time; | |
169 | |
170 // Or elsewhere? | |
621 | 171 self.integrator.set_limit(Duration::new(self.params.overshoot_delay, 0)); |
620 | 172 |
173 // Safety to avoid bad things happening to the fridge motor (?) | |
174 // When it turns off don't start up again for at least FRIDGE_DELAY | |
621 | 175 if !self.on && off_time < Duration::new(self.config.FRIDGE_DELAY, 0) { |
176 info!("fridge skipping, too early"); | |
620 | 177 return; |
178 } | |
179 | |
180 if self.params.disabled { | |
181 if self.on { | |
621 | 182 info!("Disabled, turning fridge off"); |
620 | 183 self.turn_off(); |
184 } | |
185 return; | |
186 } | |
187 | |
188 // handle broken wort sensor | |
189 if self.temp_wort.is_none() { | |
190 let invalid_time = Instant::now() - self.wort_valid_time; | |
191 warn!("Invalid wort sensor for {:?} secs", invalid_time); | |
621 | 192 if invalid_time < Duration::new(self.config.FRIDGE_WORT_INVALID_TIME, 0) { |
620 | 193 warn!("Has only been invalid for {:?}, waiting", invalid_time); |
194 return; | |
195 } | |
196 } | |
197 | |
198 if self.temp_fridge.is_none() { | |
199 warn!("Invalid fridge sensor"); | |
200 } | |
201 | |
202 if self.on { | |
203 debug!("fridge is on"); | |
204 let on_time = self.integrator.integrate().as_secs() as f32; | |
621 | 205 let on_ratio = on_time / self.params.overshoot_delay as f32; |
620 | 206 |
621 | 207 let overshoot = self.params.overshoot_factor as f32 * on_ratio; |
208 debug!("on_percent {}, overshoot {}", on_ratio * 100.0, overshoot); | |
620 | 209 |
210 let mut turn_off = false; | |
621 | 211 if self.temp_wort.is_some() && !self.params.nowort { |
212 let t = self.temp_wort.unwrap(); | |
620 | 213 // use the wort temperature |
621 | 214 if t - overshoot < self.params.fridge_setpoint { |
215 info!("wort has cooled enough, {temp}º (overshoot {overshoot}º = {factor} × {percent}%)", | |
620 | 216 temp = t, overshoot = overshoot, |
621 | 217 factor = self.params.overshoot_factor, |
218 percent = on_ratio*100.0); | |
620 | 219 turn_off = true; |
220 } | |
621 | 221 } else if let Some(t) = self.temp_fridge { |
620 | 222 // use the fridge temperature |
223 if t < fridge_min { | |
224 warn!("fridge off fallback, fridge {}, min {}", t, fridge_min); | |
225 if self.temp_wort.is_none() { | |
621 | 226 warn!("wort has been invalid for {:?}", Instant::now() - self.wort_valid_time); |
620 | 227 } |
228 turn_off = true; | |
229 } | |
230 } | |
231 if turn_off { | |
232 self.turn_off(); | |
233 } | |
234 } else { | |
235 debug!("fridge is off. fridge {:?} max {:?}. wort {:?} max {:?}", | |
236 self.temp_fridge, fridge_max, self.temp_wort, wort_max); | |
237 let mut turn_on = false; | |
621 | 238 if self.temp_wort.is_some() && !self.params.nowort { |
620 | 239 // use the wort temperature |
621 | 240 let t = self.temp_wort.unwrap(); |
620 | 241 if t >= wort_max { |
621 | 242 info!("Wort is too hot {}°, max {}°", t, wort_max); |
620 | 243 turn_on = true; |
244 } | |
245 } | |
246 | |
247 if let Some(t) = self.temp_fridge { | |
248 if t >= fridge_max { | |
621 | 249 warn!("fridge too hot fallback, fridge {}°, max {}°", t, fridge_max); |
620 | 250 turn_on = true; |
251 } | |
252 } | |
253 | |
254 if turn_on { | |
255 self.turn_on() | |
256 } | |
257 } | |
258 } | |
259 | |
606 | 260 /// Must be called after every state change. Turns the fridge on/off as required and |
261 /// schedules any future wakeups based on the present (new) state | |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
262 fn tick(&mut self) { |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
263 debug!("tick"); |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
264 |
621 | 265 self.compare_temperatures(); |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
266 self.send_next_timeout(); |
592 | 267 } |
268 | |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
269 /// Sets the next self-wakeup timeout |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
270 fn send_next_timeout(&mut self) { |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
271 let waker = self.timeout_s.clone(); |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
272 let dur = self.next_wakeup(); |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
273 debug!("fridge next wakeup {:?}", dur); |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
274 self.ticker += 1; |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
275 let v = self.ticker; |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
276 let t = Timeout::new(dur, &self.handle).unwrap() |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
277 .map_err(|_| ()) |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
278 .and_then(move |_| { |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
279 waker.send(v) |
595 | 280 .map_err(|e| { |
281 warn!("Send error in tick(): {}", e.to_string()); | |
282 () | |
283 }) | |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
284 }) |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
285 .map(|_| ()); |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
286 self.handle.spawn(t); |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
287 } |
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
288 |
609
7bda01659426
not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents:
606
diff
changeset
|
289 fn process_msg(&mut self, msg: Message) { |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
290 debug!("process_msg {:?}", msg); |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
291 match msg { |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
292 Message::Sensor{wort, fridge} => self.update_sensor(wort, fridge), |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
293 Message::Params(p) => self.update_params(p), |
606 | 294 Message::Tick(v) => if v == self.ticker {self.tick()}, // schedule a timeout if there are none pending |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
295 }; |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
296 } |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
297 |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
298 pub fn update_params(&mut self, p: Params) { |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
299 self.params = p; |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
300 println!("fridge set_params {:?}", self.params); |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
301 |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
302 self.tick(); |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
303 } |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
304 |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
305 pub fn update_sensor(&mut self, wort: Option<f32>, fridge: Option<f32>) { |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
306 self.temp_wort = wort; |
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
307 self.temp_fridge = fridge; |
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
308 |
620 | 309 if self.temp_wort.is_some() { |
606 | 310 self.wort_valid_time = Instant::now(); |
620 | 311 } |
606 | 312 |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
313 self.tick(); |
592 | 314 } |
315 | |
316 } |