use rppal::i2c::I2c;
use std::{error::Error, thread, time::Duration};

mod adt7410;
mod mcp3208;

fn main() -> Result<(), Box<dyn Error>> {
    let i2c_bus = I2c::new()?;

    let mut adt7410_dev = adt7410::ADT7410::new(i2c_bus);
    let mcp3208_dev = mcp3208::MCP3208::new()?;

    loop {
        if let Some(temp) = adt7410_dev.celcius() {
            println!("気温: {temp} 度");
        }

        if let Some(brightness) = mcp3208_dev.brightness() {
            println!("明るさ: {brightness}");
        }

        // 1秒スリープ
        thread::sleep(Duration::from_secs(1));
    }
}
