Improve states a bit

This commit is contained in:
Sofia 2026-06-01 19:48:10 +03:00
parent dde828d63d
commit 09f74bf289

View File

@ -11,7 +11,7 @@ use esp_hal::time::{Duration, Instant};
use crate::{ use crate::{
async_io::{ATPromise, KeypadButton}, async_io::{ATPromise, KeypadButton},
at_commands::{ at_commands::{
ATCommand, ATInformationCommand, ATParseError, ATResponse, CheckPinCommand, CheckPinResult, ATCommand, ATInformationCommand, ATParseError, CheckPinCommand, CheckPinResult,
EnterPinCommand, EnterPinResult, SMSFormat, SelectSMSFormatCommand, SendSMSCommand, EnterPinCommand, EnterPinResult, SMSFormat, SelectSMSFormatCommand, SendSMSCommand,
SendSMSResponse, SetTECharsetCommand, SimpleATResponse, TECharset, SendSMSResponse, SetTECharsetCommand, SimpleATResponse, TECharset,
}, },
@ -20,7 +20,7 @@ use crate::{
state::{ATCommandHelper, State, StateData, TextSettings}, state::{ATCommandHelper, State, StateData, TextSettings},
}; };
#[derive(Debug)] #[derive(Debug, Clone)]
pub struct DotsMessage { pub struct DotsMessage {
message: String, message: String,
dots: u8, dots: u8,
@ -123,7 +123,7 @@ pub struct InitATState {
check_pin: ATCommandHelper<CheckPinCommand>, check_pin: ATCommandHelper<CheckPinCommand>,
sms_charset: ATCommandHelper<SelectSMSFormatCommand>, sms_charset: ATCommandHelper<SelectSMSFormatCommand>,
te_charset: ATCommandHelper<SetTECharsetCommand>, te_charset: ATCommandHelper<SetTECharsetCommand>,
message: String, message: DotsMessage,
} }
impl Default for InitATState { impl Default for InitATState {
@ -134,17 +134,20 @@ impl Default for InitATState {
check_pin: ATCommandHelper::new(CheckPinCommand), 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: "Initializing".to_owned(), message: DotsMessage::default(),
} }
} }
} }
impl State for InitATState { impl State for InitATState {
fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> { fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> {
// Update dots
self.message.poll();
if let Some(resp) = self.ati.poll(&mut data.io) { if let Some(resp) = self.ati.poll(&mut data.io) {
resp.unwrap() resp.unwrap()
} else { } else {
self.message = "Checking ATI".to_owned(); self.message.message = "Checking ATI".to_owned();
return None; return None;
}; };
@ -165,7 +168,7 @@ impl State for InitATState {
} }
} }
} else { } else {
self.message = "Entering PIN".to_owned(); self.message.message = "Entering PIN".to_owned();
return None; return None;
}; };
@ -188,7 +191,7 @@ impl State for InitATState {
} }
} }
} else { } else {
self.message = "Checking PIN".to_owned(); self.message.message = "Checking PIN".to_owned();
return None; return None;
}; };
@ -203,7 +206,7 @@ impl State for InitATState {
} }
} }
} else { } else {
self.message = "Selecting SMS\ncharset".to_owned(); self.message.message = "Selecting SMS\ncharset".to_owned();
return None; return None;
}; };
@ -218,7 +221,7 @@ impl State for InitATState {
} }
} }
} else { } else {
self.message = "Selecting TE\ncharset".to_owned(); self.message.message = "Selecting TE\ncharset".to_owned();
return None; return None;
}; };
@ -231,7 +234,7 @@ impl State for InitATState {
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!("{}", self.message), self.message.render(),
Position::new(0, 0), Position::new(0, 0),
TextSettings::default(), TextSettings::default(),
); );