diff --git a/src/codec/command.rs b/src/codec/command.rs index e680dd4..706b899 100644 --- a/src/codec/command.rs +++ b/src/codec/command.rs @@ -1,4 +1,7 @@ -use crate::codec::misc::Backlight; +use crate::{ + KeyBeepSettings, PriorityMode, + codec::misc::{Backlight, BandPlan}, +}; #[derive(Clone, Copy, Debug, strum::IntoStaticStr)] #[strum(serialize_all = "UPPERCASE")] @@ -16,20 +19,22 @@ pub enum Command { Ver, // System settings - /// Get/set backlight + /// Get/set backlight trigger event Blt(Option), - /// Get/set battery save + /// Get/set battery charge time Bsv(Option), /// Clear all memory /// /// Takes about 20 seconds to execute Clr, /// Get/set band plan - Bpl, + /// + /// Affects frequency step. Issue before frequency programming. + Bpl(Option), /// Get/set key beep - Kbp, // TODO: optional param + Kbp(Option), // TODO: optional param /// Get/set priority mode - Pri, // TODO: optional param + Pri(Option), // TODO: optional param // Scan Settings // Scg, diff --git a/src/codec/misc.rs b/src/codec/misc.rs index ea14658..1f53659 100644 --- a/src/codec/misc.rs +++ b/src/codec/misc.rs @@ -11,3 +11,37 @@ pub enum Backlight { #[strum(to_string = "KS")] KeySquelch, } + +#[derive(Clone, Copy, Debug, strum::IntoStaticStr, strum::EnumString)] +pub enum BandPlan { + #[strum(to_string = "0")] + Usa, + #[strum(to_string = "1")] + Canada, +} + +#[derive(Clone, Copy, Debug)] +pub struct KeyBeepSettings { + pub beep_level: KeyBeepLevel, + pub lock_status: bool, +} + +#[derive(Clone, Copy, Debug, strum::IntoStaticStr, strum::EnumString)] +pub enum KeyBeepLevel { + #[strum(to_string = "0")] + Auto, + #[strum(to_string = "99")] + Off, +} + +#[derive(Clone, Copy, Debug, strum::IntoStaticStr, strum::EnumString)] +pub enum PriorityMode { + #[strum(to_string = "0")] + Off, + #[strum(to_string = "1")] + On, + #[strum(to_string = "2")] + PlusOn, + #[strum(to_string = "3")] + Dnd, +} diff --git a/src/codec/mod.rs b/src/codec/mod.rs index ed5a839..0bfdbc5 100644 --- a/src/codec/mod.rs +++ b/src/codec/mod.rs @@ -7,7 +7,7 @@ use bytes::BufMut; use tokio_util::codec::{AnyDelimiterCodec, Decoder, Encoder}; pub use command::Command; -pub use misc::Backlight; +pub use misc::{Backlight, KeyBeepLevel, KeyBeepSettings, PriorityMode}; #[derive(Clone, Debug)] pub struct Codec { @@ -56,6 +56,16 @@ impl Encoder for Codec { */ write!(dst, ",{battery_save}").unwrap(); } + Command::Kbp(Some(key_beep_settings)) => { + let beep_level: &'static str = key_beep_settings.beep_level.into(); + write!(dst, ",{beep_level}").unwrap(); + let key_lock = if key_beep_settings.lock_status { + "1" + } else { + "0" + }; + write!(dst, ",{key_lock}").unwrap(); + } _ => (), } diff --git a/src/lib.rs b/src/lib.rs index 396fe44..1098742 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ use tokio_util::codec::{AnyDelimiterCodecError, Framed}; use crate::codec::Codec; -pub use crate::codec::{Backlight, Command}; +pub use crate::codec::{Backlight, Command, KeyBeepLevel, KeyBeepSettings, PriorityMode}; const VENDOR_ID: u16 = 0x1965; const PRODUCT_ID: u16 = 0x0017; diff --git a/src/main.rs b/src/main.rs index e47d00e..06f2294 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use uniden::{Backlight, Command, Scanner}; +use uniden::{Command, KeyBeepLevel, KeyBeepSettings, Scanner}; #[tokio::main] async fn main() -> Result<(), Box> { @@ -7,13 +7,15 @@ async fn main() -> Result<(), Box> { dbg!(scanner.firmware_version().await?); dbg!(scanner.command(Command::Prg).await?); // tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await; - dbg!(scanner.command(Command::Blt(None)).await?); dbg!( scanner - .command(Command::Blt(Some(Backlight::KeySql))) + .command(Command::Kbp(Some(KeyBeepSettings { + beep_level: KeyBeepLevel::Auto, + lock_status: false, + }))) .await? ); - dbg!(scanner.command(Command::Blt(None)).await?); + dbg!(scanner.command(Command::Kbp(None)).await?); dbg!(scanner.command(Command::Epg).await?); Ok(()) }