Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
jackra1n committed May 18, 2024
1 parent c64e181 commit 5b1e4c1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/fan_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use anyhow::{anyhow, Result};
use log::debug;


const I2C_BUS_PATH: &str = "/dev/i2c-1";

pub struct FanController {
expander: Pcf8574<I2cdev>,
pub is_running: bool,
Expand All @@ -20,8 +22,8 @@ impl FanController {
if temp_on <= temp_off {
return Err(anyhow!("temp_on must be greater than temp_off"));
}

let i2c = I2cdev::new("/dev/i2c-1")?;
let i2c = I2cdev::new(I2C_BUS_PATH)?;
debug!("I2C device initialized");
let expander = Pcf8574::new(i2c, SlaveAddr::default());
debug!("pcf8574 IO Expander initialized");
Expand All @@ -35,7 +37,7 @@ impl FanController {
}

pub fn fan_on(&mut self) -> Result<(), Box<dyn std::error::Error>> {
debug!("Sending fan on signal [p0: low");
debug!("Sending fan on signal [p0: low]");
let mut parts = self.expander.split();
parts.p0.set_low().unwrap();
self.is_running = true;
Expand Down

0 comments on commit 5b1e4c1

Please sign in to comment.