extern crate kawaii;

use std::time::Duration;

use kawaii::gpio::{SyncPort, AsyncPort, Direction, Edge, Value};

#[cfg(feature = "measure")]
use kawaii::measure::Measure;

fn main() {
    println!("Hello, world!");

    #[cfg(feature = "measure")]
    {
        let mut measure = Measure::new(String::from("main({test: 1})"));

        for _ in 0..5 {
            measure.start();
            std::thread::sleep(Duration::new(0, 1_000_000));
            measure.stop();
        }

        println!("{:?}", measure);
    }

    let mut trigger = SyncPort::new(27, Direction::Out).expect("Create Trigger GPIO failed");
    let mut echo = AsyncPort::new(28, Edge::Both).expect("Create Echo GPIO failed");

    println!("trigger = {:?}", trigger.read());
    trigger.write(Value::High).expect("write failed");
    println!("trigger = {:?}", trigger.read());
    trigger.write(Value::Low).expect("write failed");
    println!("trigger = {:?}", trigger.read());
    println!("echo = {:?}", echo.poll(Some(Duration::new(1, 0))));
}
