Prefix sensor module to make it more obv

This commit is contained in:
Frederik Menke 2024-07-21 13:32:13 +02:00
parent 02c8102e35
commit d8ff2b7775
2 changed files with 7 additions and 9 deletions

View file

@ -6,7 +6,7 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
mod co2_sensor; mod co2;
use byteorder::ByteOrder; use byteorder::ByteOrder;
use defmt::*; use defmt::*;
@ -25,8 +25,6 @@ use {defmt_rtt as _, panic_probe as _};
use embassy_rp::i2c::{self, Config}; use embassy_rp::i2c::{self, Config};
use embassy_time::{Duration, Timer}; use embassy_time::{Duration, Timer};
use co2_sensor::{get_measurement, get_status, set_measurement_mode, start_app};
bind_interrupts!(struct Irqs { bind_interrupts!(struct Irqs {
I2C1_IRQ => i2c::InterruptHandler<embassy_rp::peripherals::I2C1>; I2C1_IRQ => i2c::InterruptHandler<embassy_rp::peripherals::I2C1>;
}); });
@ -67,7 +65,7 @@ async fn main(spawner: Spawner) {
// Wait for sensor to boot // Wait for sensor to boot
Timer::after(Duration::from_secs(1)).await; Timer::after(Duration::from_secs(1)).await;
let status = get_status(&mut i2c).await.unwrap(); let status = co2::get_status(&mut i2c).await.unwrap();
info!("CO2 sesor reported status on boot: {}", status); info!("CO2 sesor reported status on boot: {}", status);
@ -75,11 +73,11 @@ async fn main(spawner: Spawner) {
if status & 128u8 == 0 { if status & 128u8 == 0 {
info!("App is not running yet. Booting sensor..."); info!("App is not running yet. Booting sensor...");
// App is not running // App is not running
start_app(&mut i2c).await.unwrap(); co2::start_app(&mut i2c).await.unwrap();
// After APP_START, we have to wait at least 1 ms (according to datasheet) // After APP_START, we have to wait at least 1 ms (according to datasheet)
Timer::after(Duration::from_millis(2)).await; Timer::after(Duration::from_millis(2)).await;
if get_status(&mut i2c).await.unwrap() & 128u8 == 0 { if co2::get_status(&mut i2c).await.unwrap() & 128u8 == 0 {
error!("App still not running after boot! Terminating..."); error!("App still not running after boot! Terminating...");
return; return;
} }
@ -88,11 +86,11 @@ async fn main(spawner: Spawner) {
} }
// 16 is measurement mode 1 => 1 measurement per second // 16 is measurement mode 1 => 1 measurement per second
set_measurement_mode(&mut i2c, 16).await.unwrap(); co2::set_measurement_mode(&mut i2c, 16).await.unwrap();
loop { loop {
let status = get_status(&mut i2c).await.unwrap(); let status = co2::get_status(&mut i2c).await.unwrap();
let measured_value = get_measurement(&mut i2c).await.unwrap(); let measured_value = co2::get_measurement(&mut i2c).await.unwrap();
info!( info!(
"Reported status: {}\tMeasured value: {}", "Reported status: {}\tMeasured value: {}",
status, measured_value status, measured_value