56 lines
2.0 KiB
Rust
56 lines
2.0 KiB
Rust
use core::cell::UnsafeCell;
|
|
use core::include_bytes;
|
|
use core::mem::MaybeUninit;
|
|
|
|
use critical_section::Mutex;
|
|
use embedded_graphics::pixelcolor::Rgb565;
|
|
use tinybmp::Bmp;
|
|
|
|
pub type StaticImage = Mutex<UnsafeCell<MaybeUninit<Bmp<'static, Rgb565>>>>;
|
|
|
|
#[rustfmt::skip]
|
|
pub static HUMIDITY_ICON: StaticImage = Mutex::new(UnsafeCell::new(MaybeUninit::zeroed()));
|
|
pub static TEMPERATURE_ICON: StaticImage = Mutex::new(UnsafeCell::new(MaybeUninit::zeroed()));
|
|
pub static VOC_ICON: StaticImage = Mutex::new(UnsafeCell::new(MaybeUninit::zeroed()));
|
|
pub static CO2_ICON: StaticImage = Mutex::new(UnsafeCell::new(MaybeUninit::zeroed()));
|
|
|
|
// Tendency indicators
|
|
pub static TENDENCY_RISING: StaticImage = Mutex::new(UnsafeCell::new(MaybeUninit::zeroed()));
|
|
pub static TENDENCY_STEADY: StaticImage = Mutex::new(UnsafeCell::new(MaybeUninit::zeroed()));
|
|
pub static TENDENCY_FALLING: StaticImage = Mutex::new(UnsafeCell::new(MaybeUninit::zeroed()));
|
|
|
|
macro_rules! load_image {
|
|
($stat:expr, $path:expr) => {
|
|
critical_section::with(|cs| {
|
|
*$stat.borrow(cs).get() =
|
|
MaybeUninit::new(Bmp::from_slice(include_bytes!($path)).unwrap());
|
|
})
|
|
};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! get_image {
|
|
($image:expr) => {
|
|
unsafe {
|
|
use core::mem::MaybeUninit;
|
|
use tinybmp::Bmp;
|
|
&*core::mem::transmute::<*mut MaybeUninit<Bmp<Rgb565>>, *mut Bmp<Rgb565>>(
|
|
critical_section::with(|cs| $image.borrow(cs).get()),
|
|
)
|
|
}
|
|
};
|
|
}
|
|
|
|
pub fn prepare_images() {
|
|
unsafe {
|
|
load_image!(HUMIDITY_ICON, "../../assets/humidity-icon.bmp");
|
|
load_image!(TEMPERATURE_ICON, "../../assets/temperature-icon.bmp");
|
|
load_image!(VOC_ICON, "../../assets/voc-icon.bmp");
|
|
load_image!(CO2_ICON, "../../assets/co2-icon.bmp");
|
|
|
|
load_image!(TENDENCY_RISING, "../../assets/indic-rising.bmp");
|
|
load_image!(TENDENCY_STEADY, "../../assets/indic-steady.bmp");
|
|
load_image!(TENDENCY_FALLING, "../../assets/indic-falling.bmp");
|
|
}
|
|
}
|