diff --git a/src/async_io.rs b/src/async_io.rs index b513fe5..1823758 100644 --- a/src/async_io.rs +++ b/src/async_io.rs @@ -21,6 +21,7 @@ pub enum KeypadButton { Keypad7, Keypad8, Keypad9, + Keypad0, KeypadStar, KeypadHash, KeypadA, diff --git a/src/main.rs b/src/main.rs index c91fc5d..ee40f3a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -213,7 +213,7 @@ static KEYPAD_BUTTONS: [[KeypadButton; 4]; 4] = [ ], [ KeypadButton::KeypadStar, - KeypadButton::Keypad9, + KeypadButton::Keypad0, KeypadButton::KeypadHash, KeypadButton::KeypadD, ], diff --git a/src/states.rs b/src/states.rs index d5408aa..d0cceca 100644 --- a/src/states.rs +++ b/src/states.rs @@ -1,6 +1,11 @@ use core::iter::repeat; -use alloc::{borrow::ToOwned, boxed::Box, format, string::String}; +use alloc::{ + borrow::ToOwned, + boxed::Box, + format, + string::{String, ToString}, +}; use esp_hal::time::{Duration, Instant}; use crate::{ @@ -125,7 +130,9 @@ pub struct TextState { impl State for TextState { fn update(&mut self, data: &mut StateData) -> Option> { if data.io.keypad.get_presses(KeypadButton::KeypadA) > 0 { - Some(Box::new(ButtonTestState { presses: 0 })) + Some(Box::new(ButtonTestState { + written: String::new(), + })) } else { None } @@ -147,19 +154,39 @@ impl State for TextState { } pub struct ButtonTestState { - presses: u32, + written: String, } impl State for ButtonTestState { fn update(&mut self, data: &mut StateData) -> Option> { - self.presses += data.io.keypad.get_presses(KeypadButton::KeypadA); + for button in data.io.keypad.just_pressed_buttons() { + let character = match button { + KeypadButton::Keypad1 => '1', + KeypadButton::Keypad2 => '2', + KeypadButton::Keypad3 => '3', + KeypadButton::Keypad4 => '4', + KeypadButton::Keypad5 => '5', + KeypadButton::Keypad6 => '6', + KeypadButton::Keypad7 => '7', + KeypadButton::Keypad8 => '8', + KeypadButton::Keypad9 => '9', + KeypadButton::Keypad0 => '0', + KeypadButton::KeypadStar => '*', + KeypadButton::KeypadHash => '#', + KeypadButton::KeypadA => 'A', + KeypadButton::KeypadB => 'B', + KeypadButton::KeypadC => 'C', + KeypadButton::KeypadD => 'D', + }; + self.written += &character.to_string(); + } None } fn draw(&self, data: &mut StateData) { data.clear_screen(Rgb565::black().as_color()); data.draw_text( - format!("Presses: {}", self.presses), + format!("{}", self.written), Position::new(0, 0), TextSettings::default(), );