From c880923a13c46da0588f2092fa14d93b0c5a9554 Mon Sep 17 00:00:00 2001 From: Raul Victor Trombin Date: Wed, 6 Dec 2023 12:22:17 -0300 Subject: [PATCH 1/5] src: lib: Change method pwm_enable to set_pwm_enable --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 4e14825ddd..e23c3ca513 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -404,7 +404,7 @@ impl Navigator { /// # Examples /// /// Please check [`set_pwm_channel_value`](struct.Navigator.html#method.set_pwm_channel_value). - pub fn pwm_enable(&mut self, state: bool) { + pub fn set_pwm_enable(&mut self, state: bool) { if state { self.pwm.oe_pin.set_direction(Direction::Low).unwrap(); } else { From 83f4c05b02607a23ee3578f6a67a2dbaa8c091e6 Mon Sep 17 00:00:00 2001 From: Raul Victor Trombin Date: Wed, 6 Dec 2023 12:26:59 -0300 Subject: [PATCH 2/5] src: lib: Add get_pwm_method --- src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index e23c3ca513..839c56f136 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -412,6 +412,10 @@ impl Navigator { } } + pub fn get_pwm_enable(&mut self) -> bool { + self.pwm.oe_pin.get_value().expect("Error: Get PWM value") == 1 + } + /// Sets the Duty Cycle (high value time) of selected channel. /// /// On PCA9685, this function sets the `OFF` counter and uses ON value as 0. From 9239508ddd27d3ccd82025ddf75f5c57eb712975 Mon Sep 17 00:00:00 2001 From: Raul Victor Trombin Date: Wed, 6 Dec 2023 12:31:46 -0300 Subject: [PATCH 3/5] benches: update and add new get_pwm_enable method --- benches/bench.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/benches/bench.rs b/benches/bench.rs index 7318c8ac0c..e1920479c9 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -29,7 +29,8 @@ fn navigator_benchmark(c: &mut Criterion) { bench!(read_all()); // Benchmark Outputs - bench!(pwm_enable(false)); + bench!(set_pwm_enable(false)); + bench!(get_pwm_enable()); bench!(set_pwm_channel_value(PwmChannel::Ch1, 100)); bench!(set_pwm_freq_hz(60.0)); bench!(set_pwm_freq_prescale(100)); From 5d51dc42fec7d666f6b988694e0f1343ed675b48 Mon Sep 17 00:00:00 2001 From: Raul Victor Trombin Date: Wed, 6 Dec 2023 13:00:36 -0300 Subject: [PATCH 4/5] src: lib: Update examples to use set_pwm_enable and fix ci tests --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 839c56f136..ef6276dbdd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -431,7 +431,7 @@ impl Navigator { /// let mut nav = Navigator::new(); /// /// nav.init(); - /// nav.pwm_enable(true); + /// nav.set_pwm_enable(true); /// /// nav.set_pwm_freq_prescale(99); // sets the pwm frequency to 60 Hz /// nav.set_pwm_channel_value(PwmChannel::Ch1, 2048); // sets the duty cycle to 50% @@ -457,7 +457,7 @@ impl Navigator { /// let mut nav = Navigator::new(); /// /// nav.init(); - /// nav.pwm_enable(true); + /// nav.set_pwm_enable(true); /// nav.set_pwm_freq_prescale(99); // sets the pwm frequency to 60 Hz /// /// let channels: [PwmChannel; 3] = [PwmChannel::Ch1, PwmChannel::Ch1, PwmChannel::Ch2]; @@ -486,7 +486,7 @@ impl Navigator { /// let mut nav = Navigator::new(); /// /// nav.init(); - /// nav.pwm_enable(true); + /// nav.set_pwm_enable(true); /// nav.set_pwm_freq_prescale(99); // sets the pwm frequency to 60 Hz /// /// let channels: [PwmChannel; 3] = [PwmChannel::Ch1, PwmChannel::Ch1, PwmChannel::Ch2]; @@ -535,7 +535,7 @@ impl Navigator { /// let mut nav = Navigator::new(); /// /// nav.init(); - /// nav.pwm_enable(true); + /// nav.set_pwm_enable(true); /// /// nav.set_pwm_freq_prescale(99); // sets the pwm frequency to 60 Hz /// @@ -567,7 +567,7 @@ impl Navigator { /// let mut nav = Navigator::new(); /// /// nav.init(); - /// nav.pwm_enable(true); + /// nav.set_pwm_enable(true); /// /// let mut i: f32 = 10.0; /// From 9b79e756ec093805507923b0bf54f83aab97b0b3 Mon Sep 17 00:00:00 2001 From: Raul Victor Trombin Date: Wed, 6 Dec 2023 13:36:21 -0300 Subject: [PATCH 5/5] docs: add: get_pwm_enable and fix at set_ pwm_enable --- src/lib.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index ef6276dbdd..00b98cae81 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 /// @@ -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 }