bug hunting xD

This commit is contained in:
puckoprutt 2026-07-13 19:35:04 +02:00
parent a74c2f1aec
commit 871a4cb7af
2 changed files with 14 additions and 11 deletions

View File

@ -319,13 +319,14 @@ impl Terminal {
Self::write(b"\x1B[0m"); 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 { match loglevel {
30..=39 => Self::pp_danger(data.as_bytes()), 30..=39 => Self::pp_danger(data.as_bytes()),
20..=29 => Self::pp_warning(data.as_bytes()), 20..=29 => Self::pp_warning(data.as_bytes()),
10..=19 => Self::pp_info(data.as_bytes()), 10..=19 => Self::pp_info(data.as_bytes()),
_ => Self::pp_debug(data.as_bytes()), _ => Self::pp_debug(data.as_bytes()),
} }
Self::write(b"\r\n");
} }
/// clears the screen with a simple ANSI sequence. /// clears the screen with a simple ANSI sequence.

View File

@ -9,6 +9,7 @@
//! let argument1 = message.get_word(1); //! let argument1 = message.get_word(1);
//! let argument2 = message.get_word(2); //! let argument2 = message.get_word(2);
//! ``` //! ```
use heapless::String; use heapless::String;
use heapless::Vec; use heapless::Vec;
use cortex_m::asm; use cortex_m::asm;
@ -55,7 +56,7 @@ pub struct UsbMessage {
/// the line /// the line
pub words: usize, pub words: usize,
/// the length /// the length
pub message: [u8; 128] pub message: Vec<UsbWord, 8>,
} }
impl UsbMessage { impl UsbMessage {
@ -65,9 +66,15 @@ impl UsbMessage {
Terminal::pp_info(b"got: something"); Terminal::pp_info(b"got: something");
Terminal::user_prompt(); Terminal::user_prompt();
let msg: &[u8; 128] = s.trim(); let msg: &[u8; 128] = s.trim();
let words = Self::count_word(msg);
let mut message = Vec::<UsbWord, 8>::new();
for i in 0..words {
let _ = message.push(Self::get_word(msg, words, i).unwrap());
}
Self { Self {
words : Self::count_word(msg), 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. /// gets the word provided or None if out of bounds.
pub fn get_word(&mut self, index: usize) -> Option<UsbWord> { fn get_word(message: &[u8], words: usize, index: usize) -> Option<UsbWord> {
if index > self.words { return None; } if index > words { return None; }
let mut word: usize = 0; let mut word: usize = 0;
let mut ret_index: usize = 0; let mut ret_index: usize = 0;
let mut ret = Vec::<u8, 16>::new(); let mut ret = Vec::<u8, 16>::new();
self.message.iter().take(self.message.len()).for_each(|w| { message.iter().take(message.len()).for_each(|w| {
if *w == 0x0 { asm::nop(); } if *w == 0x0 { asm::nop(); }
else if *w == 0x20 { else if *w == 0x20 {
word += 1; word += 1;