diff --git a/README.md b/README.md index 8833522..ba8adc2 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,8 @@ Il contient l'ID de la figurine sur les bits 0-5 de l'octet, si la figurine est un personnage (1) ou une année (0) sur le bit 6 et si la figurine a été posée (0) ou retirée (1) sur le bit 7. Ainsi, si on interprète l'octet comme un nombre signé, si le nombre est négatif -on sait que la figurine a été retirée. +on sait que la figurine a été retirée. +**_Dû à un détail d'implémentation, l'identifiant 127 est invalide et réservé._** #### Schéma ``` diff --git a/include/RFID.h b/include/RFID.h index 66a42f8..1c8bd8b 100644 --- a/include/RFID.h +++ b/include/RFID.h @@ -32,6 +32,8 @@ struct uidNode { class RFID { public: static constexpr int maxTags = 2; + /* Error value returned when checking for new or gone tags. */ + static constexpr int8_t checkFail = -1; /*** * Use the main SPI port and NFC chip select by default, but allow choosing @@ -48,7 +50,8 @@ public: * at a time, another call would be needed to get eventual concurrent events. * This updates the respective lists and returns the ID with the direction * of the change. - * @return 0 if no change, ID if new tag detected, ID & sign bit if the tag left. + * @return ID if new tag detected, ID & sign bit if the tag left + * @return RFID::checkFail if no change or error. */ int8_t checkTags(); diff --git a/src/RFID.cpp b/src/RFID.cpp index 2b15851..62a4a2f 100644 --- a/src/RFID.cpp +++ b/src/RFID.cpp @@ -52,21 +52,21 @@ int8_t RFID::checkTags() { if ( currentActiveTags >= maxTags || !mfrc.PICC_IsNewCardPresent() || !mfrc.PICC_ReadCardSerial()) { - return 0; + return checkFail; } // Assume we have a new tag. uidNode* newTag = addActiveTag(mfrc.uid); // Tag ID is put in a specific block, which can be read after from comData. if ( !newTag ) { - return 0; + return checkFail; } // If the read fails, we cannot use this tag anyway so remove it from the list. if (!readBlock(newTag->uid, tagIdBlock) ) { removeActiveTag(newTag, nullptr); - return 0; + return checkFail; } - // Don' t check the ID, otherwise we cannot program the tag. + // Don't check the ID, otherwise we cannot program the tag. newTag->tag_ID = comData[0]; return newTag->tag_ID; } diff --git a/src/main.cpp b/src/main.cpp index b281973..dcaf1c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,7 +67,7 @@ __attribute__((noreturn)) int main() { speaker.checkPlayingAndDisable(); tagEvent = rfid.checkTags(); - if (tagEvent) { + if (tagEvent != RFID::checkFail) { Com::sendFigUpdate(tagEvent); /* Currently, we only play effects when placing a new figurine. */ if (!isIdGone(tagEvent)) {