Mercurial > templog
comparison rust/src/fridge.rs @ 638:a9f353f488d0 rust
fix channels
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 09 Nov 2019 11:35:59 +0800 |
parents | 43eb3cfdf769 |
children |
comparison
equal
deleted
inserted
replaced
637:1e147b3c2c55 | 638:a9f353f488d0 |
---|---|
9 use riker::actors::*; | 9 use riker::actors::*; |
10 | 10 |
11 #[cfg(target_os = "linux")] | 11 #[cfg(target_os = "linux")] |
12 use self::sysfs_gpio::{Direction, Pin}; | 12 use self::sysfs_gpio::{Direction, Pin}; |
13 | 13 |
14 use crate::params::Params; | |
14 use super::config::Config; | 15 use super::config::Config; |
15 use super::params::Params; | 16 use super::params; |
17 use super::sensor; | |
16 use super::types::*; | 18 use super::types::*; |
17 | 19 |
18 #[derive(Debug,Clone)] | 20 #[derive(Debug,Clone)] |
19 pub struct Tick; | 21 pub struct Tick; |
20 | 22 |
21 #[actor(Params, Tick, Readings)] | 23 #[actor(Params, Tick, Readings)] |
22 pub struct Fridge { | 24 pub struct Fridge { |
23 params: Params, | 25 params: Params, |
24 config: Config, | 26 config: Config, |
27 testmode: bool, | |
25 | 28 |
26 on: bool, | 29 on: bool, |
27 temp_wort: Option<f32>, | 30 temp_wort: Option<f32>, |
28 temp_fridge: Option<f32>, | 31 temp_fridge: Option<f32>, |
29 last_off_time: Instant, | 32 last_off_time: Instant, |
41 self.receive(ctx, msg, sender); | 44 self.receive(ctx, msg, sender); |
42 // TODO: should we do self.tick(ctx) here instead? | 45 // TODO: should we do self.tick(ctx) here instead? |
43 } | 46 } |
44 | 47 |
45 fn pre_start(&mut self, ctx: &Context<Self::Msg>) { | 48 fn pre_start(&mut self, ctx: &Context<Self::Msg>) { |
46 let chan: ChannelRef<Readings> = channel("readings", &ctx.system).unwrap(); | 49 |
50 let params_chan : ChannelRef<Params> = channel("params", ctx).unwrap(); | |
51 let sensor_chan : ChannelRef<Readings> = channel("readings", ctx).unwrap(); | |
47 let sub = Box::new(ctx.myself()); | 52 let sub = Box::new(ctx.myself()); |
48 chan.tell(Subscribe {actor: sub, topic: "readings".into()}, None); | 53 params_chan.tell(Subscribe {actor: sub.clone(), topic: "params".into()}, None); |
49 | 54 sensor_chan.tell(Subscribe {actor: sub.clone(), topic: "readings".into()}, None); |
50 let chan: ChannelRef<Params> = channel("params", &ctx.system).unwrap(); | 55 |
51 let sub = Box::new(ctx.myself()); | 56 |
52 chan.tell(Subscribe {actor: sub, topic: "params".into()}, None); | 57 // XXX a better way to get own reference? |
58 let props = Props::new_args(params::ParamWaiter::new_actor, (self.config.clone(), params_chan)); | |
59 ctx.actor_of(props, "paramwaiter").unwrap(); | |
60 | |
61 if self.testmode { | |
62 let props = Props::new_args(sensor::TestSensor::new_actor, (self.config.clone(), sensor_chan)); | |
63 ctx.actor_of(props, "sensor").unwrap() | |
64 } else { | |
65 let props = Props::new_args(sensor::OneWireSensor::new_actor, (self.config.clone(), sensor_chan)); | |
66 ctx.actor_of(props, "sensor").unwrap() | |
67 }; | |
53 | 68 |
54 self.tick(ctx); | 69 self.tick(ctx); |
55 } | 70 } |
56 } | 71 } |
57 | 72 |
107 self.turn(false); | 122 self.turn(false); |
108 } | 123 } |
109 } | 124 } |
110 | 125 |
111 impl Fridge { | 126 impl Fridge { |
112 pub fn new_actor((config, nowait) : (Config, bool)) -> Fridge { | 127 pub fn new_actor((config, testmode, nowait) |
113 Self::new(config, nowait) | 128 : (Config, bool, bool)) -> Fridge { |
114 | 129 Self::new(config, testmode, nowait) |
115 } | 130 |
116 pub fn new(config: Config, nowait: bool) -> Fridge { | 131 } |
132 pub fn new(config: Config, | |
133 testmode: bool, | |
134 nowait: bool) -> Fridge { | |
117 let mut f = Fridge { | 135 let mut f = Fridge { |
118 config: config.clone(), | 136 config: config.clone(), |
119 params: Params::defaults(), | 137 params: Params::defaults(), |
120 on: false, | 138 on: false, |
121 temp_wort: None, | 139 temp_wort: None, |
122 temp_fridge: None, | 140 temp_fridge: None, |
123 last_off_time: Instant::now(), | 141 last_off_time: Instant::now(), |
124 wort_valid_time: Instant::now() - Duration::new(config.fridge_wort_invalid_time, 100), | 142 wort_valid_time: Instant::now() - Duration::new(config.fridge_wort_invalid_time, 100), |
125 integrator: StepIntegrator::new(Duration::new(1, 0)), | 143 integrator: StepIntegrator::new(Duration::new(1, 0)), |
126 control: Self::make_control(&config), | 144 control: Self::make_control(&config), |
145 testmode: testmode, | |
127 }; | 146 }; |
128 | 147 |
129 if nowait { | 148 if nowait { |
130 f.last_off_time -= Duration::new(config.fridge_delay, 1); | 149 f.last_off_time -= Duration::new(config.fridge_delay, 1); |
131 } | 150 } |