-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistr-reader.ino
executable file
·57 lines (52 loc) · 1.4 KB
/
registr-reader.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <WebUSB.h>
#include "rfid.h"
/**
* Creating an instance of WebUSBSerial will add an additional USB interface to
* the device that is marked as vendor-specific (rather than USB CDC-ACM) and
* is therefore accessible to the browser.
*
* The URL here provides a hint to the browser about what page the user should
* navigate to to interact with the device.
*/
WebUSB WebUSBSerial(1 /* https:// */, "join.tuna.tsinghua.edu.cn");
RFID rfid;
#define Serial WebUSBSerial
void setup() {
while (!Serial) {
;
}
Serial.begin(9600);
Serial.println("Sketch begins.");
rfid.Init();
Serial.flush();
}
double lastKeepalive;
void loop() {
if (Serial && Serial.available()) {
int byte = Serial.read();
if (byte == 'H') {
Serial.println("Turning LED on.");
} else if (byte == 'L') {
Serial.println("Turning LED off.");
}
Serial.flush();
}
rfid.Poll();
if(rfid.Found()){
if(rfid.GetCardType() == RFID::Card_14443B){
Serial.println("CardBegin");
Serial.print("StuNumber="); Serial.println(rfid.GetStuID());
Serial.print("Name="); Serial.println(rfid.GetName());
Serial.print("Gender="); Serial.println(rfid.GetGender());
Serial.println("CardEnd");
Serial.flush();
}
rfid.Next();
Serial.flush();
}
if(millis()-lastKeepalive > 1000){
Serial.println("KeepAlive");
Serial.flush();
lastKeepalive = millis();
}
}