From 5c8bb47e119d2517b655336d5dbd7e65d74b0431 Mon Sep 17 00:00:00 2001 From: Astro Date: Wed, 9 Dec 2020 01:07:08 +0100 Subject: [PATCH] command_parser: require the explicit `i_set` symbol --- README.md | 16 ++++++++-------- src/command_parser.rs | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 58dd1d5..47d98be 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ The scope of this setting is per TCP session. | `pwm <0/1> max_i_pos ` | Set PWM duty cycle for **max_i_pos** to *ampere* | | `pwm <0/1> max_i_neg ` | Set PWM duty cycle for **max_i_neg** to *ampere* | | `pwm <0/1> max_v ` | Set PWM duty cycle for **max_v** to *volt* | -| `pwm <0/1> ` | Disengage PID, set **i_set** DAC to *ampere* | +| `pwm <0/1> i_set ` | Disengage PID, set **i_set** DAC to *ampere* | | `pwm <0/1> pid` | Set PWM to be controlled by PID | | `center <0/1> ` | Set the MAX1968 0A-centerpoint to *volts* | | `center <0/1> vref` | Set the MAX1968 0A-centerpoint to measure from VREF | @@ -146,12 +146,12 @@ output limits. Use the `pwm` command to see current settings and maximum values. -| Limit | Unit | Description | -| --- | :---: | --- | -| `max_v` | Volts | Maximum voltage | -| `max_i_pos` | Amperes | Maximum positive current | -| `max_i_neg` | Amperes | Maximum negative current | -| | Amperes | Output current control (Open-loop mode) | +| Limit | Unit | Description | +| --- | :---: | --- | +| `max_v` | Volts | Maximum voltage | +| `max_i_pos` | Amperes | Maximum positive current | +| `max_i_neg` | Amperes | Maximum negative current | +| `i_set` | Amperes | (Not a limit; Open-loop mode) | Example: set the maximum voltage of channel 0 to 1.5 V. ``` @@ -166,7 +166,7 @@ channel. Example: set output current of channel 0 to 0 A. ``` -pwm 0 0 +pwm 0 i_set 0 ``` ## PID-stabilized temperature control diff --git a/src/command_parser.rs b/src/command_parser.rs index 8cc7aa4..a71ddc4 100644 --- a/src/command_parser.rs +++ b/src/command_parser.rs @@ -249,6 +249,16 @@ fn pwm_setup(input: &[u8]) -> IResult<&[u8], Result<(PwmPin, f64), Error>> { result.map(|value| (pin, value)); alt(( + map( + preceded( + tag("i_set"), + preceded( + whitespace, + float + ) + ), + result_with_pin(PwmPin::ISet) + ), map( preceded( tag("max_i_pos"), @@ -278,8 +288,6 @@ fn pwm_setup(input: &[u8]) -> IResult<&[u8], Result<(PwmPin, f64), Error>> { ) ), result_with_pin(PwmPin::MaxV) - ), - map(float, result_with_pin(PwmPin::ISet) )) )(input) } @@ -528,8 +536,8 @@ mod test { } #[test] - fn parse_pwm_manual() { - let command = Command::parse(b"pwm 1 16383"); + fn parse_pwm_i_set() { + let command = Command::parse(b"pwm 1 i_set 16383"); assert_eq!(command, Ok(Command::Pwm { channel: 1, pin: PwmPin::ISet,