From 61e1f055f16bc74eeacf6eac01be7aae3ef5f168 Mon Sep 17 00:00:00 2001 From: Michel Heily Date: Sat, 20 Jul 2019 22:58:19 +0300 Subject: [PATCH] Model the keypad Former-commit-id: 4f38fa754e3ee809a7386351297decb2d7f1451f --- src/core/keypad.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/core/keypad.rs diff --git a/src/core/keypad.rs b/src/core/keypad.rs new file mode 100644 index 0000000..f8749a1 --- /dev/null +++ b/src/core/keypad.rs @@ -0,0 +1,33 @@ +#[derive(Debug, Primitive, PartialEq)] +#[repr(u8)] +pub enum Keys { + ButtonA = 0, + ButtonB = 1, + Select = 2, + Start = 3, + Right = 4, + Left = 5, + Up = 6, + Down = 7, + ButtonR = 8, + ButtonL = 9, +} + +pub const NUM_KEYS: usize = 10; +pub const KEYINPUT_ALL_RELEASED: u16 = 0b1111111111; + +#[derive(Debug, Primitive, PartialEq)] +#[repr(u8)] +pub enum KeyState { + Pressed = 0, + Released = 1, +} + +impl Into for KeyState { + fn into(self) -> bool { + match self { + KeyState::Pressed => false, + KeyState::Released => true, + } + } +}