Configure i2c device and shunt resistor
This commit is contained in:
10
src/lib.rs
10
src/lib.rs
@@ -17,11 +17,11 @@ pub struct Ina3221 {
|
||||
|
||||
impl Ina3221 {
|
||||
|
||||
pub fn new(slave_address: u16) -> Ina3221 {
|
||||
pub fn new(slave_address: u16, i2c_device: &str, shunt_resistor: f64) -> Ina3221 {
|
||||
Ina3221 {
|
||||
slave_addr: slave_address,
|
||||
i2c_device: format!("/dev/i2c-1"),
|
||||
shunt_resistor: 1.0,
|
||||
i2c_device: format!("{}", i2c_device),
|
||||
shunt_resistor,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ impl Ina3221 {
|
||||
|
||||
pub fn current(&mut self, channel: Channel) -> Result<f64, LinuxI2CError> {
|
||||
let tmp: f64 = self.shunt_voltage(channel)?;
|
||||
let res: f64 = tmp * self.shunt_resistor;
|
||||
let res: f64 = tmp / self.shunt_resistor * 100.0; // No idea why multiplying with 100 but the result seems to be correct...
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user