Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
fix: make the shit actually work
Browse files Browse the repository at this point in the history
also fix naming and add to prelude
  • Loading branch information
Gavin-Niederman committed Dec 8, 2023
1 parent 7ef0e40 commit 01dc7f9
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 119 deletions.
2 changes: 2 additions & 0 deletions pros-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ extern "C" {
pub fn free(ptr: *mut core::ffi::c_void);
pub fn __errno() -> *mut i32;
pub fn clock() -> i32;
pub fn printf(__format: *const core::ffi::c_char,...) -> core::ffi::c_int;
pub fn puts(__s: *const core::ffi::c_char) -> core::ffi::c_int;
}
2 changes: 0 additions & 2 deletions pros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ snafu = { version = "0.7.5", default-features = false, features = [
"rust_1_61",
] }
no_std_io = { version = "0.6.0", features = ["alloc"] }
tracing = { version = "0.1.40", default-features = false }
tracing-subscriber = { version = "0.3.18", default-features = false, features = ["alloc"] }
log = "0.4.20"
chrono = { version = "0.4.31", default-features = false }

Expand Down
4 changes: 3 additions & 1 deletion pros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod lcd;
pub mod adi;
pub mod link;
pub mod lvgl;
mod tracing;
pub mod logger;

pub type Result<T = ()> = core::result::Result<T, alloc::boxed::Box<dyn core::error::Error>>;

Expand Down Expand Up @@ -176,4 +176,6 @@ pub mod prelude {
pub use crate::sensors::rotation::*;
pub use crate::sensors::vision::*;
pub use crate::task::{sleep, spawn};

pub use log::{debug, error, info, log, trace, warn};
}
51 changes: 51 additions & 0 deletions pros/src/logger.rs
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) {}
}
115 changes: 0 additions & 115 deletions pros/src/tracing.rs

This file was deleted.

2 changes: 1 addition & 1 deletion pros/src/wasm_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate alloc;
use core::panic::PanicInfo;

use alloc::{
alloc::{alloc, dealloc, handle_alloc_error, GlobalAlloc, Layout},
alloc::{alloc, dealloc, handle_alloc_error, Layout},
collections::BTreeMap,
ffi::CString,
format,
Expand Down

0 comments on commit 01dc7f9

Please sign in to comment.