implement self test mode request

This commit is contained in:
Robert 2022-12-19 00:11:11 +01:00
parent 31d1df64ef
commit ab1d4403c9
2 changed files with 37 additions and 1 deletions

View file

@ -115,6 +115,42 @@ impl B15F {
Ok(port)
}
/// Tries to reestablish a connection to the B15
pub fn reconnect(&mut self) -> Result<(), Error> {
let tries = 3;
while tries > 0 {
sleep(Duration::from_millis(64));
self.discard()?;
match self.test_connection() {
Ok(_) => return Ok(()),
Err(_) => { }
};
}
Err("Connection could not be repaired".into())
}
/// Enables the self test mode of the B15
///
/// IMPORTANT: Nothing must be connected to the B15 during this self check
/// routine.
///
/// # Errors
/// This function returns an `error::Error` when communication with
/// the board or the self check fails.
pub fn self_test(&mut self) -> Result<(), Error> {
self.usart.write(build_request!(Request::SelfTest))?;
let aw = read_sized::<1>(&mut self.usart)?;
if aw[0] != B15F::MSG_OK {
return Err("Self test failed".into())
}
Ok(())
}
/// Sets the value of the specified port
///
/// # Errors

View file

@ -21,7 +21,7 @@ pub enum Request {
Test = 1,
Info = 2,
IntTest = 3,
SelfTest = 4,
DigitalWrite0 = 5,
DigitalWrite1 = 6,
DigitalRead0 = 7,