Mercurial > templog
annotate rust/src/fridge.rs @ 632:bde302def78e rust
moving to riker, nowhere near yet
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 22 Aug 2019 23:59:50 +0800 |
parents | c57821a60e51 |
children | 490e9e15b98c |
rev | line source |
---|---|
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
1 use std; |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
2 |
597 | 3 use std::time::{Duration,Instant}; |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
4 use riker::actors::*; |
621 | 5 |
6 #[cfg(target_os = "linux")] | |
626 | 7 use self::sysfs_gpio::{Direction, Pin}; |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
8 |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
9 use super::config::Config; |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
10 use super::params::Params; |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
11 use super::types::*; |
592 | 12 |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
13 #[derive(Debug)] |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
14 pub struct Reading { |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
15 wort: Option<f32>, |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
16 fridge: Option<f32>, |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
17 } |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
18 |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
19 #[derive(Debug)] |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
20 pub struct Tick; |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
21 |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
22 |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
23 #[actor(Params, Tick, Reading)] |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
24 pub struct Fridge { |
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
25 params: Params, |
603
b45b8b4cf0f5
get rid of lazy_static, config is passed around
Matt Johnston <matt@ucc.asn.au>
parents:
601
diff
changeset
|
26 config: Config, |
620 | 27 |
28 on: bool, | |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
29 temp_wort: Option<f32>, |
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
30 temp_fridge: Option<f32>, |
620 | 31 last_off_time: Instant, |
32 wort_valid_time: Instant, | |
33 integrator: StepIntegrator, | |
621 | 34 control: FridgeControl, |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
35 } |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
36 |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
37 impl Actor for Fridge { |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
38 type Msg = FridgeMsg; |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
39 fn recv(&mut self, |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
40 ctx: &Context<Self::Msg>, |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
41 msg: Self::Msg, |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
42 sender: Sender) { |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
43 self.receive(ctx, msg, sender); |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
44 // TODO: should we do self.tick(ctx) here instead? |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
45 } |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
46 |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
47 fn post_start(&mut self, ctx: &Context<Self::Msg>) { |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
48 self.tick(ctx); |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
49 } |
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 |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
52 impl Receive<Reading> for Fridge { |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
53 type Msg = FridgeMsg; |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
54 fn receive(&mut self, |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
55 ctx: &Context<Self::Msg>, |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
56 r: Reading, |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
57 _sender: Sender) { |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
58 self.temp_wort = r.wort; |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
59 self.temp_fridge = r.fridge; |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
60 |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
61 if self.temp_wort.is_some() { |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
62 self.wort_valid_time = Instant::now(); |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
63 } |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
64 |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
65 self.tick(ctx); |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
66 } |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
67 } |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
68 |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
69 impl Receive<Params> for Fridge { |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
70 type Msg = FridgeMsg; |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
71 fn receive(&mut self, |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
72 ctx: &Context<Self::Msg>, |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
73 p: Params, |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
74 _sender: Sender) { |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
75 self.params = p; |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
76 println!("fridge set_params {:?}", self.params); |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
77 |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
78 self.tick(ctx); |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
79 } |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
80 } |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
81 |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
82 impl Receive<Tick> for Fridge { |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
83 type Msg = FridgeMsg; |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
84 fn receive(&mut self, |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
85 ctx: &Context<Self::Msg>, |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
86 _tick: Tick, |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
87 _sender: Sender) { |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
88 self.tick(ctx); |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
89 } |
592 | 90 } |
91 | |
621 | 92 enum FridgeControl { |
93 #[cfg(target_os = "linux")] | |
94 Gpio(Pin), | |
95 Fake, | |
96 } | |
97 | |
620 | 98 impl Drop for Fridge { |
99 fn drop(&mut self) { | |
100 // safety fridge off | |
621 | 101 self.turn(false); |
620 | 102 } |
103 } | |
104 | |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
105 impl Fridge { |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
106 pub fn new(config: &Config, nowait: bool, p: Params) -> Fridge { |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
107 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
|
108 config: config.clone(), |
615 | 109 params: p.clone(), |
620 | 110 on: false, |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
111 temp_wort: None, |
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
112 temp_fridge: None, |
620 | 113 last_off_time: Instant::now(), |
114 wort_valid_time: Instant::now() - Duration::new(config.FRIDGE_WORT_INVALID_TIME, 100), | |
621 | 115 integrator: StepIntegrator::new(Duration::new(p.overshoot_delay, 0)), |
116 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
|
117 }; |
620 | 118 |
597 | 119 if nowait { |
609
7bda01659426
not building, paramwaiter work
Matt Johnston <matt@ucc.asn.au>
parents:
606
diff
changeset
|
120 f.last_off_time -= Duration::new(config.FRIDGE_DELAY, 1); |
597 | 121 } |
620 | 122 |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
123 f.tick(); |
620 | 124 |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
125 f |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
126 } |
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
127 |
621 | 128 #[cfg(target_os = "linux")] |
129 fn make_control(config: &Config) -> FridgeControl { | |
130 let mut pin = Pin(config.FRIDGE_GPIO_PIN); | |
131 // XXX better error handling? | |
132 pin.export().expect("Exporting fridge gpio failed"); | |
133 pin.set_direction(Direction::Low).expect("Fridge gpio direction failed"); | |
134 FridgeControl::Gpio(pin) | |
135 } | |
136 | |
137 #[cfg(not(target_os = "linux"))] | |
138 fn make_control(config: &Config) -> FridgeControl { | |
139 FridgeControl::Fake | |
140 } | |
141 | |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
142 fn next_wakeup(&self) -> Duration { |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
143 let millis = 400; |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
144 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
|
145 dur |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
146 } |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
147 |
606 | 148 |
620 | 149 fn turn_off(&mut self) { |
621 | 150 info!("Turning fridge off"); |
620 | 151 self.turn(false); |
152 } | |
153 | |
154 fn turn_on(&mut self) { | |
621 | 155 info!("Turning fridge on"); |
620 | 156 self.turn(true); |
157 } | |
158 | |
159 fn turn(&mut self, on: bool) { | |
621 | 160 match self.control { |
161 #[cfg(target_os = "linux")] | |
162 Gpio(pin) => pin.set_value(on as u8), | |
163 FridgeControl::Fake => debug!("fridge turns {}", if on {"on"} else {"off"}), | |
164 } | |
620 | 165 self.on = on; |
166 } | |
167 | |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
168 // Turns the fridge off and on |
620 | 169 fn compare_temperatures(&mut self) { |
170 let fridge_min = self.params.fridge_setpoint - self.params.fridge_range_lower; | |
171 let fridge_max = self.params.fridge_setpoint - self.params.fridge_range_upper; | |
172 let wort_max = self.params.fridge_setpoint + self.params.fridge_difference; | |
173 let off_time = Instant::now() - self.last_off_time; | |
174 | |
175 // Or elsewhere? | |
621 | 176 self.integrator.set_limit(Duration::new(self.params.overshoot_delay, 0)); |
620 | 177 |
178 // Safety to avoid bad things happening to the fridge motor (?) | |
179 // When it turns off don't start up again for at least FRIDGE_DELAY | |
621 | 180 if !self.on && off_time < Duration::new(self.config.FRIDGE_DELAY, 0) { |
181 info!("fridge skipping, too early"); | |
620 | 182 return; |
183 } | |
184 | |
185 if self.params.disabled { | |
186 if self.on { | |
621 | 187 info!("Disabled, turning fridge off"); |
620 | 188 self.turn_off(); |
189 } | |
190 return; | |
191 } | |
192 | |
193 // handle broken wort sensor | |
194 if self.temp_wort.is_none() { | |
195 let invalid_time = Instant::now() - self.wort_valid_time; | |
196 warn!("Invalid wort sensor for {:?} secs", invalid_time); | |
621 | 197 if invalid_time < Duration::new(self.config.FRIDGE_WORT_INVALID_TIME, 0) { |
620 | 198 warn!("Has only been invalid for {:?}, waiting", invalid_time); |
199 return; | |
200 } | |
201 } | |
202 | |
203 if self.temp_fridge.is_none() { | |
204 warn!("Invalid fridge sensor"); | |
205 } | |
206 | |
207 if self.on { | |
208 debug!("fridge is on"); | |
209 let on_time = self.integrator.integrate().as_secs() as f32; | |
621 | 210 let on_ratio = on_time / self.params.overshoot_delay as f32; |
620 | 211 |
621 | 212 let overshoot = self.params.overshoot_factor as f32 * on_ratio; |
213 debug!("on_percent {}, overshoot {}", on_ratio * 100.0, overshoot); | |
620 | 214 |
215 let mut turn_off = false; | |
621 | 216 if self.temp_wort.is_some() && !self.params.nowort { |
217 let t = self.temp_wort.unwrap(); | |
620 | 218 // use the wort temperature |
621 | 219 if t - overshoot < self.params.fridge_setpoint { |
220 info!("wort has cooled enough, {temp}º (overshoot {overshoot}º = {factor} × {percent}%)", | |
620 | 221 temp = t, overshoot = overshoot, |
621 | 222 factor = self.params.overshoot_factor, |
223 percent = on_ratio*100.0); | |
620 | 224 turn_off = true; |
225 } | |
621 | 226 } else if let Some(t) = self.temp_fridge { |
620 | 227 // use the fridge temperature |
228 if t < fridge_min { | |
229 warn!("fridge off fallback, fridge {}, min {}", t, fridge_min); | |
230 if self.temp_wort.is_none() { | |
621 | 231 warn!("wort has been invalid for {:?}", Instant::now() - self.wort_valid_time); |
620 | 232 } |
233 turn_off = true; | |
234 } | |
235 } | |
236 if turn_off { | |
237 self.turn_off(); | |
238 } | |
239 } else { | |
240 debug!("fridge is off. fridge {:?} max {:?}. wort {:?} max {:?}", | |
241 self.temp_fridge, fridge_max, self.temp_wort, wort_max); | |
242 let mut turn_on = false; | |
621 | 243 if self.temp_wort.is_some() && !self.params.nowort { |
620 | 244 // use the wort temperature |
621 | 245 let t = self.temp_wort.unwrap(); |
620 | 246 if t >= wort_max { |
621 | 247 info!("Wort is too hot {}°, max {}°", t, wort_max); |
620 | 248 turn_on = true; |
249 } | |
250 } | |
251 | |
252 if let Some(t) = self.temp_fridge { | |
253 if t >= fridge_max { | |
621 | 254 warn!("fridge too hot fallback, fridge {}°, max {}°", t, fridge_max); |
620 | 255 turn_on = true; |
256 } | |
257 } | |
258 | |
259 if turn_on { | |
260 self.turn_on() | |
261 } | |
262 } | |
263 } | |
264 | |
606 | 265 /// Must be called after every state change. Turns the fridge on/off as required and |
266 /// schedules any future wakeups based on the present (new) state | |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
267 /// Examples of wakeups events are |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
268 /// |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
269 /// * overshoot calculation |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
270 /// * minimum fridge-off time |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
271 /// * invalid wort timeout |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
272 /// All specified in next_wakeup() |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
273 fn tick(&mut self, |
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
274 ctx: &Context<Self::Msg>) { |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
275 debug!("tick"); |
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
276 |
621 | 277 self.compare_temperatures(); |
592 | 278 |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
279 // Sets the next self-wakeup timeout |
594
aff50ee77252
rust working better now with streams and sinks.
Matt Johnston <matt@ucc.asn.au>
parents:
593
diff
changeset
|
280 let dur = self.next_wakeup(); |
632
bde302def78e
moving to riker, nowhere near yet
Matt Johnston <matt@ucc.asn.au>
parents:
631
diff
changeset
|
281 ctx.schedule_once(dur, self, None, Tick); |
593
bf138339d20a
fiddling with timeouts and closures
Matt Johnston <matt@ucc.asn.au>
parents:
592
diff
changeset
|
282 } |
592 | 283 } |