Skip to content

Commit

Permalink
Implement clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
golemparts committed Jan 30, 2023
1 parent 33f794c commit 9010c85
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/gpio/epoll.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::unnecessary_cast)]
#![allow(dead_code)]

use std::io;
Expand Down
4 changes: 2 additions & 2 deletions src/gpio/hal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl embedded_hal_0::PwmPin for OutputPin {
}

fn set_duty(&mut self, duty: Self::Duty) {
self.duty_cycle = duty.max(0.0).min(1.0);
self.duty_cycle = duty.clamp(0.0, 1.0);

if self.soft_pwm.is_some() {
let _ = self.set_pwm_frequency(self.frequency, self.duty_cycle);
Expand Down Expand Up @@ -217,7 +217,7 @@ impl embedded_hal_0::PwmPin for IoPin {
}

fn set_duty(&mut self, duty: Self::Duty) {
self.duty_cycle = duty.max(0.0).min(1.0);
self.duty_cycle = duty.clamp(0.0, 1.0);

if self.soft_pwm.is_some() {
let _ = self.set_pwm_frequency(self.frequency, self.duty_cycle);
Expand Down
4 changes: 2 additions & 2 deletions src/gpio/hal_unproven.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl embedded_hal_0::Pwm for OutputPin {

/// Sets a new duty cycle.
fn set_duty(&mut self, _channel: Self::Channel, duty: Self::Duty) {
self.duty_cycle = duty.max(0.0).min(1.0);
self.duty_cycle = duty.clamp(0.0, 1.0);

if self.soft_pwm.is_some() {
let _ = self.set_pwm_frequency(self.frequency, self.duty_cycle);
Expand Down Expand Up @@ -199,7 +199,7 @@ impl embedded_hal_0::Pwm for IoPin {

/// Sets a new duty cycle.
fn set_duty(&mut self, _channel: Self::Channel, duty: Self::Duty) {
self.duty_cycle = duty.max(0.0).min(1.0);
self.duty_cycle = duty.clamp(0.0, 1.0);

if self.soft_pwm.is_some() {
let _ = self.set_pwm_frequency(self.frequency, self.duty_cycle);
Expand Down
8 changes: 4 additions & 4 deletions src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl Pwm {
} else {
(1.0 / frequency) * NANOS_PER_SEC
};
let pulse_width = period * duty_cycle.max(0.0).min(1.0);
let pulse_width = period * duty_cycle.clamp(0.0, 1.0);

sysfs::set_period(channel as u8, period as u64)?;
sysfs::set_pulse_width(channel as u8, pulse_width as u64)?;
Expand Down Expand Up @@ -365,7 +365,7 @@ impl Pwm {
} else {
(1.0 / frequency) * NANOS_PER_SEC
};
let pulse_width = period * duty_cycle.max(0.0).min(1.0);
let pulse_width = period * duty_cycle.clamp(0.0, 1.0);

sysfs::set_period(self.channel as u8, period as u64)?;
sysfs::set_pulse_width(self.channel as u8, pulse_width as u64)?;
Expand All @@ -385,7 +385,7 @@ impl Pwm {
Ok(if period == 0.0 {
0.0
} else {
(pulse_width / period).max(0.0).min(1.0)
(pulse_width / period).clamp(0.0, 1.0)
})
}

Expand All @@ -397,7 +397,7 @@ impl Pwm {
/// `duty_cycle` is specified as a floating point value between `0.0` (0%) and `1.0` (100%).
pub fn set_duty_cycle(&self, duty_cycle: f64) -> Result<()> {
let period = sysfs::period(self.channel as u8)? as f64;
let pulse_width = period * duty_cycle.max(0.0).min(1.0);
let pulse_width = period * duty_cycle.clamp(0.0, 1.0);

sysfs::set_pulse_width(self.channel as u8, pulse_width as u64)?;

Expand Down

0 comments on commit 9010c85

Please sign in to comment.