Skip to content

Commit

Permalink
src: lib: Change logger to be optional using it's own method
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulTrombin committed Sep 14, 2023
1 parent 2ded610 commit 5c9bee5
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use linux_embedded_hal::spidev::{self, SpidevOptions};
use linux_embedded_hal::sysfs_gpio::Direction;
use linux_embedded_hal::I2cdev;
use linux_embedded_hal::{Delay, Pin, Spidev};
use log::{info, warn};
use log::{error, info, warn};
use nb::block;
use pwm_pca9685::{Address as pwm_Address, Pca9685};
use sk6812_rpi::led::Led as StripLed;
Expand Down Expand Up @@ -275,8 +275,6 @@ impl NavigatorBuilder {
}

pub fn build(self) -> Navigator {
env_logger::init();

let dev = I2cdev::new("/dev/i2c-4").unwrap();
let address = pwm_Address::default();
let pwm = Pca9685::new(dev, address).unwrap();
Expand Down Expand Up @@ -384,6 +382,21 @@ impl Navigator {
self.led.set_led_all(false);
}

/// Initialize the log service. Which can display feedback for some processes.
/// The function will return a true value if initialized successfully.
pub fn init_logger(&self) -> bool {
match env_logger::try_init() {
Ok(_) => {
info!("Logger initialized successfully");
true
}
Err(e) => {
error!("Failed to initialize logger: {}", e);
false
}
}
}

pub fn self_test(&mut self) -> bool {
//Check if the sensors are attached by it's IDs,
//run self-test if they have.
Expand Down

0 comments on commit 5c9bee5

Please sign in to comment.