1
0
Fork 0

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.
This commit is contained in:
Teo-CD 2024-03-07 23:22:24 +00:00
parent 3ee09f284a
commit 776a4e252f
2 changed files with 18 additions and 1 deletions

View file

@ -42,6 +42,7 @@ se synchroniser avec le firmware et potentiellement le mettre à jour.
- [ ] Contrôle des modules - [ ] Contrôle des modules
- [x] RFID (base) - [x] RFID (base)
- [x] RFID (avancé, écriture des tags) - [x] RFID (avancé, écriture des tags)
- [x] RFID (deux lecteurs)
- [x] LCD (base) - [x] LCD (base)
- [x] LCD (animations) - [x] LCD (animations)
- [ ] LCD (UI) - [ ] LCD (UI)

View file

@ -16,11 +16,13 @@ __attribute__((noreturn)) int main() {
pinMode(pin_Audio_AMP_GAIN_EN, OUTPUT); pinMode(pin_Audio_AMP_GAIN_EN, OUTPUT);
pinMode(pin_NFC1_RST, OUTPUT); pinMode(pin_NFC1_RST, OUTPUT);
pinMode(pin_NFC2_RST, OUTPUT);
pinMode(pin_LCD_RST, OUTPUT); pinMode(pin_LCD_RST, OUTPUT);
/* Preemptively disable what we can before the regulator is ON. */ /* Preemptively disable what we can before the regulator is ON. */
digitalWrite(pin_Audio_Amp_enable, LOW); digitalWrite(pin_Audio_Amp_enable, LOW);
digitalWrite(pin_NFC1_RST, LOW); digitalWrite(pin_NFC1_RST, LOW);
digitalWrite(pin_NFC2_RST, LOW);
digitalWrite(pin_LCD_RST, LOW); digitalWrite(pin_LCD_RST, LOW);
pinMode(pin_BAT_SNS, INPUT); pinMode(pin_BAT_SNS, INPUT);
@ -45,6 +47,11 @@ __attribute__((noreturn)) int main() {
digitalWrite(pin_NFC1_RST, HIGH); digitalWrite(pin_NFC1_RST, HIGH);
rfid.init(); 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)) if (!SD.begin(BUILTIN_SDCARD))
Com::sendComment("Could not use the SD Card."); Com::sendComment("Could not use the SD Card.");
@ -66,7 +73,14 @@ __attribute__((noreturn)) int main() {
lcd.checkAndDisplay(); lcd.checkAndDisplay();
speaker.checkPlayingAndDisable(); 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(); tagEvent = rfid.checkTags();
if (tagEvent == RFID::checkFail) {
tagEvent = rfid2.checkTags();
}
if (tagEvent != RFID::checkFail) { if (tagEvent != RFID::checkFail) {
Com::sendFigUpdate(tagEvent); Com::sendFigUpdate(tagEvent);
/* Currently, we only play effects when placing a new figurine. */ /* Currently, we only play effects when placing a new figurine. */
@ -80,9 +94,11 @@ __attribute__((noreturn)) int main() {
Com::ReceivedMessage message = Com::receiveMessage(); Com::ReceivedMessage message = Com::receiveMessage();
if (message == Com::TAG_INFO_REQUEST) { if (message == Com::TAG_INFO_REQUEST) {
uint8_t tagCount = rfid.gatherTagInfo(Com::getTagRecords()); uint8_t tagCount = rfid.gatherTagInfo(Com::getTagRecords());
tagCount += rfid2.gatherTagInfo(Com::getTagRecords() + tagCount);
Com::sendTagInfo(tagCount); Com::sendTagInfo(tagCount);
} else if (message == Com::TAG_PROGRAMMING) { } 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."); Com::sendComment("Tag programming failed.");
} }
} }