Commit 1572b8ea authored by Simon Wörner's avatar Simon Wörner

poll return None on timeout

parent b97684f6
......@@ -197,13 +197,17 @@ impl AsyncPort {
.or(Err(Error::new(ErrorKind::Other, "open failed")))
}
pub fn poll(&mut self, timeout: Option<Duration>) -> std::io::Result<Value> {
pub fn poll(&mut self, timeout: Option<Duration>) -> std::io::Result<Option<Value>> {
let mut fds = [nix::poll::PollFd::new(self.file, nix::poll::POLLPRI, nix::poll::EventFlags::empty())];
let mut buffer: [u8; 1] = [0; 1];
nix::poll::poll(&mut fds, match timeout { None => -1, Some(t) => duration_to_ms(t) as i32})
let poll = nix::poll::poll(&mut fds, match timeout { None => -1, Some(t) => duration_to_ms(t) as i32})
.or(Err(Error::new(ErrorKind::Other, "poll failed")))?;
if poll == 0 {
return Ok(None);
}
nix::unistd::lseek(self.file, 0, nix::unistd::Whence::SeekSet)
.or(Err(Error::new(ErrorKind::Other, "lseek failed")))?;
......@@ -211,8 +215,8 @@ impl AsyncPort {
.or(Err(Error::new(ErrorKind::Other, "read failed")))?;
match buffer[0] {
48 => Ok(Value::Low), // '0'
49 => Ok(Value::High), // '1'
48 => Ok(Some(Value::Low)), // '0'
49 => Ok(Some(Value::High)), // '1'
_ => Err(Error::new(ErrorKind::InvalidData, "Unrecognized GPIO Value"))
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment