forked from kiranshila/pac194x
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinux.rs
More file actions
28 lines (25 loc) · 811 Bytes
/
linux.rs
File metadata and controls
28 lines (25 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use linux_embedded_hal::I2cdev;
use pac194x::{AddrSelect, PAC194X};
use std::{thread, time::Duration};
const SENSE_RESISTOR: f32 = 0.5;
fn main() {
let i2c = I2cdev::new("/dev/i2c-3").unwrap();
let mut sensor = PAC194X::new(i2c, AddrSelect::GND);
loop {
for channel in 1..5 {
let bus_voltage = sensor.read_bus_voltage_n(channel).unwrap();
let sense_voltage = sensor.read_sense_voltage_n(channel).unwrap();
print!(
"CH{} {:.2}V, {:.2}A, ",
channel,
bus_voltage,
sense_voltage / SENSE_RESISTOR
);
}
println!();
println!();
sensor.refresh().unwrap();
sensor.refresh_v().unwrap();
thread::sleep(Duration::from_millis(100));
}
}