📟 pmme-device: Move oled_task function down
This commit is contained in:
parent
d87215bebd
commit
385988401c
@ -46,35 +46,6 @@ pub struct Pms7003Data {
|
||||
pub particles_10um: u16,
|
||||
}
|
||||
|
||||
fn oled_task(pm_data: Arc<Mutex<Pms7003Data>>, i2c: I2cDriver) -> Result<()> {
|
||||
info!("Staring OLED Task");
|
||||
|
||||
let interface = I2CDisplayInterface::new(i2c);
|
||||
let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
|
||||
.into_buffered_graphics_mode();
|
||||
|
||||
display.init().unwrap();
|
||||
|
||||
let raw: ImageRaw<BinaryColor> = ImageRaw::new(include_bytes!("../rust.raw"), 64);
|
||||
let im = Image::new(&raw, Point::new(32, 0));
|
||||
|
||||
im.draw(&mut display).unwrap();
|
||||
display.flush().map_err(|e| anyhow!("Could not flush display! {:?}", e))?;
|
||||
|
||||
FreeRtos::delay_ms(2000);
|
||||
loop {
|
||||
let current_pm_data = pm_data.lock().unwrap().clone();
|
||||
display.clear(BinaryColor::Off).map_err(|e| anyhow!("Could not clear display! {:?}", e))?;
|
||||
Text::new(
|
||||
&format!("PM 2.5: {}", current_pm_data.pm2_5_atm),
|
||||
Point::new(20, 40),
|
||||
MonoTextStyle::new(&FONT_10X20, BinaryColor::On),
|
||||
).draw(&mut display).map_err(|e| anyhow!("Could not draw text! {:?}", e))?;
|
||||
display.flush().map_err(|e| anyhow!("Could not flush display! {:?}", e))?;
|
||||
FreeRtos::delay_ms(500);
|
||||
}
|
||||
}
|
||||
|
||||
// u16::from_be_bytes is too verbose
|
||||
fn get_u16(buf: &[u8]) -> u16 { ((buf[0] as u16) << 8) | buf[1] as u16 }
|
||||
|
||||
@ -138,6 +109,35 @@ fn pm_sensor_task(pm_data: Arc<Mutex<Pms7003Data>>, uart: &UartDriver) -> Result
|
||||
}
|
||||
}
|
||||
|
||||
fn oled_task(pm_data: Arc<Mutex<Pms7003Data>>, i2c: I2cDriver) -> Result<()> {
|
||||
info!("Staring OLED Task");
|
||||
|
||||
let interface = I2CDisplayInterface::new(i2c);
|
||||
let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
|
||||
.into_buffered_graphics_mode();
|
||||
|
||||
display.init().unwrap();
|
||||
|
||||
let raw: ImageRaw<BinaryColor> = ImageRaw::new(include_bytes!("../rust.raw"), 64);
|
||||
let im = Image::new(&raw, Point::new(32, 0));
|
||||
|
||||
im.draw(&mut display).unwrap();
|
||||
display.flush().map_err(|e| anyhow!("Could not flush display! {:?}", e))?;
|
||||
|
||||
FreeRtos::delay_ms(2000);
|
||||
loop {
|
||||
let current_pm_data = pm_data.lock().unwrap().clone();
|
||||
display.clear(BinaryColor::Off).map_err(|e| anyhow!("Could not clear display! {:?}", e))?;
|
||||
Text::new(
|
||||
&format!("PM 2.5: {}", current_pm_data.pm2_5_atm),
|
||||
Point::new(20, 40),
|
||||
MonoTextStyle::new(&FONT_10X20, BinaryColor::On),
|
||||
).draw(&mut display).map_err(|e| anyhow!("Could not draw text! {:?}", e))?;
|
||||
display.flush().map_err(|e| anyhow!("Could not flush display! {:?}", e))?;
|
||||
FreeRtos::delay_ms(500);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// It is necessary to call this function once. Otherwise some patches to the runtime
|
||||
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
|
||||
|
Loading…
x
Reference in New Issue
Block a user