Add menu for selecting PIN
This commit is contained in:
parent
09f74bf289
commit
3a43aff319
@ -8,6 +8,7 @@ use alloc::{
|
|||||||
vec::Vec,
|
vec::Vec,
|
||||||
};
|
};
|
||||||
use critical_section::Mutex;
|
use critical_section::Mutex;
|
||||||
|
use esp_hal::delay::Delay;
|
||||||
|
|
||||||
use crate::at_commands::{ATCommand, ATParseError, ATResponseParser, SimpleATCommand};
|
use crate::at_commands::{ATCommand, ATParseError, ATResponseParser, SimpleATCommand};
|
||||||
|
|
||||||
@ -144,9 +145,10 @@ impl<T: ATCommand> ATPromise<T> {
|
|||||||
pub fn poll(&self, io: &mut AsyncIO) -> Option<Option<Result<T::Response, ATParseError>>> {
|
pub fn poll(&self, io: &mut AsyncIO) -> Option<Option<Result<T::Response, ATParseError>>> {
|
||||||
match io.poll_at_response() {
|
match io.poll_at_response() {
|
||||||
Some(response) => match response {
|
Some(response) => match response {
|
||||||
Some(response) => Some(Some(T::parse_response(&mut ATResponseParser::from(
|
Some(response) => {
|
||||||
response,
|
let mut parser = ATResponseParser::from(response);
|
||||||
)))),
|
Some(Some(T::parse_response(&mut parser)))
|
||||||
|
}
|
||||||
None => Some(None),
|
None => Some(None),
|
||||||
},
|
},
|
||||||
None => Some(None),
|
None => Some(None),
|
||||||
|
|||||||
@ -112,6 +112,8 @@ impl<'a, 'd> ATCommands<'a, 'd> {
|
|||||||
response = self.parse_response(cmd, &start);
|
response = self.parse_response(cmd, &start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log::info!("{:?}", response);
|
||||||
|
|
||||||
response.unwrap()
|
response.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
125
src/states.rs
125
src/states.rs
@ -119,8 +119,6 @@ where
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct InitATState {
|
pub struct InitATState {
|
||||||
ati: ATCommandHelper<ATInformationCommand>,
|
ati: ATCommandHelper<ATInformationCommand>,
|
||||||
enter_pin: ATCommandHelper<EnterPinCommand>,
|
|
||||||
check_pin: ATCommandHelper<CheckPinCommand>,
|
|
||||||
sms_charset: ATCommandHelper<SelectSMSFormatCommand>,
|
sms_charset: ATCommandHelper<SelectSMSFormatCommand>,
|
||||||
te_charset: ATCommandHelper<SetTECharsetCommand>,
|
te_charset: ATCommandHelper<SetTECharsetCommand>,
|
||||||
message: DotsMessage,
|
message: DotsMessage,
|
||||||
@ -130,8 +128,6 @@ impl Default for InitATState {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
ati: ATCommandHelper::new(ATInformationCommand),
|
ati: ATCommandHelper::new(ATInformationCommand),
|
||||||
enter_pin: ATCommandHelper::new(EnterPinCommand("1234".to_owned())),
|
|
||||||
check_pin: ATCommandHelper::new(CheckPinCommand),
|
|
||||||
sms_charset: ATCommandHelper::new(SelectSMSFormatCommand(SMSFormat::TextMode)),
|
sms_charset: ATCommandHelper::new(SelectSMSFormatCommand(SMSFormat::TextMode)),
|
||||||
te_charset: ATCommandHelper::new(SetTECharsetCommand(TECharset::IRA)),
|
te_charset: ATCommandHelper::new(SetTECharsetCommand(TECharset::IRA)),
|
||||||
message: DotsMessage::default(),
|
message: DotsMessage::default(),
|
||||||
@ -151,50 +147,6 @@ impl State for InitATState {
|
|||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(resp) = self.enter_pin.poll(&mut data.io) {
|
|
||||||
match resp.unwrap() {
|
|
||||||
EnterPinResult::Ok => {}
|
|
||||||
EnterPinResult::Error => {
|
|
||||||
return Some(Box::new(TextState {
|
|
||||||
text: "ERROR!".to_owned(),
|
|
||||||
after: InitATState::default(),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
EnterPinResult::ErrorMessage(msg) => {
|
|
||||||
return Some(Box::new(TextState {
|
|
||||||
text: format!("Error:\n{}", msg),
|
|
||||||
after: InitATState::default(),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
self.message.message = "Entering PIN".to_owned();
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(resp) = self.check_pin.poll(&mut data.io) {
|
|
||||||
match resp.unwrap() {
|
|
||||||
CheckPinResult::Status(status) => {
|
|
||||||
log::info!("Status: {}", status)
|
|
||||||
}
|
|
||||||
CheckPinResult::Error => {
|
|
||||||
return Some(Box::new(TextState {
|
|
||||||
text: "ERROR!".to_owned(),
|
|
||||||
after: InitATState::default(),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
CheckPinResult::ErrorMessage(msg) => {
|
|
||||||
return Some(Box::new(TextState {
|
|
||||||
text: format!("Error:\n{}", msg),
|
|
||||||
after: InitATState::default(),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
self.message.message = "Checking PIN".to_owned();
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(resp) = self.sms_charset.poll(&mut data.io) {
|
if let Some(resp) = self.sms_charset.poll(&mut data.io) {
|
||||||
match resp.unwrap() {
|
match resp.unwrap() {
|
||||||
SimpleATResponse::Ok => {}
|
SimpleATResponse::Ok => {}
|
||||||
@ -225,10 +177,7 @@ impl State for InitATState {
|
|||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(Box::new(TextState {
|
Some(Box::new(EnterPinState::default()))
|
||||||
text: "All done!".to_owned(),
|
|
||||||
after: PhoneNumberState::default(),
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&self, data: &mut StateData) {
|
fn draw(&self, data: &mut StateData) {
|
||||||
@ -271,6 +220,78 @@ impl<T: State + Clone> State for TextState<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Default)]
|
||||||
|
pub struct EnterPinState {
|
||||||
|
written: String,
|
||||||
|
helper: Option<ATCommandHelper<EnterPinCommand>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl State for EnterPinState {
|
||||||
|
fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> {
|
||||||
|
if let Some(helper) = &mut self.helper {
|
||||||
|
match helper.poll(&mut data.io) {
|
||||||
|
Some(response) => match response.unwrap() {
|
||||||
|
EnterPinResult::Ok => {
|
||||||
|
return Some(Box::new(TextState {
|
||||||
|
text: "SIM entered\nsuccessfully".to_owned(),
|
||||||
|
after: PhoneNumberState::default(),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
EnterPinResult::Error => {
|
||||||
|
return Some(Box::new(TextState {
|
||||||
|
text: "ERROR!".to_owned(),
|
||||||
|
after: EnterPinState::default(),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
EnterPinResult::ErrorMessage(msg) => {
|
||||||
|
return Some(Box::new(TextState {
|
||||||
|
text: format!("Error:\n{}", msg),
|
||||||
|
after: EnterPinState::default(),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => return None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for button in data.io.keypad.just_pressed_buttons() {
|
||||||
|
let character = match button {
|
||||||
|
KeypadButton::Keypad1 => Some('1'),
|
||||||
|
KeypadButton::Keypad2 => Some('2'),
|
||||||
|
KeypadButton::Keypad3 => Some('3'),
|
||||||
|
KeypadButton::Keypad4 => Some('4'),
|
||||||
|
KeypadButton::Keypad5 => Some('5'),
|
||||||
|
KeypadButton::Keypad6 => Some('6'),
|
||||||
|
KeypadButton::Keypad7 => Some('7'),
|
||||||
|
KeypadButton::Keypad8 => Some('8'),
|
||||||
|
KeypadButton::Keypad9 => Some('9'),
|
||||||
|
KeypadButton::Keypad0 => Some('0'),
|
||||||
|
KeypadButton::KeypadStar => Some('*'),
|
||||||
|
KeypadButton::KeypadHash => Some('#'),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
if let Some(character) = character {
|
||||||
|
self.written += &character.to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.io.keypad.get_presses(KeypadButton::KeypadA) > 0 {
|
||||||
|
self.helper = Some(ATCommandHelper::new(EnterPinCommand(self.written.clone())));
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw(&self, data: &mut StateData) {
|
||||||
|
data.clear_screen(Rgb565::black().as_color());
|
||||||
|
data.draw_text("PIN:", Position::new(0, 0), TextSettings::default());
|
||||||
|
data.draw_text(
|
||||||
|
format!("{}", self.written),
|
||||||
|
Position::new(0, 30),
|
||||||
|
TextSettings::default(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct PhoneNumberState {
|
pub struct PhoneNumberState {
|
||||||
written: String,
|
written: String,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user