comparison rust/src/fridge.rs @ 633:490e9e15b98c rust

move some bits to riker
author Matt Johnston <matt@ucc.asn.au>
date Wed, 04 Sep 2019 23:24:13 +0800
parents bde302def78e
children a5721c02d3ee
comparison
equal deleted inserted replaced
632:bde302def78e 633:490e9e15b98c
9 use super::config::Config; 9 use super::config::Config;
10 use super::params::Params; 10 use super::params::Params;
11 use super::types::*; 11 use super::types::*;
12 12
13 #[derive(Debug)] 13 #[derive(Debug)]
14 pub struct Reading {
15 wort: Option<f32>,
16 fridge: Option<f32>,
17 }
18
19 #[derive(Debug)]
20 pub struct Tick; 14 pub struct Tick;
21 15
22 16
23 #[actor(Params, Tick, Reading)] 17 #[actor(Params, Tick, Readings)]
24 pub struct Fridge { 18 pub struct Fridge {
25 params: Params, 19 params: Params,
26 config: Config, 20 config: Config,
27 21
28 on: bool, 22 on: bool,
44 // TODO: should we do self.tick(ctx) here instead? 38 // TODO: should we do self.tick(ctx) here instead?
45 } 39 }
46 40
47 fn post_start(&mut self, ctx: &Context<Self::Msg>) { 41 fn post_start(&mut self, ctx: &Context<Self::Msg>) {
48 self.tick(ctx); 42 self.tick(ctx);
49 } 43
50 } 44 let chan = channel("readings", &ctx.system).unwrap();
51 45 let sub = Box::new(ctx.myself());
52 impl Receive<Reading> for Fridge { 46 chan.tell(Subscribe {actor: sub, topic: "readings".into()}, None);
47
48 let chan = channel("params", &ctx.system).unwrap();
49 let sub = Box::new(ctx.myself());
50 chan.tell(Subscribe {actor: sub, topic: "params".into()}, None);
51 }
52 }
53
54 impl Receive<Readings> for Fridge {
53 type Msg = FridgeMsg; 55 type Msg = FridgeMsg;
54 fn receive(&mut self, 56 fn receive(&mut self,
55 ctx: &Context<Self::Msg>, 57 ctx: &Context<Self::Msg>,
56 r: Reading, 58 r: Readings,
57 _sender: Sender) { 59 _sender: Sender) {
58 self.temp_wort = r.wort; 60 self.temp_wort = r.get_temp(self.config.WORT_NAME);
59 self.temp_fridge = r.fridge; 61 self.temp_fridge = r.get_temp(self.config.FRIDGE_NAME);
60 62
61 if self.temp_wort.is_some() { 63 if self.temp_wort.is_some() {
62 self.wort_valid_time = Instant::now(); 64 self.wort_valid_time = Instant::now();
63 } 65 }
64 66
269 /// * overshoot calculation 271 /// * overshoot calculation
270 /// * minimum fridge-off time 272 /// * minimum fridge-off time
271 /// * invalid wort timeout 273 /// * invalid wort timeout
272 /// All specified in next_wakeup() 274 /// All specified in next_wakeup()
273 fn tick(&mut self, 275 fn tick(&mut self,
274 ctx: &Context<Self::Msg>) { 276 ctx: &Context<<Self as Actor>::Msg>) {
275 debug!("tick"); 277 debug!("tick");
276 278
277 self.compare_temperatures(); 279 self.compare_temperatures();
278 280
279 // Sets the next self-wakeup timeout 281 // Sets the next self-wakeup timeout