Skip to content

Commit

Permalink
Add preliminary function to read from INA219
Browse files Browse the repository at this point in the history
  • Loading branch information
samderanova committed Apr 8, 2024
1 parent bb1b221 commit b1102c1
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 12 deletions.
161 changes: 150 additions & 11 deletions pod-operation/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pod-operation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ serde = { version = "1.0.192", features = ["derive"] }
serde_json = "1.0.108"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
rppal = "0.17.1"
rppal = { version = "0.17.1", features = ["hal"] }
ina219 = "0.1.0"
18 changes: 18 additions & 0 deletions pod-operation/src/components/ina219.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use ina219::{INA219, INA219_ADDR};
use rppal::i2c::I2c;
use tracing::debug;

pub async fn read_current() {
let device = I2c::new().unwrap();
let mut ina = INA219::new(device, INA219_ADDR);
debug!("Initialized I2C and INA219");

ina.calibrate(0x0100).unwrap();
debug!("Calibrating INA219");

loop {
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
let current = ina.current().unwrap();
println!("current: {:?}", current);
}
}
1 change: 1 addition & 0 deletions pod-operation/src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod ina219;
pub mod signal_light;
3 changes: 3 additions & 0 deletions pod-operation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod components;
mod demo;
mod handlers;

use crate::components::ina219::read_current;
use crate::components::signal_light::SignalLight;

#[tokio::main]
Expand All @@ -23,6 +24,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let signal_light = SignalLight::new();
tokio::spawn(demo::blink(signal_light));

tokio::spawn(read_current());

let app = axum::Router::new().layer(layer);

info!("Starting server on port 5000");
Expand Down

0 comments on commit b1102c1

Please sign in to comment.