1
0
Fork 0

RFID: Update definitions to allow a second reader

The board has a second SPI bus wired up for communication with two RFID readers
if needed.
However, the code only provided a constructor with no arguments, preventing
the use of a second instance on the different bus.

Update the constructor and the definitions to allow changing the chip select
and SPI bus used when creating an RFID reader.
This commit is contained in:
Teo-CD 2023-12-17 21:39:05 +00:00
parent 73d80312aa
commit aaa2b6553c

View file

@ -30,7 +30,15 @@ struct uidNode {
class RFID { class RFID {
public: public:
RFID() : comData{}, sd(SD) {}; /***
* Use the main SPI port and NFC chip select by default, but allow choosing
* an alternate chip select and/or SPI bus if needed to allow multiple
* RFID readers in parallel.
*/
explicit RFID(const uint8_t chipSelect = pin_NFC1_CS, SPIClass &spiBus = SPI) :
driverPin(chipSelect), driverSpi(driverPin, spiBus),
mfrc(driverSpi), comData{}, sd(SD) {};
void init(); void init();
/*** /***
* Check if any new tags are present or have left. Only one event is reported * Check if any new tags are present or have left. Only one event is reported
@ -54,9 +62,9 @@ private:
uidNode* activeTags = nullptr; uidNode* activeTags = nullptr;
uidNode* nextFreeTagSlot = activeTagsArray; uidNode* nextFreeTagSlot = activeTagsArray;
MFRC522DriverPinSimple driverPin{pin_NFC1_CS}; MFRC522DriverPinSimple driverPin;
MFRC522DriverSPI driverSpi{driverPin}; MFRC522DriverSPI driverSpi;
MFRC522 mfrc{driverSpi}; MFRC522 mfrc;
/* /*
* Array used to read and write blocks to the tags. Blocks are 16 bytes but * Array used to read and write blocks to the tags. Blocks are 16 bytes but