Merge pull request #24 from tgikal/tgikal-SPI-read_passive_target-timeout

SPI read_passive_target timeout
This commit is contained in:
Carter Nelson 2019-07-03 14:30:27 -07:00 committed by GitHub
commit b949e87e1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -81,14 +81,14 @@ class PN532_SPI(PN532):
status = bytearray([reverse_bit(_SPI_STATREAD), 0])
timestamp = time.monotonic()
while (time.monotonic() - timestamp) < timeout:
with self._spi as spi:
with self._spi as spi:
while (time.monotonic() - timestamp) < timeout:
time.sleep(0.02) # required
spi.write_readinto(status, status) #pylint: disable=no-member
if reverse_bit(status[1]) == 0x01: # LSB data is read in MSB
return True # Not busy anymore!
else:
time.sleep(0.01) # pause a bit till we ask again
if reverse_bit(status[1]) == 0x01: # LSB data is read in MSB
return True # Not busy anymore!
else:
time.sleep(0.01) # pause a bit till we ask again
# We timed out!
return False