diff --git a/src/lib.rs b/src/lib.rs index f3a8ff1..83395cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -319,13 +319,14 @@ impl Terminal { Self::write(b"\x1B[0m"); } - pub fn pp_println(data: String<16>, loglevel: u8) { + pub fn pp_logln(data: String<16>, loglevel: u8) { match loglevel { 30..=39 => Self::pp_danger(data.as_bytes()), 20..=29 => Self::pp_warning(data.as_bytes()), 10..=19 => Self::pp_info(data.as_bytes()), _ => Self::pp_debug(data.as_bytes()), } + Self::write(b"\r\n"); } /// clears the screen with a simple ANSI sequence. diff --git a/src/message.rs b/src/message.rs index a4c0f3b..68cdbf7 100644 --- a/src/message.rs +++ b/src/message.rs @@ -9,6 +9,7 @@ //! let argument1 = message.get_word(1); //! let argument2 = message.get_word(2); //! ``` + use heapless::String; use heapless::Vec; use cortex_m::asm; @@ -55,7 +56,7 @@ pub struct UsbMessage { /// the line pub words: usize, /// the length - pub message: [u8; 128] + pub message: Vec, } impl UsbMessage { @@ -65,9 +66,15 @@ impl UsbMessage { Terminal::pp_info(b"got: something"); Terminal::user_prompt(); let msg: &[u8; 128] = s.trim(); + let words = Self::count_word(msg); + let mut message = Vec::::new(); + + for i in 0..words { + let _ = message.push(Self::get_word(msg, words, i).unwrap()); + } Self { words : Self::count_word(msg), - message : msg.clone() + message : message } } @@ -92,18 +99,13 @@ impl UsbMessage { } } - /// gets the first word - pub fn get_command(&mut self) -> UsbWord { - self.get_word(0).unwrap() - } - /// gets the word provided or None if out of bounds. - pub fn get_word(&mut self, index: usize) -> Option { - if index > self.words { return None; } + fn get_word(message: &[u8], words: usize, index: usize) -> Option { + if index > words { return None; } let mut word: usize = 0; let mut ret_index: usize = 0; let mut ret = Vec::::new(); - self.message.iter().take(self.message.len()).for_each(|w| { + message.iter().take(message.len()).for_each(|w| { if *w == 0x0 { asm::nop(); } else if *w == 0x20 { word += 1;