diff --git a/README.md b/README.md index 018bf52..c507035 100644 --- a/README.md +++ b/README.md @@ -52,10 +52,10 @@ The scope of this setting is per TCP session. | `report mode` | Show current report mode | | `report mode ` | Set report mode | | `pwm` | Show current PWM settings | -| `pwm <0/1> max_i_pos ` | Set PWM duty cycle for **max_i_pos** to *width* | -| `pwm <0/1> max_i_neg ` | Set PWM duty cycle for **max_i_neg** to *width* | -| `pwm <0/1> max_v ` | Set PWM duty cycle for **max_v** to *width* | -| `pwm <0/1> ` | Disengage PID, set **i_set** DAC to *width* | +| `pwm <0/1> max_i_pos ` | Set PWM duty cycle for **max_i_pos** to *ratio* | +| `pwm <0/1> max_i_neg ` | Set PWM duty cycle for **max_i_neg** to *ratio* | +| `pwm <0/1> max_v ` | Set PWM duty cycle for **max_v** to *ratio* | +| `pwm <0/1> ` | Disengage PID, set **i_set** DAC to *volts* | | `pwm <0/1> pid` | Set PWM to be controlled by PID | | `pid` | Show PID configuration | | `pid <0/1> target ` | Set the PID controller target | diff --git a/src/main.rs b/src/main.rs index 6faa96b..84a2b00 100644 --- a/src/main.rs +++ b/src/main.rs @@ -273,13 +273,13 @@ fn main() -> ! { ); } Command::Pwm { channel, pin, duty } => { - let duty = duty as u16; - - fn set_pwm_channel>(pin: &mut P, duty: u16) -> u16 { - pin.set_duty(duty); - pin.get_max_duty() + fn set_pwm_channel>(pin: &mut P, duty: f64) -> (u16, u16) { + let max = pin.get_max_duty(); + let value = (duty * (max as f64)) as u16; + pin.set_duty(value); + (value, max) } - let max = match (channel, pin) { + let (value, max) = match (channel, pin) { (_, PwmPin::ISet) => // Handled above unreachable!(), @@ -300,7 +300,7 @@ fn main() -> ! { }; let _ = writeln!( socket, "channel {}: PWM {} reconfigured to {}/{}", - channel, pin.name(), duty, max + channel, pin.name(), value, max ); } Command::Pid { channel, parameter, value } => {