view rust/src/main.rs @ 591:4a944663fa8d rust

more skeleton
author Matt Johnston <matt@ucc.asn.au>
date Fri, 23 Dec 2016 00:33:19 +0800
parents dccd8504aa38
children 03b48ec0bb03
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;

#[derive(RustcDecodable, RustcEncodable)]
struct Params {
    fridge_setpoint: f32,
    fridge_difference: f32,
    overshoot_delay: u32,
    overshoot_factor: f32,
    disabled: bool,
    nowort: bool,
    fridge_range_lower: f32,
    fridge_range_upper: f32,
}

struct ParamHolder {
    p: Params,
    epoch: String, // XXX or a byte array?
}

impl ParamHolder {
    fn new() -> ParamHolder {
        ParamHolder {
            p: Params {
                fridge_setpoint: 16.0,
                fridge_difference: 0.2,
                overshoot_delay: 720, // 12 minutes
                overshoot_factor: 1.0,
                disabled: false,
                nowort: false,
                fridge_range_lower: 3.0,
                fridge_range_upper: 3.0,
            },
            epoch: String::new(),
        }
    }
}

struct Readings {
    temps: Vec<Vec<sensor::Reading>>,
}

impl Readings {
    fn new() -> Readings {
        Readings {
            temps: Vec::new(),
        }
    }
    fn fridge() -> Option<f32> {
        unimplemented!();
    }

    fn wort() -> Option<f32> {
        unimplemented!();
    }
}

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

    let param = ParamHolder::new();
    let mut readings = Readings::new();

    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 h = s.for_each(|r| {
        println!("readings {:?}", r);
        Ok(())
    });

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

    let all = h.select(i);

    core.run(all);
}