remove too detailed adc control
This commit is contained in:
parent
76e30c0f7c
commit
c50e1c7766
@ -52,31 +52,11 @@ pub enum Error {
|
|||||||
Parser,
|
Parser,
|
||||||
UnexpectedEnd,
|
UnexpectedEnd,
|
||||||
UnexpectedToken(Token),
|
UnexpectedToken(Token),
|
||||||
NoSuchChannel,
|
|
||||||
NoSuchSetup,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ShowCommand {
|
pub enum ShowCommand {
|
||||||
ReportMode,
|
ReportMode,
|
||||||
Channel(u8),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum ChannelCommand {
|
|
||||||
Enable,
|
|
||||||
Disable,
|
|
||||||
Setup(u8),
|
|
||||||
EnableInput(InputBuffer),
|
|
||||||
DisableInput(InputBuffer),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub enum InputBuffer {
|
|
||||||
RefPos,
|
|
||||||
RefNeg,
|
|
||||||
AinPos,
|
|
||||||
AinNeg,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -84,14 +64,8 @@ pub enum Command {
|
|||||||
Quit,
|
Quit,
|
||||||
Show(ShowCommand),
|
Show(ShowCommand),
|
||||||
Report(ReportMode),
|
Report(ReportMode),
|
||||||
Channel(u8, ChannelCommand),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const CHANNEL_IDS: &'static [&'static str] = &[
|
|
||||||
"0", "1", "2", "3",
|
|
||||||
];
|
|
||||||
const SETUP_IDS: &'static [&'static str] = CHANNEL_IDS;
|
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
pub fn parse(input: &str) -> Result<Self, Error> {
|
pub fn parse(input: &str) -> Result<Self, Error> {
|
||||||
let mut lexer = Token::lexer(input);
|
let mut lexer = Token::lexer(input);
|
||||||
@ -121,19 +95,6 @@ impl Command {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! channel_input {
|
|
||||||
($channel: expr, $input: tt) => {
|
|
||||||
choice![
|
|
||||||
End =>
|
|
||||||
Ok(Command::Show(ShowCommand::Channel($channel))),
|
|
||||||
Enable =>
|
|
||||||
end![Command::Channel($channel, ChannelCommand::EnableInput(InputBuffer::$input))],
|
|
||||||
Disable =>
|
|
||||||
end![Command::Channel($channel, ChannelCommand::DisableInput(InputBuffer::$input))],
|
|
||||||
]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Command grammar
|
// Command grammar
|
||||||
choice![
|
choice![
|
||||||
Quit => Ok(Command::Quit),
|
Quit => Ok(Command::Quit),
|
||||||
@ -146,37 +107,6 @@ impl Command {
|
|||||||
],
|
],
|
||||||
End => Ok(Command::Report(ReportMode::Once)),
|
End => Ok(Command::Report(ReportMode::Once)),
|
||||||
],
|
],
|
||||||
Channel => {
|
|
||||||
let channel = choice![
|
|
||||||
Number => {
|
|
||||||
CHANNEL_IDS.iter()
|
|
||||||
.position(|id| *id == lexer.slice())
|
|
||||||
.ok_or(Error::NoSuchChannel)
|
|
||||||
},
|
|
||||||
]? as u8;
|
|
||||||
choice![
|
|
||||||
End =>
|
|
||||||
Ok(Command::Show(ShowCommand::Channel(channel))),
|
|
||||||
Enable =>
|
|
||||||
Ok(Command::Channel(channel, ChannelCommand::Enable)),
|
|
||||||
Disable =>
|
|
||||||
Ok(Command::Channel(channel, ChannelCommand::Enable)),
|
|
||||||
Setup => {
|
|
||||||
let setup = choice![
|
|
||||||
Number => {
|
|
||||||
SETUP_IDS.iter()
|
|
||||||
.position(|id| *id == lexer.slice())
|
|
||||||
.ok_or(Error::NoSuchSetup)
|
|
||||||
},
|
|
||||||
]? as u8;
|
|
||||||
end!(Command::Channel(channel, ChannelCommand::Setup(setup)))
|
|
||||||
},
|
|
||||||
RefPos => channel_input!(channel, RefPos),
|
|
||||||
RefNeg => channel_input!(channel, RefNeg),
|
|
||||||
AinPos => channel_input!(channel, AinPos),
|
|
||||||
AinNeg => channel_input!(channel, AinNeg),
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,27 +244,6 @@ fn main() -> ! {
|
|||||||
Command::Show(ShowCommand::ReportMode) => {
|
Command::Show(ShowCommand::ReportMode) => {
|
||||||
let _ = writeln!(socket, "Report mode: {:?}", session.report_mode());
|
let _ = writeln!(socket, "Report mode: {:?}", session.report_mode());
|
||||||
}
|
}
|
||||||
Command::Show(ShowCommand::Channel(index)) => {
|
|
||||||
let _ = writeln!(socket, "Channel {:?} configuration", index);
|
|
||||||
adc.read_reg(&ad7172::regs::Channel { index })
|
|
||||||
.map(|data| {
|
|
||||||
let _ = writeln!(socket, "{} setup={}",
|
|
||||||
if data.enabled() { "enabled" } else { "disabled" },
|
|
||||||
data.setup()
|
|
||||||
);
|
|
||||||
let _ = writeln!(socket, "ain+={} ain-={}",
|
|
||||||
data.a_in_pos(), data.a_in_neg()
|
|
||||||
);
|
|
||||||
});
|
|
||||||
adc.read_reg(&ad7172::regs::SetupCon { index })
|
|
||||||
.map(|data| {
|
|
||||||
let _ = writeln!(socket, "{} burnout={}, ref={}",
|
|
||||||
if data.bi_unipolar() { "bipolar" } else { "unipolar" },
|
|
||||||
if data.burnout_en() { "enabled" } else { "disabled" },
|
|
||||||
data.ref_sel()
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
command => {
|
command => {
|
||||||
// TODO: remove for exhaustion check
|
// TODO: remove for exhaustion check
|
||||||
let _ = writeln!(socket, "Not implemented: {:?}", command);
|
let _ = writeln!(socket, "Not implemented: {:?}", command);
|
||||||
|
Loading…
Reference in New Issue
Block a user