49 lines
839 B
C++
49 lines
839 B
C++
#include <SoftwareSerial.h>
|
|
|
|
class RfidClass {
|
|
private:
|
|
SoftwareSerial* serD;
|
|
void init(void);
|
|
String rmsg;
|
|
public:
|
|
RfidClass(void);
|
|
bool hasData(void);
|
|
String getData(void);
|
|
bool allowed(void);
|
|
void clear(void);
|
|
};
|
|
|
|
RfidClass::RfidClass(void) {
|
|
this->init();
|
|
}
|
|
|
|
void RfidClass::init(void) {
|
|
this->serD = new SoftwareSerial (9, 8);
|
|
this->serD->begin(9600);
|
|
}
|
|
|
|
bool RfidClass::hasData(void) {
|
|
this->serD->listen();
|
|
if(this->serD->available()) {
|
|
this->rmsg += (char)this->serD->read();
|
|
}
|
|
if(this->rmsg.length() >= 14) {
|
|
this->rmsg = this->rmsg.substring(1,13);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
String RfidClass::getData(void){
|
|
return this->rmsg;
|
|
}
|
|
|
|
bool RfidClass::allowed() {
|
|
return (this->rmsg == "0A006AB7AE79");
|
|
}
|
|
|
|
void RfidClass::clear(void) {
|
|
this->rmsg = "";
|
|
}
|
|
|