From 776a4e252f2cb680fb91db7000e989114e20fb87 Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Thu, 7 Mar 2024 23:22:24 +0000 Subject: [PATCH] main: Use both RFID readers As our RFID tags cannot co-exist on the same reader as originally plan, handle another reader on SPI1. Checking tags is not time sensitive and can be made in successive loops, which minimizes the changes needed from the original code. --- README.md | 1 + src/main.cpp | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ba8adc2..aa125af 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ se synchroniser avec le firmware et potentiellement le mettre à jour. - [ ] Contrôle des modules - [x] RFID (base) - [x] RFID (avancé, écriture des tags) + - [x] RFID (deux lecteurs) - [x] LCD (base) - [x] LCD (animations) - [ ] LCD (UI) diff --git a/src/main.cpp b/src/main.cpp index dcaf1c7..1389e37 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,11 +16,13 @@ __attribute__((noreturn)) int main() { pinMode(pin_Audio_AMP_GAIN_EN, OUTPUT); pinMode(pin_NFC1_RST, OUTPUT); + pinMode(pin_NFC2_RST, OUTPUT); pinMode(pin_LCD_RST, OUTPUT); /* Preemptively disable what we can before the regulator is ON. */ digitalWrite(pin_Audio_Amp_enable, LOW); digitalWrite(pin_NFC1_RST, LOW); + digitalWrite(pin_NFC2_RST, LOW); digitalWrite(pin_LCD_RST, LOW); pinMode(pin_BAT_SNS, INPUT); @@ -45,6 +47,11 @@ __attribute__((noreturn)) int main() { digitalWrite(pin_NFC1_RST, HIGH); rfid.init(); + SPI1.setMISO(pin_SPI1_CIPO); + RFID rfid2(pin_NFC2_CS, SPI1); + digitalWrite(pin_NFC2_RST, HIGH); + rfid2.init(); + if (!SD.begin(BUILTIN_SDCARD)) Com::sendComment("Could not use the SD Card."); @@ -66,7 +73,14 @@ __attribute__((noreturn)) int main() { lcd.checkAndDisplay(); speaker.checkPlayingAndDisable(); + /* + * In the unlikely case where two changes happen in the same cycle, we + * can check the second RFID reader on the next one. + */ tagEvent = rfid.checkTags(); + if (tagEvent == RFID::checkFail) { + tagEvent = rfid2.checkTags(); + } if (tagEvent != RFID::checkFail) { Com::sendFigUpdate(tagEvent); /* Currently, we only play effects when placing a new figurine. */ @@ -80,9 +94,11 @@ __attribute__((noreturn)) int main() { Com::ReceivedMessage message = Com::receiveMessage(); if (message == Com::TAG_INFO_REQUEST) { uint8_t tagCount = rfid.gatherTagInfo(Com::getTagRecords()); + tagCount += rfid2.gatherTagInfo(Com::getTagRecords() + tagCount); Com::sendTagInfo(tagCount); } else if (message == Com::TAG_PROGRAMMING) { - if (!rfid.programTag(Com::getTagRecords())) { + if (!rfid.programTag(Com::getTagRecords()) && + !rfid2.programTag(Com::getTagRecords())) { Com::sendComment("Tag programming failed."); } }