#include <Arduino.h>
#include "MFRC522.h"
#include "utils.h"
#include "readers.h"

MFRC522Reader::MFRC522Reader(byte chipSelectPin, byte resetPowerDownPin) {
	mfrc522 = new MFRC522(chipSelectPin, resetPowerDownPin);
}

bool MFRC522Reader::isNewCardPresent() {
	return mfrc522->PICC_IsNewCardPresent() && mfrc522->PICC_ReadCardSerial();
}

String MFRC522Reader::getCardUid() {
	return byteArrayAsHexString(mfrc522->uid.uidByte, mfrc522->uid.size);
}

void MFRC522Reader::begin(){
}
void MFRC522Reader::end(){
}

void MFRC522Reader::reset() {
	mfrc522->PCD_AntennaOff();
	mfrc522->PCD_Init();
	mfrc522->PCD_AntennaOn();
}

inline bool MFRC522Reader::canHaveUnstableIdentifier() {
	return true;
}

void MFRC522Reader::init() {
	mfrc522->PCD_Init();
	mfrc522->PCD_DumpVersionToSerial();
}

String MFRC522Reader::getReaderName() {
	return "mfrc522";
}
