Add sending SMS messages through UI

This commit is contained in:
Sofia 2026-05-29 22:28:47 +03:00
parent 5a45601148
commit 7554b95fff
2 changed files with 96 additions and 26 deletions

View File

@ -78,10 +78,17 @@ impl<'a, 'd> ATCommands<'a, 'd> {
self.flush_rx(); self.flush_rx();
let text = additional.clone() + "\x1A"; 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.uart.flush().unwrap();
self.read_response(text) self.read_response(format!("> {}", text))
} }
pub fn readline(&mut self) -> Option<String> { pub fn readline(&mut self) -> Option<String> {
@ -97,6 +104,7 @@ impl<'a, 'd> ATCommands<'a, 'd> {
let mut response = None; let mut response = None;
while response.is_none() { while response.is_none() {
self.flush_rx(); self.flush_rx();
log::info!("{:?}", self.lines);
response = self.parse_response(&start); response = self.parse_response(&start);
} }
@ -313,7 +321,7 @@ impl ATCommand for SendSMSCommand {
fn execute(&self) -> ConstructedATCommand { fn execute(&self) -> ConstructedATCommand {
ConstructedATCommand::AddInfo( ConstructedATCommand::AddInfo(
format!("AT+CMGS={}", self.destination), format!("AT+CMGS=\"{}\"", self.destination),
self.message.clone(), self.message.clone(),
) )
} }

View File

@ -12,7 +12,7 @@ use crate::{
async_io::{ATPromise, KeypadButton}, async_io::{ATPromise, KeypadButton},
at_commands::{ at_commands::{
ATCommand, ATInformationCommand, CheckPinCommand, EnterPinCommand, SMSFormat, ATCommand, ATInformationCommand, CheckPinCommand, EnterPinCommand, SMSFormat,
SelectSMSFormatCommand, SetTECharsetCommand, TECharset, SelectSMSFormatCommand, SendSMSCommand, SetTECharsetCommand, TECharset,
}, },
display::{Position, Rgb565}, display::{Position, Rgb565},
font::{HorizontalAlignment, VerticalAlignment}, font::{HorizontalAlignment, VerticalAlignment},
@ -130,7 +130,7 @@ 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 { Some(Box::new(PhoneNumberState {
written: String::new(), written: String::new(),
})) }))
} else { } else {
@ -153,41 +153,103 @@ impl State for TextState {
} }
} }
pub struct ButtonTestState { pub struct PhoneNumberState {
written: String, written: String,
} }
impl State for ButtonTestState { impl State for PhoneNumberState {
fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> { fn update(&mut self, data: &mut StateData) -> Option<Box<dyn State>> {
for button in data.io.keypad.just_pressed_buttons() { for button in data.io.keypad.just_pressed_buttons() {
let character = match button { let character = match button {
KeypadButton::Keypad1 => '1', KeypadButton::Keypad1 => Some('1'),
KeypadButton::Keypad2 => '2', KeypadButton::Keypad2 => Some('2'),
KeypadButton::Keypad3 => '3', KeypadButton::Keypad3 => Some('3'),
KeypadButton::Keypad4 => '4', KeypadButton::Keypad4 => Some('4'),
KeypadButton::Keypad5 => '5', KeypadButton::Keypad5 => Some('5'),
KeypadButton::Keypad6 => '6', KeypadButton::Keypad6 => Some('6'),
KeypadButton::Keypad7 => '7', KeypadButton::Keypad7 => Some('7'),
KeypadButton::Keypad8 => '8', KeypadButton::Keypad8 => Some('8'),
KeypadButton::Keypad9 => '9', KeypadButton::Keypad9 => Some('9'),
KeypadButton::Keypad0 => '0', KeypadButton::Keypad0 => Some('0'),
KeypadButton::KeypadStar => '*', KeypadButton::KeypadStar => Some('*'),
KeypadButton::KeypadHash => '#', KeypadButton::KeypadHash => Some('#'),
KeypadButton::KeypadA => 'A', _ => None,
KeypadButton::KeypadB => 'B',
KeypadButton::KeypadC => 'C',
KeypadButton::KeypadD => 'D',
}; };
if let Some(character) = character {
self.written += &character.to_string(); 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) { fn draw(&self, data: &mut StateData) {
data.clear_screen(Rgb565::black().as_color()); data.clear_screen(Rgb565::black().as_color());
data.draw_text("Phone num:", Position::new(0, 0), TextSettings::default());
data.draw_text( data.draw_text(
format!("{}", self.written), 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(), TextSettings::default(),
); );
} }