cleans up lifetimes and ownership
This commit is contained in:
@@ -5,6 +5,7 @@ use crate::logger::setup_logger;
|
||||
use anyhow::Result;
|
||||
use log::info;
|
||||
use crate::hardware::Hardware;
|
||||
use crate::hardware::mcp23017::Mcp23017;
|
||||
|
||||
mod hardware;
|
||||
mod logger;
|
||||
@@ -18,14 +19,36 @@ pub fn run() -> Result<()> {
|
||||
|
||||
let hal = initialize()?;
|
||||
|
||||
for i in 0..100 {
|
||||
sleep(Duration::from_millis(1000));
|
||||
info!("Battery Voltage: {}", hal.get_battery_voltage()?);
|
||||
}
|
||||
let mut mcp23017_a = hal.get_mcp23017_a();
|
||||
let mut mcp23017_b = hal.get_mcp23017_b();
|
||||
|
||||
// hal.set_mcp0_pin(15u8, true)?;
|
||||
// sleep(Duration::from_secs(1));
|
||||
// hal.set_mcp0_pin(15u8, false)?;
|
||||
info!("Battery Voltage: {}", hal.get_battery_voltage()?);
|
||||
|
||||
mcp23017_a.init()?;
|
||||
mcp23017_b.init()?;
|
||||
|
||||
mcp23017_a.set_pin(7u8, true)?;
|
||||
mcp23017_a.flush()?;
|
||||
|
||||
sleep(Duration::from_secs(1));
|
||||
|
||||
mcp23017_b.set_pin(7u8, true)?;
|
||||
mcp23017_b.flush()?;
|
||||
|
||||
sleep(Duration::from_secs(1));
|
||||
|
||||
mcp23017_a.set_pin(7u8, false)?;
|
||||
mcp23017_a.flush()?;
|
||||
|
||||
sleep(Duration::from_secs(1));
|
||||
|
||||
mcp23017_b.set_pin(7u8, false)?;
|
||||
mcp23017_b.flush()?;
|
||||
|
||||
// Explicitly drop these to allow the borrow checker to be sure that
|
||||
// dropping the hal is safe
|
||||
drop(mcp23017_a);
|
||||
drop(mcp23017_b);
|
||||
|
||||
drop(hal);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user