A platform-agnostic driver crate for the Microchip PAC194X single/multi channel power monitor using the embedded-hal traits.
This driver allows you to:
- Read/Write every available register as a Rust data structure, allowing you to configure alerts, averaging, etc.
- Read the bus and sense voltages directly as f32
s
To use this driver, import this crate and an embedded_hal
implementation,
then instantiate the appropriate device.
```rust use linuxembeddedhal::I2cdev; use pac194x::{PAC194X, AddrSelect};
const SENSE_RESISTOR: f32 = 0.5;
fn main() { let i2c = I2cdev::new("/dev/i2c-1").unwrap(); let mut sensor = PAC194X::new(i2c, AddrSelect::GND).unwrap(); loop { let busvoltage1 = sensor.readbusvoltagen(1).unwrap(); let sensevoltage1 = sensor.readsensevoltagen(1).unwrap(); println!("Channel 1 has a bus voltage of: {:.2} V", busvoltage1); println!("Channel 1 is pulling a current of: {:.2} A", sensevoltage1 / SENSE_RESISTOR); } } ```
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.