forked from M-Labs/thermostat
set pwm values as ratio 0..1
This commit is contained in:
parent
35af543e33
commit
ec6aa03dc3
|
@ -52,10 +52,10 @@ The scope of this setting is per TCP session.
|
|||
| `report mode` | Show current report mode |
|
||||
| `report mode <off/on>` | Set report mode |
|
||||
| `pwm` | Show current PWM settings |
|
||||
| `pwm <0/1> max_i_pos <width>` | Set PWM duty cycle for **max_i_pos** to *width* |
|
||||
| `pwm <0/1> max_i_neg <width>` | Set PWM duty cycle for **max_i_neg** to *width* |
|
||||
| `pwm <0/1> max_v <width>` | Set PWM duty cycle for **max_v** to *width* |
|
||||
| `pwm <0/1> <width>` | Disengage PID, set **i_set** DAC to *width* |
|
||||
| `pwm <0/1> max_i_pos <ratio>` | Set PWM duty cycle for **max_i_pos** to *ratio* |
|
||||
| `pwm <0/1> max_i_neg <ratio>` | Set PWM duty cycle for **max_i_neg** to *ratio* |
|
||||
| `pwm <0/1> max_v <ratio>` | Set PWM duty cycle for **max_v** to *ratio* |
|
||||
| `pwm <0/1> <volts>` | 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 <value>` | Set the PID controller target |
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -273,13 +273,13 @@ fn main() -> ! {
|
|||
);
|
||||
}
|
||||
Command::Pwm { channel, pin, duty } => {
|
||||
let duty = duty as u16;
|
||||
|
||||
fn set_pwm_channel<P: hal::PwmPin<Duty=u16>>(pin: &mut P, duty: u16) -> u16 {
|
||||
pin.set_duty(duty);
|
||||
pin.get_max_duty()
|
||||
fn set_pwm_channel<P: hal::PwmPin<Duty=u16>>(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 } => {
|
||||
|
|
Loading…
Reference in New Issue