add dip switch
This commit is contained in:
parent
ab1d4403c9
commit
3c8b790e7f
|
@ -3,6 +3,9 @@ use b15f::b15f::B15F;
|
||||||
fn main() -> Result<(), String> {
|
fn main() -> Result<(), String> {
|
||||||
let mut drv = B15F::new()?;
|
let mut drv = B15F::new()?;
|
||||||
|
|
||||||
println!("{}", drv.digital_read::<0>().unwrap());
|
println!("BA-0: {:b}", drv.digital_read::<0>()?);
|
||||||
|
println!("BA-1: {:b}", drv.digital_read::<1>()?);
|
||||||
|
println!("DIP : {:b}", drv.read_dip_switch()?);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
29
src/b15f.rs
29
src/b15f.rs
|
@ -233,6 +233,35 @@ impl B15F {
|
||||||
Ok(u8::reverse_bits(aw[0]))
|
Ok(u8::reverse_bits(aw[0]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reads the value of the DIP switch (S7)
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
/// A bitfield representing the value of all 8 DIP switches. The least
|
||||||
|
/// significant bit represents switch 1.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// When communication with the board fails an `error::Error` is returned.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
/// ```
|
||||||
|
/// use b15f::B15F;
|
||||||
|
///
|
||||||
|
/// fn main() -> Result<(), String> {
|
||||||
|
/// let mut drv = B15F::new()?;
|
||||||
|
///
|
||||||
|
/// println!("{}", drv.read_dip_switch()?);
|
||||||
|
///
|
||||||
|
/// Ok(())
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
pub fn read_dip_switch(&mut self) -> Result<u8, Error> {
|
||||||
|
self.usart.clear(serialport::ClearBuffer::Input)?;
|
||||||
|
self.usart.write(build_request!(Request::ReadDipSwitch))?;
|
||||||
|
|
||||||
|
let aw = read_sized::<1>(&mut self.usart)?;
|
||||||
|
Ok(aw[0].reverse_bits())
|
||||||
|
}
|
||||||
|
|
||||||
/// Yields information about the installed firmware on the B15
|
/// Yields information about the installed firmware on the B15
|
||||||
///
|
///
|
||||||
/// Returns an array of strings, where each string contains a piece
|
/// Returns an array of strings, where each string contains a piece
|
||||||
|
|
|
@ -25,5 +25,6 @@ pub enum Request {
|
||||||
DigitalWrite0 = 5,
|
DigitalWrite0 = 5,
|
||||||
DigitalWrite1 = 6,
|
DigitalWrite1 = 6,
|
||||||
DigitalRead0 = 7,
|
DigitalRead0 = 7,
|
||||||
DigitalRead1 = 8
|
DigitalRead1 = 8,
|
||||||
|
ReadDipSwitch = 9
|
||||||
}
|
}
|
Loading…
Reference in a new issue