From a2a752a720aaa4f9c6d492e3bbe4eeac29a856dd Mon Sep 17 00:00:00 2001 From: trotFunky Date: Sun, 24 Sep 2023 12:31:01 +0100 Subject: [PATCH] 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. --- src/RFID.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RFID.cpp b/src/RFID.cpp index 87a79a4..8eb7379 100644 --- a/src/RFID.cpp +++ b/src/RFID.cpp @@ -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; } } }