-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrintToKeyboard.ino
84 lines (69 loc) · 1.98 KB
/
PrintToKeyboard.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "Database.h"
#include "UHFRecv.h"
#define RS485_CONTROL 4 //< Pin for RS485 Direction Control
#define LED 17 //< LED Pin
#define BAUD_RATE 9600
// Comment out this to speed up the setup process (no flash())
#define DEBUG
void flash();
Database* database;
UHFRecv TictagUhf(Serial1, BAUD_RATE, RS485_CONTROL);
uint32_t now = 0;
uint32_t period = 600; //< Change this value to modify time between inventory
// sessions (600 means 600 ms).
void setup()
{
/* Setting Serial */
Serial.begin(BAUD_RATE);
flash();
/* Setting UHF Receiver */
#ifdef DEBUG
Serial.println("Initialise UHF Receiver.");
flash();
#endif
TictagUhf.begin();
/* Setting database */
#ifdef DEBUG
Serial.println("Initialise Database");
flash();
#endif
database = new Database;
database->begin();
/* Setting prefix */
String prefix = "";
#ifdef DEBUG
Serial.print("Setting prefix to ");
if (prefix == "")
Serial.println("default prefix: empty string");
else
Serial.println(prefix);
#endif
_setPrefix(prefix);
delay(300);
Serial.println("Scanning cards...");
}
void loop()
{
Status status = 0x00;
byte reData[INV_MAX_SIZE] = {0};
byte* cmd = TictagUhf.setCommand(READER_ADDRESS, TID_ARRESSS, LENGTH_TID);
size_t sizeCmd = TictagUhf.getSizeCommand();
if (millis() > (now + period)) {
now = millis();
TictagUhf.getRawData(reData, cmd, sizeCmd); //< Get raw data from
// inventory command
if (TictagUhf.isDataPreserved(reData, sizeof(reData))) {
if ((status = database->updateDB(reData)) != STATUS_SUCCESS)
return ;
database->printToKeyboard();
} else {
Keyboard.println("CSERR");
}
}
}
void flash()
{
digitalWrite(LED, HIGH);
delay(800);
digitalWrite(LED, LOW);
}