1
0
Fork 0

RFID: Fix tag return when gone

Previously, the return value when a tag was gone was the negative ID.
However, this isn't the most effective to process later as a negative
number uses two's complement, changing all lower bits in addition
to the sign bit.

Change this to just set the sign bit instead. This still produces
a negative number, which is what we want to check to konw if the tag
is new or went away, but maintains the lower bits so the ID can be
retrieved with a simple bit-wise and.
This commit is contained in:
Teo-CD 2023-09-24 12:31:01 +01:00
parent aa2f2e4803
commit 8d80dd2604

View file

@ -37,9 +37,9 @@ int8_t RFID::checkTags() {
// Serial.printf("UID 0x%lX is gone\n", *(uint32_t *)node->uid.uidByte);
// If we don't, assume the tag is gone and remove it from the list.
removeActiveTag(node, previousNode);
// Return the negative ID to signal it has gone.
// Return the ID with the sign bit set to signal it has gone.
// If other tags are gone we can check on the next loop.
return -node->tag_ID;
return node->tag_ID | 1<<7;
}
}
}