Add some new AT commands

This commit is contained in:
Sofia 2026-05-28 20:40:50 +03:00
parent eb8e619aa1
commit a8a52c8a22
4 changed files with 42 additions and 20 deletions

View File

@ -1,6 +1,6 @@
use core::cell::RefCell;
use alloc::{rc::Rc, string::String};
use alloc::{borrow::ToOwned, rc::Rc, string::String};
use critical_section::Mutex;
#[derive(Clone)]
@ -17,6 +17,8 @@ pub enum ATCommand {
CheckSMSFormat,
/// AT+CSCS=?
ListTECharacterSets,
SetTECharSet(Charset),
SendSMS(String, String),
}
#[derive(Clone)]
@ -25,6 +27,25 @@ pub enum SMSFormat {
TextMode = 1,
}
#[derive(Clone)]
pub enum Charset {
IRA,
UCS2,
HEX,
GSM,
}
impl Charset {
pub fn into_str(&self) -> String {
match self {
Charset::IRA => "IRA".to_owned(),
Charset::UCS2 => "UCS2".to_owned(),
Charset::HEX => "HEX".to_owned(),
Charset::GSM => "GSM".to_owned(),
}
}
}
#[derive(Clone)]
pub struct Button {
was_pressed: Rc<Mutex<RefCell<bool>>>,

View File

@ -32,8 +32,7 @@ impl<'a, 'd> ATCommands<'a, 'd> {
log::info!("ATCommands Ready!");
self.delay.delay_millis(1_000);
log::info!("text: {}", self.flush_rx());
self.flush_rx();
}
pub fn raw_command(&mut self, command: String) -> String {
@ -99,7 +98,6 @@ impl<'a, 'd> ATCommands<'a, 'd> {
self.uart.read_ready()
} {
let length = self.uart.read(&mut buffer).unwrap();
log::info!("{:?}", &buffer[..length]);
contents += str::from_utf8(&buffer[..length]).unwrap();
}

View File

@ -1,5 +1,6 @@
#![no_std]
#![no_main]
#![feature(ascii_char)]
#![deny(
clippy::mem_forget,
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
@ -7,24 +8,13 @@
)]
#![deny(clippy::large_stack_frames)]
use core::{
cell::{Cell, RefCell},
mem::MaybeUninit,
};
use core::mem::MaybeUninit;
use alloc::{
borrow::ToOwned,
boxed::Box,
format,
string::{String, ToString},
sync::Arc,
vec::Vec,
};
use critical_section::Mutex;
use alloc::{boxed::Box, format, string::ToString};
use esp_hal::{
clock::CpuClock,
delay::Delay,
gpio::{Input, InputConfig, Level, Output, OutputConfig},
gpio::{InputConfig, Level, Output, OutputConfig},
interrupt::software::SoftwareInterruptControl,
main,
spi::master::{Config, Spi},
@ -291,6 +281,12 @@ fn thread_2_main(async_io: AsyncIO, mut at_commands: ATCommands<'static, 'static
async_io::ATCommand::ListTECharacterSets => {
at_commands.raw_command("AT+CSCS=?".to_string())
}
async_io::ATCommand::SetTECharSet(charset) => {
at_commands.raw_command(format!("AT+CSCS=\"{}\"", charset.into_str()))
}
async_io::ATCommand::SendSMS(da, text) => {
at_commands.raw_two_part_command(format!("AT+CMGS={}", da), text)
}
};
unsafe { async_io.set_at_response(response) };
}

View File

@ -9,7 +9,7 @@ use alloc::{
use esp_hal::time::{Duration, Instant};
use crate::{
async_io::{ATCommand, SMSFormat},
async_io::{ATCommand, Charset, SMSFormat},
display::{Position, Rgb565},
font::{HorizontalAlignment, VerticalAlignment},
state::{State, StateData, TextSettings},
@ -82,6 +82,13 @@ impl State for InitATState {
self.message = "Selecting SMS\nformat".to_owned();
None
}
5 => {
data.io
.send_at_command(ATCommand::SetTECharSet(Charset::IRA))
.unwrap();
self.message = "Selecting SMS\nformat".to_owned();
None
}
_ => {
data.delay.delay_millis(1000);
Some(Box::new(TextState {
@ -90,7 +97,7 @@ impl State for InitATState {
}
};
self.inner_state = (self.inner_state + 1).min(7);
self.inner_state = (self.inner_state + 1).min(200);
res
}