Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kiranshila/pac194x
Platform-agnostic Rust driver for the PAC194x 9V, 16-bit power monitor with alerts
https://github.com/kiranshila/pac194x
driver embedded-hal embedded-hal-driver i2c power power-monitor power-monitoring rust rust-embedded
Last synced: 23 days ago
JSON representation
Platform-agnostic Rust driver for the PAC194x 9V, 16-bit power monitor with alerts
- Host: GitHub
- URL: https://github.com/kiranshila/pac194x
- Owner: kiranshila
- License: apache-2.0
- Created: 2022-03-25T22:19:36.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-04-11T00:15:35.000Z (over 2 years ago)
- Last Synced: 2024-10-15T15:23:28.456Z (about 1 month ago)
- Topics: driver, embedded-hal, embedded-hal-driver, i2c, power, power-monitor, power-monitoring, rust, rust-embedded
- Language: Rust
- Homepage:
- Size: 74.2 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Rust PAC194X Power Monitor Driver
A platform-agnostic driver crate for the Microchip [PAC194X](https://ww1.microchip.com/downloads/en/DeviceDoc/PAC194X-Data-Sheet-20006543.pdf) single/multi channel power monitor using the embedded-hal traits.
[![Build Status](https://github.com/kiranshila/pac194x/workflows/Main/badge.svg)](https://github.com/kiranshila/pac194x/actions)
[![Docs.rs](https://docs.rs/pac194x/badge.svg)](https://docs.rs/pac194x)
[![Crates.io](https://img.shields.io/crates/v/pac194x)](https://crates.io/crates/pac194x)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## Usage
To use this driver, import this crate and an `embedded_hal` implementation,
then instantiate the appropriate device.```rust
use linux_embedded_hal::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 bus_voltage_1 = sensor.read_bus_voltage_n(1).unwrap();
let sense_voltage_1 = sensor.read_sense_voltage_n(1).unwrap();
println!("Channel 1 has a bus voltage of: {:.2} V", bus_voltage_1);
println!("Channel 1 is pulling a current of: {:.2} A", sense_voltage_1 / SENSE_RESISTOR);
}
}
```## Discussion
I wrote a blog post about the development of this crate [here](https://blog.kiranshila.com/blog/pac_rust_driver.md)
## License
Licensed under either of* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
http://opensource.org/licenses/MIT)at your option.
### Contributing
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.