A personal rust firmware for the Badger 2040 W
1use embedded_graphics::prelude::Point;
2
3use super::CURRENT_IMAGE;
4
5static NUMBER_OF_IMAGES: u8 = 3;
6static FERRIS_IMG: &[u8; 15722] = include_bytes!("../../images/ferris_w_a_knife.bmp");
7static REPO_IMG: &[u8; 11262] = include_bytes!("../../images/repo.bmp");
8static MTRAS_LOGO: &[u8; 11162] = include_bytes!("../../images/mtras_logo.bmp");
9
10pub enum DisplayImage {
11 Ferris = 0,
12 Repo = 1,
13 MtrasLogo = 2,
14}
15
16pub fn get_current_image() -> DisplayImage {
17 DisplayImage::from_u8(CURRENT_IMAGE.load(core::sync::atomic::Ordering::Relaxed)).unwrap()
18}
19
20impl DisplayImage {
21 pub fn from_u8(value: u8) -> Option<Self> {
22 match value {
23 0 => Some(Self::Ferris),
24 1 => Some(Self::Repo),
25 2 => Some(Self::MtrasLogo),
26 _ => None,
27 }
28 }
29
30 pub fn as_u8(&self) -> u8 {
31 match self {
32 Self::Ferris => 0,
33 Self::Repo => 1,
34 Self::MtrasLogo => 2,
35 }
36 }
37
38 pub fn image(&self) -> &'static [u8] {
39 match self {
40 Self::Ferris => FERRIS_IMG,
41 Self::Repo => REPO_IMG,
42 Self::MtrasLogo => MTRAS_LOGO,
43 }
44 }
45
46 pub fn next(&self) -> Self {
47 let image_count = self.as_u8();
48 let next_image = (image_count + 1) % NUMBER_OF_IMAGES;
49 DisplayImage::from_u8(next_image).unwrap()
50 }
51
52 pub fn previous(&self) -> Self {
53 let image_count = self.as_u8();
54 if image_count == 0 {
55 return DisplayImage::from_u8(NUMBER_OF_IMAGES - 1).unwrap();
56 }
57 let previous_image = (image_count - 1) % NUMBER_OF_IMAGES;
58 DisplayImage::from_u8(previous_image).unwrap()
59 }
60
61 pub fn image_location(&self) -> Point {
62 match self {
63 Self::Ferris => Point::new(150, 26),
64 Self::Repo => Point::new(190, 26),
65 Self::MtrasLogo => Point::new(190, 26),
66 }
67 }
68}