This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
57 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use core::time::Duration; | ||
|
||
use alloc::{format, string::ToString}; | ||
|
||
use log::{Log, Metadata, Record}; | ||
|
||
#[derive(Default)] | ||
pub struct ProsLogger; | ||
|
||
impl ProsLogger { | ||
pub fn init() -> Result<(), log::SetLoggerError> { | ||
log::set_logger(&ProsLogger)?; | ||
log::set_max_level(log::LevelFilter::Trace); | ||
|
||
unsafe { | ||
pros_sys::lcd_initialize(); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl Log for ProsLogger { | ||
fn enabled(&self, _: &Metadata) -> bool { | ||
true | ||
} | ||
|
||
fn log(&self, record: &Record) { | ||
let level_string = format!("{:<5}", record.level().to_string()); | ||
|
||
let target = if !record.target().is_empty() { | ||
record.target() | ||
} else { | ||
record.module_path().unwrap_or_default() | ||
}; | ||
|
||
let now = | ||
chrono::Duration::from_std(Duration::from_millis(unsafe { pros_sys::millis() as _ })) | ||
.unwrap(); | ||
|
||
let message = format!("{}{} [{}] {}", now, level_string, target, record.args()); | ||
|
||
println!("{}", message); | ||
// Print to the debug | ||
unsafe { | ||
pros_sys::puts(message.as_ptr() as _); | ||
} | ||
} | ||
|
||
fn flush(&self) {} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters