Skip to content

Preliminary thermistor abstraction implementation #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 14, 2024
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 pod-operation/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
# target = "aarch64-unknown-linux-gnu"

[target.aarch64-unknown-linux-gnu]
# linker = "aarch64-linux-gnu-gcc"
# linker = "aarch64-unknown-linux-gnu-gcc"
# linker = "aarch64-none-linux-gnu-gcc"
12 changes: 12 additions & 0 deletions pod-operation/Cargo.lock

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

2 changes: 2 additions & 0 deletions pod-operation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ lazy_static = "1.4.0"
rppal = { version = "0.17.1", features = ["hal"] }
ina219 = "0.1.0"
enum-map = "2.7.3"
ads1x1x = "0.2.2"
nb = "1.1.0"
29 changes: 29 additions & 0 deletions pod-operation/src/components/lim_temperature.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use ads1x1x::ic::{Ads1015, Resolution12Bit};
use ads1x1x::interface::I2cInterface;
use ads1x1x::mode::OneShot;
use ads1x1x::ChannelSelection::{SingleA0, SingleA1, SingleA2, SingleA3};
use ads1x1x::{Ads1x1x, DynamicOneShot, SlaveAddr};
use nb::block;
use rppal::i2c::I2c;

pub struct LimTemperature {
ads1015: Ads1x1x<I2cInterface<I2c>, Ads1015, Resolution12Bit, OneShot>,
}

impl LimTemperature {
pub fn new(device_address: SlaveAddr) -> Self {
let i2cdev = I2c::new().unwrap();
let adc = Ads1x1x::new_ads1015(i2cdev, device_address);
LimTemperature { ads1015: adc }
}

pub fn cleanup(self) {
self.ads1015.destroy_ads1015();
}

pub fn read_pins(&mut self) -> (i16, i16, i16, i16) {
[SingleA0, SingleA1, SingleA2, SingleA3]
.map(|channel| block!(self.ads1015.read(channel)).unwrap())
.into()
}
}
1 change: 1 addition & 0 deletions pod-operation/src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod lim_temperature;
pub mod pressure_transducer;
pub mod signal_light;
17 changes: 17 additions & 0 deletions pod-operation/src/demo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use tracing::info;

use crate::components::lim_temperature::LimTemperature;
use crate::components::pressure_transducer::PressureTransducer;
use crate::components::signal_light::SignalLight;

Expand Down Expand Up @@ -27,3 +28,19 @@ pub async fn read_pressure_transducer(mut pressure_transducer: PressureTransduce
println!("{:?}", pressure_transducer.read());
}
}

pub async fn read_ads1015(mut lim_temperature: LimTemperature) {
info!("Starting ADS1015 Demo.");

let mut i = 0;
loop {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
println!("{:?}", lim_temperature.read_pins());
i += 1;
if i > 1000 {
break;
}
}

lim_temperature.cleanup();
}
4 changes: 4 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 state_machine;

use crate::components::lim_temperature::LimTemperature;
use crate::components::pressure_transducer::PressureTransducer;
use crate::components::signal_light::SignalLight;
use crate::state_machine::StateMachine;
Expand All @@ -23,6 +24,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let pressure_transducer = PressureTransducer::new(0x40);
tokio::spawn(demo::read_pressure_transducer(pressure_transducer));

let ads1015 = LimTemperature::new(ads1x1x::SlaveAddr::Default);
tokio::spawn(demo::read_ads1015(ads1015));

tokio::spawn(async {
let mut state_machine = StateMachine::new(io);
state_machine.run().await;
Expand Down