From 109575ca3f5d93fb9b90909dd060d931b1c3cfb1 Mon Sep 17 00:00:00 2001 From: Scott Martin Date: Sat, 30 Nov 2024 14:24:04 -0500 Subject: [PATCH] Add option to prevent halt when NFC tag not found on begin() --- NfcAdapter.cpp | 9 +++++++-- NfcAdapter.h | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/NfcAdapter.cpp b/NfcAdapter.cpp index 9099bde..14bd77e 100644 --- a/NfcAdapter.cpp +++ b/NfcAdapter.cpp @@ -10,7 +10,7 @@ NfcAdapter::~NfcAdapter(void) delete shield; } -void NfcAdapter::begin(boolean verbose) +bool NfcAdapter::begin(boolean verbose, boolean halt_on_not_found=true) { shield->begin(); @@ -21,7 +21,11 @@ void NfcAdapter::begin(boolean verbose) #ifdef NDEF_USE_SERIAL Serial.print(F("Didn't find PN53x board")); #endif - while (1); // halt + if (halt_on_not_found) { + while (1); // halt + } else { + return false; + } } if (verbose) @@ -34,6 +38,7 @@ void NfcAdapter::begin(boolean verbose) } // configure board to read RFID tags shield->SAMConfig(); + return true; } boolean NfcAdapter::tagPresent(unsigned long timeout) diff --git a/NfcAdapter.h b/NfcAdapter.h index 1ef9e59..6d010b4 100644 --- a/NfcAdapter.h +++ b/NfcAdapter.h @@ -25,7 +25,7 @@ class NfcAdapter { NfcAdapter(PN532Interface &interface); ~NfcAdapter(void); - void begin(boolean verbose=true); + boolean begin(boolean verbose=true, boolean halt_on_not_found=true); boolean tagPresent(unsigned long timeout=0); // tagAvailable NfcTag read(); boolean write(NdefMessage& ndefMessage);