Change method for scanning for card from poll, which is OK for USB-connected PN532, but causes 100% CPU usage with SPI-connected PN532

This commit is contained in:
Ondrej Mikle 2018-05-06 01:43:43 +02:00
parent 9b89a230c9
commit 91c0d72de6
3 changed files with 16 additions and 15 deletions

View file

@ -104,19 +104,16 @@ std::string NFCDevice::scanUID() throw(NFCError)
throw NFCError("NFC device not opened");
}
// We release GIL because otherwise it would block other threads. Since this polling is de-facto sleep and
// doesn't touch any variables, it works as a language without GIL would.
Py_BEGIN_ALLOW_THREADS
res = nfc_initiator_poll_target(_nfcDevice, _modulations, _modulationsLen, pollNr, pollPeriod, &nt);
Py_END_ALLOW_THREADS
/* nfc_initiator_poll_target works fine for USB-connected PN532 (sleeps until card is available or timeout),
* but causes 100% CPU usage on SPI-connected PN532
*/
//res = nfc_initiator_poll_target(_nfcDevice, _modulations, _modulationsLen, pollNr, pollPeriod, &nt);
res = nfc_initiator_list_passive_targets(_nfcDevice, _modulations[0], &nt, 1);
if (res < 0) {
throw NFCError("NFC polling error");
}
// we are not interested in non-ISO-14443A cards
if (nt.nm.nmt != NMT_ISO14443A) {
return string();
throw NFCError("NFC list passive targets error");
} else if (res == 0) {
throw NFCError("No card in reader's field");
}
const nfc_iso14443a_info& nai = nt.nti.nai;