pub fn scan_cb<F>(&mut self, mut on_response: F) -> Result<(), WriteError>
	where
		F: FnMut(Result<PingResponse, ReadError>),
	{
		self.write_instruction(packet_id::BROADCAST, instruction_id::PING, 0, |_| ())?;

		// TODO: See if we can terminate quicker.
		// Peek at the official SDK to see what they do.

		for _ in 0..253 {
			let response = self.read_status_response();
			if let Err(ReadError::Io(e)) = &response {
				if e.kind() == std::io::ErrorKind::TimedOut {
					continue;
				}
			}
			let response = response.and_then(|response| {
				crate::InvalidParameterCount::check(response.parameters().len(), 3)?;
				Ok(parse_ping_response(response.packet_id(), response.parameters()))
			});
			on_response(response);
		}

		Ok(())
	}
/// Scan a bus for motors with a broadcast ping, calling an [`FnMut`] for each response.
///
/// Only timeouts are filtered out since they indicate a lack of response.
/// All other responses (including errors) are passed to the handler.
Scan a bus for motors with a broadcast ping, calling an [`FnMut`] for each response.
Only timeouts are filtered out since they indicate a lack of response.
All other responses (including errors) are passed to the handler.
Scan a bus for motors with a broadcast ping calling an [ ` FnMut ` ] for each response . Only timeouts are filtered out since they indicate a lack of response . All other responses ( including errors ) are passed to the handler .
pub fn scan_cb<F>(&mut self, mut on_response: F) -> Result<(), WriteError>
	where
		F: FnMut(Result<PingResponse, ReadError>),
	{
		self.write_instruction(packet_id::BROADCAST, instruction_id::PING, 0, |_| ())?;
		// TODO: See if we can terminate quicker.
		// Peek at the official SDK to see what they do.
		for _ in 0..253 {
			let response = self.read_status_response();
			if let Err(ReadError::Io(e)) = &response {
				if e.kind() == std::io::ErrorKind::TimedOut {
					continue;
				}
			}
			let response = response.and_then(|response| {
				crate::InvalidParameterCount::check(response.parameters().len(), 3)?;
				Ok(parse_ping_response(response.packet_id(), response.parameters()))
			});
			on_response(response);
		}
		Ok(())
	}
pub fn scan_cb < F > ( & mut self , mut on_response : F ) -> Result < ( ) , WriteError > where F : FnMut ( Result < PingResponse , ReadError > ) , { self . write_instruction ( packet_id :: BROADCAST , instruction_id :: PING , 0 , | _ | ( ) ) ? ; // TODO: See if we can terminate quicker. // Peek at the official SDK to see what they do. for _ in 0 .. 253 { let response = self . read_status_response ( ) ; if let Err ( ReadError :: Io ( e ) ) = & response { if e . kind ( ) == std :: io :: ErrorKind :: TimedOut { continue ; } } let response = response . and_then ( | response | { crate :: InvalidParameterCount :: check ( response . parameters ( ) . len ( ) , 3 ) ? ; Ok ( parse_ping_response ( response . packet_id ( ) , response . parameters ( ) ) ) } ) ; on_response ( response ) ; } Ok ( ( ) ) }
Scan a bus for motors with a broadcast ping, calling an [`FnMut`] for each response.
Scan a bus for motors with a broadcast ping calling an [ ` FnMut ` ] for each response .
&mut self
on_response
F
&mut self
on_response
F