#[derive(Copy, Clone)] pub struct Display { pub buf: [u8; Self::SCREEN_SIZE], } impl Display { const SCREEN_SIZE: usize = 64 * 32; pub fn clear(&mut self) { self.buf = [0; Self::SCREEN_SIZE] } } impl Default for Display { fn default() -> Self { Display { buf: [0; Self::SCREEN_SIZE], } } } #[derive(Debug, Copy, Clone)] pub struct Timer { remaining: u8, enabled: bool, } impl Default for Timer { fn default() -> Self { Timer { remaining: 0, enabled: false, } } } impl Timer { pub fn set(&mut self, secs: u8) { self.remaining = secs; self.enabled = true; } pub fn get(&self) -> u8 { self.remaining } pub fn tick(&mut self) { if self.enabled { self.remaining -= 1; if self.remaining == 0 { println!("Beep!"); self.enabled = false; } } } } #[derive(Debug, Copy, Clone)] pub struct Keypad { keys: [bool; 16], } impl Default for Keypad { fn default() -> Self { Self { keys: [false; 16] } } } impl Keypad { pub fn get_pressed(&self) -> Option { let mut found: Option = None; for (index, key) in self.keys.iter().enumerate() { if *key { found = Some(index as u8); break; } } found } }