RFID: Change the checkTag fail return
Previously, checkTag() returned 0 when it failed or when there was no changes. This is fine if we are only expecting already programmed tags, but as tags arrive new with blocks zeroed out, which conflicts with the 0 return value. Introduce a new constant to RFID for the return error, -1, and use it instead of 0 everywhere. Update comments and README to highlight this new reserved ID.
This commit is contained in:
parent
2fd1939746
commit
3ee09f284a
4 changed files with 11 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue