Add HardwareRfid class implementation and integrate with main loop

This commit is contained in:
2025-10-04 11:39:26 +02:00
parent 505367d6a8
commit 697e6fd11f
4 changed files with 77 additions and 4 deletions
+44
View File
@@ -0,0 +1,44 @@
#include "hardware_rfid.hpp"
#include <Arduino.h>
HardwareRfid::HardwareRfid(uint8_t ssPin, uint8_t rstPin)
: _mfrc(ssPin, rstPin) {}
void HardwareRfid::begin() {
_mfrc.PCD_Init();
}
void HardwareRfid::end() {
// Nothing special to do
}
void HardwareRfid::update() {
if (!_mfrc.PICC_IsNewCardPresent() || !_mfrc.PICC_ReadCardSerial()) {
return;
}
// Get the UID
uint32_t cardId = 0;
for (byte i = 0; i < _mfrc.uid.size; i++) {
cardId = (cardId << 8) | _mfrc.uid.uidByte[i];
}
// Create the message
hardware_SensorToControlMessage msg = {0};
msg.sensor_id = 0; // Assuming single sensor
msg.which_payload = hardware_SensorToControlMessage_rfid_reading_tag; // Assuming this is the tag
msg.payload.rfid_reading.card_id = cardId;
// Call the callback if set
if (_callback) {
_callback(msg);
}
// Halt the card
_mfrc.PICC_HaltA();
_mfrc.PCD_StopCrypto1();
}
void HardwareRfid::setCallback(RfidCallback cb) {
_callback = cb;
}