comparison rust/src/sensor.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 aff50ee77252
comparison
equal deleted inserted replaced
591:4a944663fa8d 592:03b48ec0bb03
5 use std::io; 5 use std::io;
6 6
7 use tokio_core::reactor::Interval; 7 use tokio_core::reactor::Interval;
8 use tokio_core::reactor::Handle; 8 use tokio_core::reactor::Handle;
9 use futures::Stream; 9 use futures::Stream;
10 10 use types::*;
11 #[derive(Debug)]
12 pub struct Reading {
13 name: String,
14 value: Option<f32>,
15 }
16 11
17 pub struct Sensor { 12 pub struct Sensor {
18 current: f32, 13 current: f32,
19 suf: String, 14 suf: String,
20 } 15 }
21 16
22 impl Sensor { 17 impl Sensor {
23 fn step(&mut self) -> Vec<Reading> { 18 fn step(&mut self) -> Vec<Reading> {
24 let mut r = Vec::new(); 19 let mut r = Vec::new();
25 self.current = self.current + 0.1; 20 self.current = self.current + 0.1;
26 r.push(Reading { name: "aaa".to_string() + &self.suf, value: Some(self.current) }); 21 r.push(Reading::new("aaa".to_string() + &self.suf, self.current));
27 r.push(Reading { name: "b".to_string() + &self.suf, value: Some(self.current/3.0) }); 22 r.push(Reading::new("b".to_string() + &self.suf, self.current/3.0));
28 r 23 r
29 } 24 }
30 25
31 fn new(suffix: String) -> Self { 26 fn new(suffix: String) -> Self {
32 Sensor { current: 22.0, suf: suffix } 27 Sensor { current: 22.0, suf: suffix }