Add a tester keypad state
This commit is contained in:
parent
861bc195d7
commit
5a45601148
@ -21,6 +21,7 @@ pub enum KeypadButton {
|
|||||||
Keypad7,
|
Keypad7,
|
||||||
Keypad8,
|
Keypad8,
|
||||||
Keypad9,
|
Keypad9,
|
||||||
|
Keypad0,
|
||||||
KeypadStar,
|
KeypadStar,
|
||||||
KeypadHash,
|
KeypadHash,
|
||||||
KeypadA,
|
KeypadA,
|
||||||
|
|||||||
@ -213,7 +213,7 @@ static KEYPAD_BUTTONS: [[KeypadButton; 4]; 4] = [
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
KeypadButton::KeypadStar,
|
KeypadButton::KeypadStar,
|
||||||
KeypadButton::Keypad9,
|
KeypadButton::Keypad0,
|
||||||
KeypadButton::KeypadHash,
|
KeypadButton::KeypadHash,
|
||||||
KeypadButton::KeypadD,
|
KeypadButton::KeypadD,
|
||||||
],
|
],
|
||||||
|
|||||||
@ -1,6 +1,11 @@
|
|||||||
use core::iter::repeat;
|
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 esp_hal::time::{Duration, Instant};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -125,7 +130,9 @@ pub struct TextState {
|
|||||||
impl State for TextState {
|
impl State for TextState {
|
||||||
fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> {
|
fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> {
|
||||||
if data.io.keypad.get_presses(KeypadButton::KeypadA) > 0 {
|
if data.io.keypad.get_presses(KeypadButton::KeypadA) > 0 {
|
||||||
Some(Box::new(ButtonTestState { presses: 0 }))
|
Some(Box::new(ButtonTestState {
|
||||||
|
written: String::new(),
|
||||||
|
}))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@ -147,19 +154,39 @@ impl State for TextState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct ButtonTestState {
|
pub struct ButtonTestState {
|
||||||
presses: u32,
|
written: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State for ButtonTestState {
|
impl State for ButtonTestState {
|
||||||
fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> {
|
fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> {
|
||||||
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
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&self, data: &mut StateData) {
|
fn draw(&self, data: &mut StateData) {
|
||||||
data.clear_screen(Rgb565::black().as_color());
|
data.clear_screen(Rgb565::black().as_color());
|
||||||
data.draw_text(
|
data.draw_text(
|
||||||
format!("Presses: {}", self.presses),
|
format!("{}", self.written),
|
||||||
Position::new(0, 0),
|
Position::new(0, 0),
|
||||||
TextSettings::default(),
|
TextSettings::default(),
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user