Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: CI Build

on:
push:
pull_request:

env:
CARGO_TERM_COLOR: always
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pastey = "0.2"

# For the example
[dev-dependencies]
embedded-hal-bus = "0.3.0"
linux-embedded-hal = "0.4.1"

[dependencies.packed_struct]
Expand Down
52 changes: 52 additions & 0 deletions examples/linux-shared.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use embedded_hal_bus::i2c::RefCellDevice;
use linux_embedded_hal::I2cdev;
use pac194x::{AddrSelect, PAC194X};
use std::cell::RefCell;
use std::{thread, time::Duration};

const SENSE_RESISTORS: [f32; 8] = [0.005, 0.010, 0.010, 0.010, 0.002, 0.010, 0.010, 0.010];

fn main() {
let i2c = RefCell::new(I2cdev::new("/dev/i2c-3").unwrap());

let bus_handle1 = RefCellDevice::new(&i2c);
let mut sensor1 = PAC194X::new(bus_handle1, AddrSelect::GND).unwrap();

let bus_handle2 = RefCellDevice::new(&i2c);
let mut sensor2 = PAC194X::new(bus_handle2, AddrSelect::_499).unwrap();

loop {
print!("Sensor 1 ");
for channel in 1..5 {
let bus_voltage = sensor1.read_bus_voltage_n(channel).unwrap();
let sense_voltage = sensor1.read_sense_voltage_n(channel).unwrap();
print!(
"CH{} {:5.2}V, {:5.2}A, ",
channel,
bus_voltage,
sense_voltage / SENSE_RESISTORS[(channel - 1) as usize]
);
}
println!();
print!("Sensor 2 ");
for channel in 1..5 {
let bus_voltage = sensor2.read_bus_voltage_n(channel).unwrap();
let sense_voltage = sensor2.read_sense_voltage_n(channel).unwrap();
print!(
"CH{} {:5.2}V, {:5.2}A, ",
channel,
bus_voltage,
sense_voltage / SENSE_RESISTORS[(channel - 1 + 4) as usize]
);
}
println!();
println!();
sensor1.refresh().unwrap();
thread::sleep(Duration::from_millis(100));
sensor1.refresh_v().unwrap();
thread::sleep(Duration::from_millis(100));
sensor2.refresh().unwrap();
thread::sleep(Duration::from_millis(100));
sensor2.refresh_v().unwrap();
}
}
7 changes: 4 additions & 3 deletions examples/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use linux_embedded_hal::I2cdev;
use pac194x::{AddrSelect, PAC194X};
use std::{thread, time::Duration};

const SENSE_RESISTOR: f32 = 0.5;
const SENSE_RESISTORS: [f32; 4] = [0.005, 0.010, 0.010, 0.010];

fn main() {
let i2c = I2cdev::new("/dev/i2c-3").unwrap();
Expand All @@ -15,14 +15,15 @@ fn main() {
"CH{} {:.2}V, {:.2}A, ",
channel,
bus_voltage,
sense_voltage / SENSE_RESISTOR
sense_voltage / SENSE_RESISTORS[(channel - 1) as usize]
);
}
println!();
println!();

sensor.refresh().unwrap();
thread::sleep(Duration::from_millis(100));
sensor.refresh_v().unwrap();

thread::sleep(Duration::from_millis(100));
}
}