main: add support for disabling postfilters
This commit is contained in:
parent
61d2cd6ecf
commit
97a09e422b
|
@ -70,6 +70,8 @@ The scope of this setting is per TCP session.
|
||||||
| `pid <0/1> integral_max <value>` | Set integral upper bound |
|
| `pid <0/1> integral_max <value>` | Set integral upper bound |
|
||||||
| `s-h` | Show Steinhart-Hart equation parameters |
|
| `s-h` | Show Steinhart-Hart equation parameters |
|
||||||
| `s-h <0/1> <t/b/r0> <value>` | Set Steinhart-Hart parameter for a channel |
|
| `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 |
|
| `postfilter <0/1> rate <rate>` | Set postfilter output data rate |
|
||||||
| `load` | Restore configuration from EEPROM |
|
| `load` | Restore configuration from EEPROM |
|
||||||
| `save` | Save configuration to EEPROM |
|
| `save` | Save configuration to EEPROM |
|
||||||
|
|
|
@ -164,7 +164,7 @@ pub enum Command {
|
||||||
},
|
},
|
||||||
PostFilter {
|
PostFilter {
|
||||||
channel: usize,
|
channel: usize,
|
||||||
rate: f32,
|
rate: Option<f32>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,16 +392,24 @@ fn postfilter(input: &[u8]) -> IResult<&[u8], Result<Command, Error>> {
|
||||||
|input| {
|
|input| {
|
||||||
let (input, channel) = channel(input)?;
|
let (input, channel) = channel(input)?;
|
||||||
let (input, _) = whitespace(input)?;
|
let (input, _) = whitespace(input)?;
|
||||||
|
alt((
|
||||||
|
value(Ok(Command::PostFilter {
|
||||||
|
channel,
|
||||||
|
rate: None,
|
||||||
|
}), tag("off")),
|
||||||
|
move |input| {
|
||||||
let (input, _) = tag("rate")(input)?;
|
let (input, _) = tag("rate")(input)?;
|
||||||
let (input, _) = whitespace(input)?;
|
let (input, _) = whitespace(input)?;
|
||||||
let (input, rate) = float(input)?;
|
let (input, rate) = float(input)?;
|
||||||
let result = rate
|
let result = rate
|
||||||
.map(|rate| Command::PostFilter {
|
.map(|rate| Command::PostFilter {
|
||||||
channel,
|
channel,
|
||||||
rate: rate as f32,
|
rate: Some(rate as f32),
|
||||||
});
|
});
|
||||||
Ok((input, result))
|
Ok((input, result))
|
||||||
}
|
}
|
||||||
|
))(input)
|
||||||
|
}
|
||||||
),
|
),
|
||||||
value(Ok(Command::Show(ShowCommand::PostFilter)), end)
|
value(Ok(Command::Show(ShowCommand::PostFilter)), end)
|
||||||
))(input)
|
))(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]
|
#[test]
|
||||||
fn parse_postfilter_rate() {
|
fn parse_postfilter_rate() {
|
||||||
let command = Command::parse(b"postfilter 0 rate 21");
|
let command = Command::parse(b"postfilter 0 rate 21");
|
||||||
assert_eq!(command, Ok(Command::PostFilter {
|
assert_eq!(command, Ok(Command::PostFilter {
|
||||||
channel: 0,
|
channel: 0,
|
||||||
rate: 21.0,
|
rate: Some(21.0),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -308,7 +308,7 @@ fn main() -> ! {
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let _ = writeln!(
|
let _ = writeln!(
|
||||||
socket, "channel {}: no postfilter",
|
socket, "channel {}: postfilter disabled",
|
||||||
channel
|
channel
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -421,7 +421,14 @@ fn main() -> ! {
|
||||||
}
|
}
|
||||||
let _ = writeln!(socket, "Steinhart-Hart equation parameter updated");
|
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);
|
let filter = ad7172::PostFilter::closest(rate);
|
||||||
match filter {
|
match filter {
|
||||||
Some(filter) => {
|
Some(filter) => {
|
||||||
|
|
Loading…
Reference in New Issue