Skip to content

Commit

Permalink
docs: add: get_pwm_enable example
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulTrombin committed Dec 6, 2023
1 parent 5d51dc4 commit 6255c0a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
11 changes: 6 additions & 5 deletions examples/raspberry-pi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ use std::thread::sleep;
use std::time::Duration;

fn main() {
println!("Creating your navigator module!");
let mut nav = Navigator::new();

println!("Setting up your navigator, ahoy!");
nav.init();

loop {
nav.set_pwm_channel_value(PwmChannel::All, 0);
println!("{:#?}", nav.fmt_debug());
let previous = nav.get_pwm_enable();
println!("Enable pin logic value is {previous}.");
nav.set_pwm_enable(!previous);

println!("Enable pin logic value is {}.", nav.get_pwm_enable());

sleep(Duration::from_millis(1000));
}
}
25 changes: 24 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ impl Navigator {
.expect("Error : Error on magnetometer during self-test")
}

/// Sets the PWM IC to be enabled through firmware and OE_pin.
/// Sets the PWM IC to be enabled through OE_pin.
///
/// # Arguments
///
Expand All @@ -412,6 +412,29 @@ impl Navigator {
}
}

/// Get the PWM IC enabling value through OE_pin.
///
/// # Examples
///
/// ```no_run
/// use navigator_rs::{Navigator};
/// use std::thread::sleep;
/// use std::time::Duration;
///
/// let mut nav = Navigator::new();
///
/// nav.init();
/// loop {
/// let previous = nav.get_pwm_enable();
/// println!("Enable pin logic value is {previous}.");
///
/// nav.set_pwm_enable(!previous);
///
/// println!("Enable pin logic value is {}.", nav.get_pwm_enable());
///
/// sleep(Duration::from_millis(1000));
/// }
/// ```
pub fn get_pwm_enable(&mut self) -> bool {
self.pwm.oe_pin.get_value().expect("Error: Get PWM value") == 1
}
Expand Down

0 comments on commit 6255c0a

Please sign in to comment.