From aaa2b6553c829dd183bf6f05bd8837aba971ef44 Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Sun, 17 Dec 2023 21:39:05 +0000 Subject: [PATCH 1/2] 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. --- include/RFID.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/include/RFID.h b/include/RFID.h index 88d4c65..ef5b02b 100644 --- a/include/RFID.h +++ b/include/RFID.h @@ -30,7 +30,15 @@ struct uidNode { class RFID { 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(); /*** * Check if any new tags are present or have left. Only one event is reported @@ -54,9 +62,9 @@ private: uidNode* activeTags = nullptr; uidNode* nextFreeTagSlot = activeTagsArray; - MFRC522DriverPinSimple driverPin{pin_NFC1_CS}; - MFRC522DriverSPI driverSpi{driverPin}; - MFRC522 mfrc{driverSpi}; + MFRC522DriverPinSimple driverPin; + MFRC522DriverSPI driverSpi; + MFRC522 mfrc; /* * Array used to read and write blocks to the tags. Blocks are 16 bytes but From a438cb13d4f9f53fc9dc68a89f69968fba0b7290 Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Sun, 17 Dec 2023 21:53:36 +0000 Subject: [PATCH 2/2] Only play effects on arrival, use real tag Remove the overide of the tag value used for testing. We don't plan yet on playing effects when a tag leaves, so avoid playing the effects twice and only do so when arriving. --- src/main.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c09771e..3b5902f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,12 +68,13 @@ __attribute__((noreturn)) int main() { tagEvent = rfid.checkTags(); if (tagEvent) { - tagEvent = 4; Com::sendFigUpdate(tagEvent); - /* Start the audio first because of the possible WAV parsing delay. */ - speaker.playNewSound(tagEvent); - lcd.startNewAnim(tagEvent); - + /* Currently, we only play effects when placing a new figurine. */ + if (!isIdGone(tagEvent)) { + /* Start the audio first as WAV parsing might delay playback. */ + speaker.playNewSound(tagEvent); + lcd.startNewAnim(tagEvent); + } } /* TODO: Drop delay, WFE+timer interrupt(s) ? */