view rust/src/main.rs @ 592:03b48ec0bb03 rust

fridge, types, configwaiter
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Dec 2016 00:14:58 +0800
parents 4a944663fa8d
children bf138339d20a
line wrap: on
line source

extern crate tokio_core;
extern crate futures;
extern crate rustc_serialize;

use tokio_core::reactor::Core;
use futures::{Future,Stream};
use rustc_serialize::json;

mod sensor;
mod fridge;
mod types;
mod configwaiter;

use types::*;

fn main() {
    println!("Wort Templog");

    let paramh = ParamHolder::new();
    let mut readings = Readings::new();
    let mut fridge = fridge::Fridge::new(&paramh.p);

    let mut core = Core::new().unwrap();
    let handle = core.handle();

    let s = sensor::Sensor::run(&handle, 400, "sens1".to_string());
    let t = sensor::Sensor::run(&handle, 747, "frid".to_string());
    let w = configwaiter::ConfigWaiter::run(&handle, 3000);

    let h = s.for_each(|r| {
        fridge.set_params(&paramh.p);
        println!("readings {:?}", r);
        Ok(())
    });

    let i = t.for_each(|r| {
        println!("fridgereadings {:?}", r);
        Ok(())
    });

    let j = w.for_each(move |ph| {
        let paramh = ph;
        fridge.set_params(&ph.p);
        Ok(())
    });

    let all = h.select(j);

    core.run(all);
}