Files
projekt-arduino/RFID.cpp
T
GarandPLG 899212d7b9 Remove turn signal & sonar, add RFID auth
Define AUTH_UID and AUTH_UID_SIZE constants.
Introduce motor control pins IN_1‑IN_4 and set them as outputs.
Comment out turn‑signal and sonar pin definitions and related code.
Refactor Display to remove updateDirection functionality.
Extend RFIDReader with reset() and matches() methods; use them to toggle
carEnabled based on RFID authentication.
Update the main loop to operate only when the RFID tag matches the
authorized UID.
2026-06-16 21:56:31 +02:00

47 lines
1.1 KiB
C++

#include "RFID.h"
RFIDReader::RFIDReader(int ssPin, int rstPin)
: _rfid(ssPin, rstPin) {}
void RFIDReader::begin() {
SPI.begin();
_rfid.PCD_Init();
}
bool RFIDReader::check() {
if (!_rfid.PICC_IsNewCardPresent()) return false;
if (!_rfid.PICC_ReadCardSerial()) return false;
// _rfid.PICC_HaltA(); // stop the tag
// _rfid.PCD_StopCrypto1(); // clear RC522 crypto
return true;
}
void RFIDReader::reset() {
_rfid.PICC_HaltA();
_rfid.PCD_StopCrypto1();
}
bool RFIDReader::matches(const byte* expectedUid, byte expectedSize) const {
if (_rfid.uid.size != expectedSize) return false;
for (byte i = 0; i < expectedSize; ++i) {
if (_rfid.uid.uidByte[i] != expectedUid[i]) return false;
}
return true;
}
void RFIDReader::printUID() const {
Serial.println(F("RFID Tag UID:"));
// for (byte i = 0; i < _rfid.uid.size; i++) {
// Serial.print(_rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
// Serial.print(_rfid.uid.uidByte[i], HEX);
// }
}
const byte* RFIDReader::getUID() const {
return _rfid.uid.uidByte;
}
byte RFIDReader::getUIDSize() const {
return _rfid.uid.size;
}