use core::str::FromStr;
use heapless::String;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum Parity {
#[default]
None,
Even,
Odd,
}
impl FromStr for Parity {
type Err = ();
fn from_str(value: &str) -> Result<Self, Self::Err> {
if value.eq_ignore_ascii_case("none") || value.eq_ignore_ascii_case("n") {
Ok(Self::None)
} else if value.eq_ignore_ascii_case("even") || value.eq_ignore_ascii_case("e") {
Ok(Self::Even)
} else if value.eq_ignore_ascii_case("odd") || value.eq_ignore_ascii_case("o") {
Ok(Self::Odd)
} else {
Err(())
}
}
}
impl From<u8> for Parity {
fn from(value: u8) -> Self {
match value {
1 => Self::Even,
2 => Self::Odd,
_ => Self::None,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct UartParams {
pub baud: u32,
pub data_bits: u8,
pub parity: Parity,
pub stop_bits: u8,
}
impl Default for UartParams {
fn default() -> Self {
Self {
baud: 115_200,
data_bits: 8,
parity: Parity::None,
stop_bits: 1,
}
}
}
#[derive(Clone, Debug, Default)]
pub struct UartConfig {
pub tx_pin: u8,
pub rx_pin: u8,
pub cts_pin: Option<u8>,
pub rts_pin: Option<u8>,
pub params: UartParams,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum BandMode {
#[default]
Band2_4G,
Band5G,
Auto,
}
impl FromStr for BandMode {
type Err = ();
fn from_str(value: &str) -> Result<Self, Self::Err> {
if value.eq_ignore_ascii_case("2.4g")
|| value.eq_ignore_ascii_case("2g")
|| value.eq_ignore_ascii_case("24g")
{
Ok(Self::Band2_4G)
} else if value.eq_ignore_ascii_case("5g") {
Ok(Self::Band5G)
} else if value.eq_ignore_ascii_case("auto") {
Ok(Self::Auto)
} else {
Err(())
}
}
}
impl From<u8> for BandMode {
fn from(value: u8) -> Self {
match value {
1 => Self::Band5G,
2 => Self::Auto,
_ => Self::Band2_4G,
}
}
}
#[derive(Clone, Debug)]
pub struct WifiApConfigStatic {
pub ap_ssid: String<32>,
pub sta_ssid: String<32>,
pub ap_password: String<63>,
pub sta_password: String<63>,
pub channel: u8,
pub band: BandMode,
pub mac: [u8; 6],
}
impl Default for WifiApConfigStatic {
fn default() -> Self {
Self {
ap_ssid: String::new(),
ap_password: String::new(),
sta_ssid: String::new(),
sta_password: String::new(),
channel: 1,
band: BandMode::default(),
mac: [0; 6],
}
}
}