diff rust/src/main.rs @ 620:8fda564cc46f rust

fridge work
author Matt Johnston <matt@ucc.asn.au>
date Thu, 23 Mar 2017 00:20:22 +0800
parents a85c0c9bc1fa
children 03167105f6de
line wrap: on
line diff
--- a/rust/src/main.rs	Tue Mar 21 22:41:29 2017 +0800
+++ b/rust/src/main.rs	Thu Mar 23 00:20:22 2017 +0800
@@ -44,9 +44,6 @@
     let params = params::Params::load(&config);
     let mut fridge = fridge::Fridge::new(&config, nowait, params, &handle);
 
-    let (fridge_reading_s, fridge_reading_r) = mpsc::channel(1);
-    let fridge_reading_r = fridge_reading_r.map_err(|e| TemplogError::new("Problem with fridge_reading_r channel"));
-
     let sensor_stream = if testmode {
         sensor::TestSensor::new(config).stream(&handle)
     } else {
@@ -55,7 +52,9 @@
 
     // Send the sensors of interest to the fridge (fridge_reading_s),
     // while streaming them all to the web sender.
-    let s = sensor_stream.map(|r| {
+    let (fridge_reading_s, fridge_reading_r) = mpsc::channel(1);
+    let fridge_reading_r = fridge_reading_r.map_err(|e| TemplogError::new("Problem with fridge_reading_r channel"));
+    let sensor_stream = sensor_stream.map(|r| {
         debug!("sensors {:?}", r);
         let msg = fridge::Message::Sensor {
             wort: r.get_temp(&config.WORT_NAME), 
@@ -72,18 +71,19 @@
     });
 
     let param_stream = params::ParamWaiter::stream(config, &handle);
-    let p = param_stream.map(|p| {
+    let param_stream = param_stream.map(|p| {
             fridge::Message::Params(p)
         });
 
     let timeouts = fridge.wakeups();
 
-    let all_readings = s.for_each(|_| Ok(()));
-    let all_fridge = p.select(timeouts).select(fridge_reading_r).forward(fridge)
-        .map(|_| () );
+    // forward all the different types of messages to the fridge
+    let all_fridge = param_stream.select(timeouts).select(fridge_reading_r).forward(fridge) .map(|_| () );
 
+    let all_readings = sensor_stream.for_each(|_| Ok(()));
+
+    // run forever
     let all = all_fridge.select(all_readings);
-
     core.run(all).ok();
 }