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."); } }