Add message listing and message reading states
This commit is contained in:
parent
4c0f284b62
commit
11ca5019b5
@ -720,12 +720,12 @@ pub enum ListSMSMessagesResponse {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SMSMessageListing {
|
||||
index: u32,
|
||||
stat: SMSMessageStat,
|
||||
from_addr: String,
|
||||
to_addr: String,
|
||||
timestamp: String,
|
||||
text: String,
|
||||
pub index: u32,
|
||||
pub stat: SMSMessageStat,
|
||||
pub from_addr: String,
|
||||
pub to_addr: String,
|
||||
pub timestamp: String,
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
impl ATResponse for ListSMSMessagesResponse {
|
||||
@ -791,8 +791,8 @@ impl ATCommand for ListSMSMessages {
|
||||
let mut params = parser.params().unwrap();
|
||||
let idx = params.read_u32().unwrap();
|
||||
let stat = SMSMessageStat::from(¶ms.read_string().unwrap());
|
||||
let from_addr = params.read_string().unwrap();
|
||||
let to_addr = params.read_string().unwrap();
|
||||
let from_addr = params.read_string().unwrap();
|
||||
let timestamp = params.read_string().unwrap();
|
||||
|
||||
let mut message = String::new();
|
||||
|
||||
101
src/states.rs
101
src/states.rs
@ -5,6 +5,7 @@ use alloc::{
|
||||
boxed::Box,
|
||||
format,
|
||||
string::{String, ToString},
|
||||
vec::Vec,
|
||||
};
|
||||
use esp_hal::time::{Duration, Instant};
|
||||
|
||||
@ -12,8 +13,9 @@ use crate::{
|
||||
async_io::{ATPromise, KeypadButton, NumberInput, TextInput},
|
||||
at_commands::{
|
||||
ATCommand, ATError, ATInformationCommand, CheckPinCommand, CheckPinResult, EnterPinCommand,
|
||||
EnterPinResult, ListSMSMessages, SMSFormat, SMSMessageStat, SelectSMSFormatCommand,
|
||||
SendSMSCommand, SendSMSResponse, SetTECharsetCommand, SimpleATResponse, TECharset,
|
||||
EnterPinResult, ListSMSMessages, ListSMSMessagesResponse, SMSFormat, SMSMessageListing,
|
||||
SMSMessageStat, SelectSMSFormatCommand, SendSMSCommand, SendSMSResponse,
|
||||
SetTECharsetCommand, SimpleATResponse, TECharset,
|
||||
},
|
||||
display::{Position, Rgb565},
|
||||
font::{HorizontalAlignment, VerticalAlignment},
|
||||
@ -339,18 +341,20 @@ impl State for MainMenuState {
|
||||
MainMenuItem::SendSMS => return Some(Box::new(PhoneNumberState::default())),
|
||||
MainMenuItem::ReadSMS => {
|
||||
return Some(Box::new(ATCommandState::with(
|
||||
"Loading messages".to_owned(),
|
||||
"Loading\nmessages".to_owned(),
|
||||
ListSMSMessages {
|
||||
stat: SMSMessageStat::All,
|
||||
},
|
||||
|resp| match resp {
|
||||
Ok(messages) => {
|
||||
log::info!("{:?}", messages);
|
||||
Box::new(TextState {
|
||||
text: format!("Messages read"),
|
||||
Ok(response) => match response {
|
||||
ListSMSMessagesResponse::Ok(messages) => {
|
||||
Box::new(ListSMSMessagesState::from(messages))
|
||||
}
|
||||
ListSMSMessagesResponse::Error(err) => Box::new(TextState {
|
||||
text: format!("Error:\n{:?}", err),
|
||||
after: MainMenuState::default(),
|
||||
})
|
||||
}
|
||||
}),
|
||||
},
|
||||
Err(err) => Box::new(TextState {
|
||||
text: format!("Error:\n{:?}", err),
|
||||
after: MainMenuState::default(),
|
||||
@ -369,6 +373,85 @@ impl State for MainMenuState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct MessageListing {
|
||||
from: String,
|
||||
text: String,
|
||||
}
|
||||
|
||||
impl MenuItem for MessageListing {
|
||||
fn as_text(&self) -> String {
|
||||
format!("{}: {}", self.from, self.text)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct ListSMSMessagesState {
|
||||
menu: Menu<MessageListing>,
|
||||
}
|
||||
|
||||
impl ListSMSMessagesState {
|
||||
pub fn from(messages: Vec<SMSMessageListing>) -> ListSMSMessagesState {
|
||||
let mut menu = Menu::default();
|
||||
for message in &messages {
|
||||
menu = menu.with_item(MessageListing {
|
||||
from: message.from_addr.clone(),
|
||||
text: message.text.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
ListSMSMessagesState { menu }
|
||||
}
|
||||
}
|
||||
|
||||
impl State for ListSMSMessagesState {
|
||||
fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> {
|
||||
if let Some(listing) = self.menu.poll(&mut data.io) {
|
||||
return Some(Box::new(ReadMessageState {
|
||||
message: listing.clone(),
|
||||
}));
|
||||
}
|
||||
if data.io.keypad.get_presses(KeypadButton::KeypadB) > 0 {
|
||||
Some(Box::new(MainMenuState::default()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn draw(&self, data: &mut StateData) {
|
||||
self.menu.draw(data);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct ReadMessageState {
|
||||
message: MessageListing,
|
||||
}
|
||||
|
||||
impl State for ReadMessageState {
|
||||
fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> {
|
||||
if data.io.keypad.get_presses(KeypadButton::KeypadB) > 0 {
|
||||
Some(Box::new(MainMenuState::default()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn draw(&self, data: &mut StateData) {
|
||||
data.clear_screen(Rgb565::black().as_color());
|
||||
data.draw_text(
|
||||
self.message.from.clone(),
|
||||
Position::new(0, 0),
|
||||
TextSettings::default(),
|
||||
);
|
||||
data.draw_text(
|
||||
self.message.text.clone(),
|
||||
Position::new(0, 30),
|
||||
TextSettings::default(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct PhoneNumberState {
|
||||
input: NumberInput,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user