Add sending SMS messages through UI
This commit is contained in:
parent
5a45601148
commit
7554b95fff
@ -78,10 +78,17 @@ impl<'a, 'd> ATCommands<'a, 'd> {
|
||||
self.flush_rx();
|
||||
|
||||
let text = additional.clone() + "\x1A";
|
||||
self.uart.write_str(&text).unwrap();
|
||||
if let Some(ascii) = text.as_ascii() {
|
||||
log::info!("{:?}", &ascii.as_bytes());
|
||||
self.uart.write(&ascii.as_bytes()).unwrap();
|
||||
log::info!("Wrote additional {}", additional);
|
||||
} else {
|
||||
self.uart.write_str("???\x1A").unwrap();
|
||||
log::info!("Wrote ???");
|
||||
}
|
||||
self.uart.flush().unwrap();
|
||||
|
||||
self.read_response(text)
|
||||
self.read_response(format!("> {}", text))
|
||||
}
|
||||
|
||||
pub fn readline(&mut self) -> Option<String> {
|
||||
@ -97,6 +104,7 @@ impl<'a, 'd> ATCommands<'a, 'd> {
|
||||
let mut response = None;
|
||||
while response.is_none() {
|
||||
self.flush_rx();
|
||||
log::info!("{:?}", self.lines);
|
||||
response = self.parse_response(&start);
|
||||
}
|
||||
|
||||
@ -313,7 +321,7 @@ impl ATCommand for SendSMSCommand {
|
||||
|
||||
fn execute(&self) -> ConstructedATCommand {
|
||||
ConstructedATCommand::AddInfo(
|
||||
format!("AT+CMGS={}", self.destination),
|
||||
format!("AT+CMGS=\"{}\"", self.destination),
|
||||
self.message.clone(),
|
||||
)
|
||||
}
|
||||
|
||||
108
src/states.rs
108
src/states.rs
@ -12,7 +12,7 @@ use crate::{
|
||||
async_io::{ATPromise, KeypadButton},
|
||||
at_commands::{
|
||||
ATCommand, ATInformationCommand, CheckPinCommand, EnterPinCommand, SMSFormat,
|
||||
SelectSMSFormatCommand, SetTECharsetCommand, TECharset,
|
||||
SelectSMSFormatCommand, SendSMSCommand, SetTECharsetCommand, TECharset,
|
||||
},
|
||||
display::{Position, Rgb565},
|
||||
font::{HorizontalAlignment, VerticalAlignment},
|
||||
@ -130,7 +130,7 @@ pub struct TextState {
|
||||
impl State for TextState {
|
||||
fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> {
|
||||
if data.io.keypad.get_presses(KeypadButton::KeypadA) > 0 {
|
||||
Some(Box::new(ButtonTestState {
|
||||
Some(Box::new(PhoneNumberState {
|
||||
written: String::new(),
|
||||
}))
|
||||
} else {
|
||||
@ -153,41 +153,103 @@ impl State for TextState {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ButtonTestState {
|
||||
pub struct PhoneNumberState {
|
||||
written: String,
|
||||
}
|
||||
|
||||
impl State for ButtonTestState {
|
||||
impl State for PhoneNumberState {
|
||||
fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> {
|
||||
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',
|
||||
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,
|
||||
};
|
||||
self.written += &character.to_string();
|
||||
if let Some(character) = character {
|
||||
self.written += &character.to_string();
|
||||
}
|
||||
}
|
||||
if data.io.keypad.get_presses(KeypadButton::KeypadA) > 0 {
|
||||
Some(Box::new(MessageState {
|
||||
number: self.written.clone(),
|
||||
written: String::new(),
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn draw(&self, data: &mut StateData) {
|
||||
data.clear_screen(Rgb565::black().as_color());
|
||||
data.draw_text("Phone num:", Position::new(0, 0), TextSettings::default());
|
||||
data.draw_text(
|
||||
format!("{}", self.written),
|
||||
Position::new(0, 0),
|
||||
Position::new(0, 30),
|
||||
TextSettings::default(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MessageState {
|
||||
number: String,
|
||||
written: String,
|
||||
}
|
||||
|
||||
impl State for MessageState {
|
||||
fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> {
|
||||
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 {
|
||||
Some(Box::new(ATCommandState::with(
|
||||
"Sending SMS..".to_owned(),
|
||||
SendSMSCommand {
|
||||
destination: self.number.clone(),
|
||||
message: self.written.clone(),
|
||||
},
|
||||
TextState {
|
||||
text: "SMS Sent!".to_owned(),
|
||||
},
|
||||
)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn draw(&self, data: &mut StateData) {
|
||||
data.clear_screen(Rgb565::black().as_color());
|
||||
data.draw_text("Message:", Position::new(0, 0), TextSettings::default());
|
||||
data.draw_text(
|
||||
format!("{}", self.written),
|
||||
Position::new(0, 30),
|
||||
TextSettings::default(),
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user