diff rust/src/fridge.rs @ 634:a5721c02d3ee rust

build succeeds
author Matt Johnston <matt@ucc.asn.au>
date Sun, 22 Sep 2019 20:35:40 +0800
parents 490e9e15b98c
children 4424a8b30f9c
line wrap: on
line diff
--- a/rust/src/fridge.rs	Wed Sep 04 23:24:13 2019 +0800
+++ b/rust/src/fridge.rs	Sun Sep 22 20:35:40 2019 +0800
@@ -1,3 +1,8 @@
+// TODO:
+// - riker
+//   - use monotonic clock
+//   - timer.rs should use rx.recv_timeout(next_time) instead of rx.try_recv()
+//       and then could remove cfg.frequency_millis
 use std;
 
 use std::time::{Duration,Instant};
@@ -10,10 +15,9 @@
 use super::params::Params;
 use super::types::*;
 
-#[derive(Debug)]
+#[derive(Debug,Clone)]
 pub struct Tick;
 
-
 #[actor(Params, Tick, Readings)]
 pub struct Fridge {
     params: Params,
@@ -38,16 +42,16 @@
         // TODO: should we do self.tick(ctx) here instead?
     }
 
-    fn post_start(&mut self, ctx: &Context<Self::Msg>) {
-        self.tick(ctx);
-
-        let chan = channel("readings", &ctx.system).unwrap();
+    fn pre_start(&mut self, ctx: &Context<Self::Msg>) {
+        let chan: ChannelRef<Readings> = channel("readings", &ctx.system).unwrap();
         let sub = Box::new(ctx.myself());
         chan.tell(Subscribe {actor: sub, topic: "readings".into()}, None);
 
-        let chan = channel("params", &ctx.system).unwrap();
+        let chan: ChannelRef<Params> = channel("params", &ctx.system).unwrap();
         let sub = Box::new(ctx.myself());
         chan.tell(Subscribe {actor: sub, topic: "params".into()}, None);
+
+        self.tick(ctx);
     }
 }
 
@@ -57,8 +61,8 @@
                 ctx: &Context<Self::Msg>,
                 r: Readings,
                 _sender: Sender) {
-        self.temp_wort = r.get_temp(self.config.WORT_NAME);
-        self.temp_fridge = r.get_temp(self.config.FRIDGE_NAME);
+        self.temp_wort = r.get_temp(&self.config.WORT_NAME);
+        self.temp_fridge = r.get_temp(&self.config.FRIDGE_NAME);
 
         if self.temp_wort.is_some() {
             self.wort_valid_time = Instant::now();
@@ -105,25 +109,27 @@
 }
 
 impl Fridge {
-    pub fn new(config: &Config, nowait: bool, p: Params) -> Fridge {
+    pub fn new_actor((config, nowait) : (Config, bool)) -> Fridge {
+        Self::new(config, nowait)
+
+    }
+    pub fn new(config: Config, nowait: bool) -> Fridge {
         let mut f = Fridge { 
             config: config.clone(),
-            params: p.clone(),
+            params: Params::defaults(),
             on: false,
             temp_wort: None,
             temp_fridge: None,
             last_off_time: Instant::now(),
             wort_valid_time: Instant::now() - Duration::new(config.FRIDGE_WORT_INVALID_TIME, 100),
-            integrator: StepIntegrator::new(Duration::new(p.overshoot_delay, 0)),
-            control: Self::make_control(config),
+            integrator: StepIntegrator::new(Duration::new(1, 0)),
+            control: Self::make_control(&config),
         };
 
         if nowait {
             f.last_off_time -= Duration::new(config.FRIDGE_DELAY, 1);
         }
 
-        f.tick();
-
         f
     }
 
@@ -137,7 +143,7 @@
     }
 
 #[cfg(not(target_os = "linux"))]
-    fn make_control(config: &Config) -> FridgeControl {
+    fn make_control(_config: &Config) -> FridgeControl {
             FridgeControl::Fake
     }
 
@@ -280,6 +286,6 @@
 
         // Sets the next self-wakeup timeout
         let dur = self.next_wakeup();
-        ctx.schedule_once(dur, self, None, Tick);
+        ctx.schedule_once(dur, ctx.myself(), None, Tick);
     }
 }