diff 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
line wrap: on
line diff
--- a/rust/src/fridge.rs	Thu Aug 22 23:59:50 2019 +0800
+++ b/rust/src/fridge.rs	Wed Sep 04 23:24:13 2019 +0800
@@ -11,16 +11,10 @@
 use super::types::*;
 
 #[derive(Debug)]
-pub struct Reading {
-    wort: Option<f32>, 
-    fridge: Option<f32>,
-}
-
-#[derive(Debug)]
 pub struct Tick;
 
 
-#[actor(Params, Tick, Reading)]
+#[actor(Params, Tick, Readings)]
 pub struct Fridge {
     params: Params,
     config: Config,
@@ -46,17 +40,25 @@
 
     fn post_start(&mut self, ctx: &Context<Self::Msg>) {
         self.tick(ctx);
+
+        let chan = 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 sub = Box::new(ctx.myself());
+        chan.tell(Subscribe {actor: sub, topic: "params".into()}, None);
     }
 }
 
-impl Receive<Reading> for Fridge {
+impl Receive<Readings> for Fridge {
     type Msg = FridgeMsg;
     fn receive(&mut self,
                 ctx: &Context<Self::Msg>,
-                r: Reading,
+                r: Readings,
                 _sender: Sender) {
-        self.temp_wort = r.wort;
-        self.temp_fridge = r.fridge;
+        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();
@@ -271,7 +273,7 @@
     ///  * invalid wort timeout
     /// All specified in next_wakeup()
     fn tick(&mut self,
-        ctx: &Context<Self::Msg>) {
+        ctx: &Context<<Self as Actor>::Msg>) {
         debug!("tick");
 
         self.compare_temperatures();