Increase upper threshold and add lower threshold with yellow light

main
trivernis 2 years ago
parent 4bb2919c0c
commit 53f4ba9a6b
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: DFFFCC2C7A02DB45

@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"

@ -1,5 +1,6 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
#![feature(exclusive_range_pattern)]
use embedded_alloc::Heap; use embedded_alloc::Heap;
use panic_halt as _; use panic_halt as _;
@ -43,13 +44,14 @@ const HEAP_SIZE: usize = 1024;
const XTAL_FREQ_HZ: u32 = 12_000_000u32; const XTAL_FREQ_HZ: u32 = 12_000_000u32;
const MVG_AVG_COUNT: u16 = 20; const MVG_AVG_COUNT: u16 = 20;
const DISPLAY_UPDATE_INT_TICKS: u32 = 500_000;
const SENSOR_READ_INT_TICKS: u32 = 50_000;
const AIR_QUALITY_THRESHOLD: u16 = 480;
const AIR_QUALITY_THRESHOLD_LOWER: u16 = 400;
#[rtic::app(device = hal::pac, peripherals = true)] #[rtic::app(device = hal::pac, peripherals = true)]
mod app { mod app {
const DISPLAY_UPDATE_INT_TICKS: u32 = 500_000;
const SENSOR_READ_INT_TICKS: u32 = 50_000;
use super::*; use super::*;
type DisplayI2C = hal::I2C< type DisplayI2C = hal::I2C<
I2C1, I2C1,
@ -80,6 +82,7 @@ mod app {
adc: Adc, adc: Adc,
adc_pin: Pin<hal::gpio::bank0::Gpio29, hal::gpio::FloatingInput>, adc_pin: Pin<hal::gpio::bank0::Gpio29, hal::gpio::FloatingInput>,
watchdog: hal::Watchdog, watchdog: hal::Watchdog,
use_lower_limit: bool,
} }
#[init()] #[init()]
@ -157,6 +160,7 @@ mod app {
adc, adc,
adc_pin, adc_pin,
watchdog, watchdog,
use_lower_limit: false,
}, },
init::Monotonics(), init::Monotonics(),
) )
@ -210,16 +214,27 @@ mod app {
}); });
} }
#[task(binds = TIMER_IRQ_1, priority = 2, shared = [alarm1, sensor_value, led], local = [adc, adc_pin, watchdog])] #[task(binds = TIMER_IRQ_1, priority = 2, shared = [alarm1, sensor_value, led], local = [adc, adc_pin, watchdog, use_lower_limit])]
fn read_sensor(mut c: read_sensor::Context) { fn read_sensor(mut c: read_sensor::Context) {
let mut sensor_value: u16 = c.local.adc.read(c.local.adc_pin).unwrap(); let mut sensor_value: u16 = c.local.adc.read(c.local.adc_pin).unwrap();
sensor_value = c.shared.sensor_value.lock(|v| { sensor_value = c.shared.sensor_value.lock(|v| {
*v = (*v * (MVG_AVG_COUNT - 1) + sensor_value) / MVG_AVG_COUNT; *v = (*v * (MVG_AVG_COUNT - 1) + sensor_value) / MVG_AVG_COUNT;
*v *v
}); });
if sensor_value >= AIR_QUALITY_THRESHOLD {
*c.local.use_lower_limit = true;
} else if sensor_value < AIR_QUALITY_THRESHOLD_LOWER && *c.local.use_lower_limit {
*c.local.use_lower_limit = false;
}
let color = match sensor_value { let color = match sensor_value {
0..=450 => RGB8::new(255, 0, 0), 0..AIR_QUALITY_THRESHOLD_LOWER => RGB8::new(255, 0, 0),
451.. => RGB8::new(0, 255, 0), AIR_QUALITY_THRESHOLD_LOWER..AIR_QUALITY_THRESHOLD if *c.local.use_lower_limit => {
RGB8::new(200, 255, 0)
}
AIR_QUALITY_THRESHOLD_LOWER..AIR_QUALITY_THRESHOLD => RGB8::new(255, 0, 0),
AIR_QUALITY_THRESHOLD.. => RGB8::new(0, 255, 0),
}; };
c.shared.led.lock(|l| { c.shared.led.lock(|l| {

Loading…
Cancel
Save