Mercurial > templog
comparison 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 |
comparison
equal
deleted
inserted
replaced
619:aecd0a15133c | 620:8fda564cc46f |
---|---|
42 let handle = core.handle(); | 42 let handle = core.handle(); |
43 | 43 |
44 let params = params::Params::load(&config); | 44 let params = params::Params::load(&config); |
45 let mut fridge = fridge::Fridge::new(&config, nowait, params, &handle); | 45 let mut fridge = fridge::Fridge::new(&config, nowait, params, &handle); |
46 | 46 |
47 let (fridge_reading_s, fridge_reading_r) = mpsc::channel(1); | |
48 let fridge_reading_r = fridge_reading_r.map_err(|e| TemplogError::new("Problem with fridge_reading_r channel")); | |
49 | |
50 let sensor_stream = if testmode { | 47 let sensor_stream = if testmode { |
51 sensor::TestSensor::new(config).stream(&handle) | 48 sensor::TestSensor::new(config).stream(&handle) |
52 } else { | 49 } else { |
53 sensor::OneWireSensor::new(config).stream(&handle) | 50 sensor::OneWireSensor::new(config).stream(&handle) |
54 }; | 51 }; |
55 | 52 |
56 // Send the sensors of interest to the fridge (fridge_reading_s), | 53 // Send the sensors of interest to the fridge (fridge_reading_s), |
57 // while streaming them all to the web sender. | 54 // while streaming them all to the web sender. |
58 let s = sensor_stream.map(|r| { | 55 let (fridge_reading_s, fridge_reading_r) = mpsc::channel(1); |
56 let fridge_reading_r = fridge_reading_r.map_err(|e| TemplogError::new("Problem with fridge_reading_r channel")); | |
57 let sensor_stream = sensor_stream.map(|r| { | |
59 debug!("sensors {:?}", r); | 58 debug!("sensors {:?}", r); |
60 let msg = fridge::Message::Sensor { | 59 let msg = fridge::Message::Sensor { |
61 wort: r.get_temp(&config.WORT_NAME), | 60 wort: r.get_temp(&config.WORT_NAME), |
62 fridge: r.get_temp(&config.FRIDGE_NAME) | 61 fridge: r.get_temp(&config.FRIDGE_NAME) |
63 }; | 62 }; |
70 handle.spawn(t); | 69 handle.spawn(t); |
71 r | 70 r |
72 }); | 71 }); |
73 | 72 |
74 let param_stream = params::ParamWaiter::stream(config, &handle); | 73 let param_stream = params::ParamWaiter::stream(config, &handle); |
75 let p = param_stream.map(|p| { | 74 let param_stream = param_stream.map(|p| { |
76 fridge::Message::Params(p) | 75 fridge::Message::Params(p) |
77 }); | 76 }); |
78 | 77 |
79 let timeouts = fridge.wakeups(); | 78 let timeouts = fridge.wakeups(); |
80 | 79 |
81 let all_readings = s.for_each(|_| Ok(())); | 80 // forward all the different types of messages to the fridge |
82 let all_fridge = p.select(timeouts).select(fridge_reading_r).forward(fridge) | 81 let all_fridge = param_stream.select(timeouts).select(fridge_reading_r).forward(fridge) .map(|_| () ); |
83 .map(|_| () ); | |
84 | 82 |
83 let all_readings = sensor_stream.for_each(|_| Ok(())); | |
84 | |
85 // run forever | |
85 let all = all_fridge.select(all_readings); | 86 let all = all_fridge.select(all_readings); |
86 | |
87 core.run(all).ok(); | 87 core.run(all).ok(); |
88 } | 88 } |
89 | 89 |
90 const USAGE: &'static str = "\ | 90 const USAGE: &'static str = "\ |
91 Wort Temperature | 91 Wort Temperature |