use std::error::Error;
use std::time::Duration;
use std::thread::sleep;
use brewdrivers::controllers::Waveshare;
use brewdrivers::state::BinaryState;
fn main() -> Result<(), Box<dyn Error>> {
let mut ws = Waveshare::connect(0x01, "/dev/ttyUSB0", 9600, Duration::from_millis(100))?;
println!("Board software revision: {:?}", ws.software_revision());
ws.set_relay(0, BinaryState::On)?;
ws.set_relay(2, BinaryState::On)?;
let statuses = ws.get_all_relays()?;
for i in 0..8 {
println!("Relay {}: {}", i, statuses[i]);
}
sleep(Duration::from_millis(100));
ws.set_all_relays(BinaryState::Off)?;
println!("{:X?}", ws.get_address());
println!("Setting the address to 0x07...");
ws.set_address(0x07)?;
println!("Address is now 0x{:02X?}", ws.get_address()?);
println!("Now setting it back to 0x01");
ws.set_address(0x01)?;
Ok(())
}