main: add support for disabling postfilters

This commit is contained in:
Astro 2020-09-26 01:29:35 +02:00
parent 61d2cd6ecf
commit 97a09e422b
3 changed files with 44 additions and 12 deletions

View File

@ -70,6 +70,8 @@ The scope of this setting is per TCP session.
| `pid <0/1> integral_max <value>` | Set integral upper bound |
| `s-h` | Show Steinhart-Hart equation parameters |
| `s-h <0/1> <t/b/r0> <value>` | Set Steinhart-Hart parameter for a channel |
| `postfilter` | Show postfilter settings |
| `postfilter <0/1> off` | Disable postfilter |
| `postfilter <0/1> rate <rate>` | Set postfilter output data rate |
| `load` | Restore configuration from EEPROM |
| `save` | Save configuration to EEPROM |

View File

@ -164,7 +164,7 @@ pub enum Command {
},
PostFilter {
channel: usize,
rate: f32,
rate: Option<f32>,
},
}
@ -392,16 +392,24 @@ fn postfilter(input: &[u8]) -> IResult<&[u8], Result<Command, Error>> {
|input| {
let (input, channel) = channel(input)?;
let (input, _) = whitespace(input)?;
alt((
value(Ok(Command::PostFilter {
channel,
rate: None,
}), tag("off")),
move |input| {
let (input, _) = tag("rate")(input)?;
let (input, _) = whitespace(input)?;
let (input, rate) = float(input)?;
let result = rate
.map(|rate| Command::PostFilter {
channel,
rate: rate as f32,
rate: Some(rate as f32),
});
Ok((input, result))
}
))(input)
}
),
value(Ok(Command::Show(ShowCommand::PostFilter)), end)
))(input)
@ -570,12 +578,27 @@ mod test {
}));
}
#[test]
fn parse_postfilter() {
let command = Command::parse(b"postfilter");
assert_eq!(command, Ok(Command::Show(ShowCommand::PostFilter)));
}
#[test]
fn parse_postfilter_off() {
let command = Command::parse(b"postfilter 1 off");
assert_eq!(command, Ok(Command::PostFilter {
channel: 1,
rate: None,
}));
}
#[test]
fn parse_postfilter_rate() {
let command = Command::parse(b"postfilter 0 rate 21");
assert_eq!(command, Ok(Command::PostFilter {
channel: 0,
rate: 21.0,
rate: Some(21.0),
}));
}

View File

@ -308,7 +308,7 @@ fn main() -> ! {
}
None => {
let _ = writeln!(
socket, "channel {}: no postfilter",
socket, "channel {}: postfilter disabled",
channel
);
}
@ -421,7 +421,14 @@ fn main() -> ! {
}
let _ = writeln!(socket, "Steinhart-Hart equation parameter updated");
}
Command::PostFilter { channel, rate } => {
Command::PostFilter { channel, rate: None } => {
channels.adc.set_postfilter(channel as u8, None).unwrap();
let _ = writeln!(
socket, "channel {}: postfilter disabled",
channel
);
}
Command::PostFilter { channel, rate: Some(rate) } => {
let filter = ad7172::PostFilter::closest(rate);
match filter {
Some(filter) => {