use std::error::Error;
use std::thread;
use std::time::Duration;

use rppal::i2c::I2c;

const ADDR_ADS7830: u16 = 0x48;

const CMD_A0: u8 = 0x84;

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

    i2c.set_slave_address(ADDR_ADS7830)?;

    let mut data = [0u8; 1];
    loop {
        i2c.block_read(CMD_A0, &mut data)?;
        println!("{:.2}V", data[0] as f32 / 255.0 * 3.3);

        thread::sleep(Duration::from_secs(1));
    }
}
