converted message::UsbWord.word from [u8; 16] to heapledd::String and added Terminal::pp_println
This commit is contained in:
parent
8f99bbdd6c
commit
f41750dde2
@ -58,10 +58,10 @@ fn main() -> ! {
|
||||
Terminal::clear_screen();
|
||||
Terminal::print_banner();
|
||||
for i in 0..msg.words {
|
||||
Terminal::pp_debug(&msg.get_word(i).unwrap().word);
|
||||
Terminal::pp_info(&msg.get_word(i).unwrap().word);
|
||||
Terminal::pp_warning(&msg.get_word(i).unwrap().word);
|
||||
Terminal::pp_danger(&msg.get_word(i).unwrap().word);
|
||||
Terminal::pp_println(&msg.get_word(i).unwrap().word, 0);
|
||||
Terminal::pp_println(&msg.get_word(i).unwrap().word, 10);
|
||||
Terminal::pp_println(&msg.get_word(i).unwrap().word, 20);
|
||||
Terminal::pp_println(&msg.get_word(i).unwrap().word, 30);
|
||||
}
|
||||
Terminal::user_prompt();
|
||||
}
|
||||
|
||||
10
src/lib.rs
10
src/lib.rs
@ -81,6 +81,7 @@ pub mod rx;
|
||||
use core::sync::atomic::{AtomicBool, AtomicU8, Ordering};
|
||||
use core::cell::RefCell;
|
||||
use critical_section::Mutex;
|
||||
use heapless::String;
|
||||
use heapless::spsc::Queue;
|
||||
use static_cell::StaticCell;
|
||||
use usb_device::class_prelude::UsbBusAllocator;
|
||||
@ -318,6 +319,15 @@ impl Terminal {
|
||||
Self::write(b"\x1B[0m");
|
||||
}
|
||||
|
||||
pub fn pp_println(data: String, 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()),
|
||||
}
|
||||
}
|
||||
|
||||
/// clears the screen with a simple ANSI sequence.
|
||||
pub fn clear_screen() {
|
||||
Self::write(b"\x1B[2J");
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
//! let argument1 = message.get_word(1);
|
||||
//! let argument2 = message.get_word(2);
|
||||
//! ```
|
||||
use heapless::String;
|
||||
use heapless::Vec;
|
||||
use cortex_m::asm;
|
||||
use super::Terminal;
|
||||
|
||||
@ -43,7 +45,7 @@ impl SliceExt for [u8; 128] {
|
||||
/// holds a word, each word can be 16 characters long max.
|
||||
pub struct UsbWord {
|
||||
/// the word.
|
||||
pub word: [u8; 16],
|
||||
pub word: String<16>,
|
||||
/// the length of the word.
|
||||
pub size: usize
|
||||
}
|
||||
@ -100,19 +102,20 @@ impl UsbMessage {
|
||||
if index > self.words { return None; }
|
||||
let mut word: usize = 0;
|
||||
let mut ret_index: usize = 0;
|
||||
let mut ret = [0u8; 16];
|
||||
let mut ret = Vec::<u8, 16>::new();
|
||||
self.message.iter().take(self.message.len()).for_each(|w| {
|
||||
if *w == 0x0 { asm::nop(); }
|
||||
else if *w == 0x20 {
|
||||
word += 1;
|
||||
}
|
||||
else if word == index {
|
||||
ret.push(*w).unwrap();
|
||||
ret[ret_index] = *w;
|
||||
ret_index += 1;
|
||||
}
|
||||
});
|
||||
Some(UsbWord{
|
||||
word: ret,
|
||||
word: String::from_utf8(ret).unwrap(),
|
||||
size: ret_index
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user