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:
parent
3ee09f284a
commit
776a4e252f
2 changed files with 18 additions and 1 deletions
|
@ -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)
|
||||
|
|
18
src/main.cpp
18
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.");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue