Drawing CO2, temp. & RH to the screen
This commit is contained in:
parent
39a59a2658
commit
d59a15c91b
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -869,6 +869,7 @@ dependencies = [
|
|||||||
"embassy-sync",
|
"embassy-sync",
|
||||||
"embassy-time",
|
"embassy-time",
|
||||||
"embedded-graphics",
|
"embedded-graphics",
|
||||||
|
"heapless",
|
||||||
"rtt-target",
|
"rtt-target",
|
||||||
"scd4x",
|
"scd4x",
|
||||||
"ssd1351",
|
"ssd1351",
|
||||||
|
@ -38,6 +38,9 @@ scd4x = { git = "https://github.com/twokilohertz/scd4x-rs.git", branch = "conver
|
|||||||
ssd1351 = "0.5.0"
|
ssd1351 = "0.5.0"
|
||||||
display-interface-spi = "0.5.0"
|
display-interface-spi = "0.5.0"
|
||||||
|
|
||||||
|
# Extra
|
||||||
|
heapless = "0.8.0"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
opt-level = "s"
|
opt-level = "s"
|
||||||
|
|
||||||
|
@ -13,17 +13,15 @@ use ssd1351::{
|
|||||||
|
|
||||||
// Graphics
|
// Graphics
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
mono_font::{
|
mono_font::{ascii::FONT_6X10, MonoTextStyle},
|
||||||
ascii::{FONT_5X7, FONT_6X10},
|
|
||||||
MonoTextStyle,
|
|
||||||
},
|
|
||||||
pixelcolor::Rgb565,
|
pixelcolor::Rgb565,
|
||||||
prelude::{Dimensions, Point, RgbColor},
|
prelude::{Point, WebColors},
|
||||||
text::{Alignment, Text},
|
text::{Alignment, Text},
|
||||||
Drawable,
|
Drawable,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::Spi0BusMutex;
|
use crate::{Spi0BusMutex, SENSOR_DATA_SIGNAL};
|
||||||
|
use core::fmt::Write;
|
||||||
|
|
||||||
/// Output to the SSD1351 display
|
/// Output to the SSD1351 display
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
@ -48,26 +46,55 @@ pub async fn display_output_task(
|
|||||||
display.reset(rst, &mut embassy_time::Delay).unwrap();
|
display.reset(rst, &mut embassy_time::Delay).unwrap();
|
||||||
display.init().unwrap();
|
display.init().unwrap();
|
||||||
|
|
||||||
let text_style1 = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
|
let co2_text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::CSS_DARK_GREEN);
|
||||||
let text_style2 = MonoTextStyle::new(&FONT_5X7, Rgb565::WHITE);
|
let temp_text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::CSS_ORANGE);
|
||||||
let text1 = "Hello, World!";
|
let humidity_text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::CSS_AQUA);
|
||||||
let text2 = "2khz.xyz";
|
|
||||||
|
|
||||||
Text::with_alignment(
|
let mut co2_text_buf = heapless::String::<16>::new();
|
||||||
text1,
|
let mut temp_text_buf = heapless::String::<16>::new();
|
||||||
display.bounding_box().center() + Point::new(0, -6),
|
let mut humidity_text_buf = heapless::String::<16>::new();
|
||||||
text_style1,
|
|
||||||
Alignment::Center,
|
|
||||||
)
|
|
||||||
.draw(&mut display)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
Text::with_alignment(
|
loop {
|
||||||
text2,
|
// Clear contents of buffers
|
||||||
display.bounding_box().center() + Point::new(0, 6),
|
co2_text_buf.clear();
|
||||||
text_style2,
|
temp_text_buf.clear();
|
||||||
Alignment::Center,
|
humidity_text_buf.clear();
|
||||||
)
|
|
||||||
.draw(&mut display)
|
// Wait on sensor data & format into the buffers
|
||||||
.unwrap();
|
let data = SENSOR_DATA_SIGNAL.wait().await;
|
||||||
|
write!(&mut co2_text_buf, "CO2: {} ppm", data.co2).unwrap();
|
||||||
|
write!(&mut temp_text_buf, "Temp: {:.1} C", data.temperature).unwrap();
|
||||||
|
write!(&mut humidity_text_buf, "RH: {:.1} %", data.humidity).unwrap();
|
||||||
|
|
||||||
|
// Clear the display
|
||||||
|
display.clear();
|
||||||
|
|
||||||
|
// Draw the text to the screen
|
||||||
|
Text::with_alignment(
|
||||||
|
&co2_text_buf,
|
||||||
|
Point::new(1, 12),
|
||||||
|
co2_text_style,
|
||||||
|
Alignment::Left,
|
||||||
|
)
|
||||||
|
.draw(&mut display)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
Text::with_alignment(
|
||||||
|
&temp_text_buf,
|
||||||
|
Point::new(1, 24),
|
||||||
|
temp_text_style,
|
||||||
|
Alignment::Left,
|
||||||
|
)
|
||||||
|
.draw(&mut display)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
Text::with_alignment(
|
||||||
|
&humidity_text_buf,
|
||||||
|
Point::new(1, 36),
|
||||||
|
humidity_text_style,
|
||||||
|
Alignment::Left,
|
||||||
|
)
|
||||||
|
.draw(&mut display)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
15
src/main.rs
15
src/main.rs
@ -16,19 +16,28 @@ use embassy_rp::{
|
|||||||
peripherals::{I2C0, SPI0},
|
peripherals::{I2C0, SPI0},
|
||||||
spi,
|
spi,
|
||||||
};
|
};
|
||||||
use embassy_sync::blocking_mutex::{raw::NoopRawMutex, Mutex};
|
use embassy_sync::{
|
||||||
|
blocking_mutex::{
|
||||||
|
raw::{CriticalSectionRawMutex, NoopRawMutex},
|
||||||
|
Mutex,
|
||||||
|
},
|
||||||
|
signal::Signal,
|
||||||
|
};
|
||||||
use embassy_time::Timer;
|
use embassy_time::Timer;
|
||||||
use static_cell::StaticCell;
|
use static_cell::StaticCell;
|
||||||
|
|
||||||
use display_task::display_output_task;
|
use display_task::display_output_task;
|
||||||
use sensor_task::sensor_read_task;
|
use sensor_task::sensor_read_task;
|
||||||
|
|
||||||
|
type I2c0BusMutex = Mutex<NoopRawMutex, RefCell<i2c::I2c<'static, I2C0, i2c::Blocking>>>;
|
||||||
|
type Spi0BusMutex = Mutex<NoopRawMutex, RefCell<spi::Spi<'static, SPI0, spi::Blocking>>>;
|
||||||
|
|
||||||
embassy_rp::bind_interrupts!(struct Irqs {
|
embassy_rp::bind_interrupts!(struct Irqs {
|
||||||
I2C0_IRQ => embassy_rp::i2c::InterruptHandler<embassy_rp::peripherals::I2C0>;
|
I2C0_IRQ => embassy_rp::i2c::InterruptHandler<embassy_rp::peripherals::I2C0>;
|
||||||
});
|
});
|
||||||
|
|
||||||
type I2c0BusMutex = Mutex<NoopRawMutex, RefCell<i2c::I2c<'static, I2C0, i2c::Blocking>>>;
|
static SENSOR_DATA_SIGNAL: Signal<CriticalSectionRawMutex, scd4x::types::SensorData> =
|
||||||
type Spi0BusMutex = Mutex<NoopRawMutex, RefCell<spi::Spi<'static, SPI0, spi::Blocking>>>;
|
Signal::new();
|
||||||
|
|
||||||
/// Entrypoint
|
/// Entrypoint
|
||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
|
@ -6,7 +6,7 @@ use rtt_target::rprintln;
|
|||||||
// Sensor
|
// Sensor
|
||||||
use scd4x::Scd4x;
|
use scd4x::Scd4x;
|
||||||
|
|
||||||
use crate::I2c0BusMutex;
|
use crate::{I2c0BusMutex, SENSOR_DATA_SIGNAL};
|
||||||
|
|
||||||
/// Read CO2/temp./humidity data from the sensor
|
/// Read CO2/temp./humidity data from the sensor
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
@ -41,6 +41,8 @@ pub async fn sensor_read_task(i2c_bus: &'static I2c0BusMutex) {
|
|||||||
data.temperature,
|
data.temperature,
|
||||||
data.humidity
|
data.humidity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
SENSOR_DATA_SIGNAL.signal(data);
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
rprintln!(
|
rprintln!(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user