forked from soonuse/pn532-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqpn532.cpp
48 lines (43 loc) · 1.21 KB
/
qpn532.cpp
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
#include "qpn532.h"
#include <QtConcurrent/QtConcurrent>
QPN532::QPN532(QObject *parent) : QObject(parent)
{
PN532_I2C_Init(&_pn532);
if (PN532_GetFirmwareVersion(&_pn532, _buff) == PN532_STATUS_OK) {
printf("Found PN532 with firmware version: %d.%d\r\n", _buff[1], _buff[2]);
_ready = true;
Q_EMIT readyChanged();
PN532_SamConfiguration(&_pn532);
QtConcurrent::run(this, &QPN532::loop);
}
else
{
qDebug()<<"Failed to init reader";
}
}
bool QPN532::isReady() const
{
return _ready;
}
void QPN532::loop()
{
while (1)
{
// Check if a card is available to read
_uid_len = PN532_ReadPassiveTarget(&_pn532, _uid, PN532_MIFARE_ISO14443A, 1000);
if (_uid_len == PN532_STATUS_ERROR) {
printf(".");
fflush(stdout);
} else {
printf("Found card with UID: ");
for (uint8_t i = 0; i <_uid_len; i++) {
_uidArr.append(_uid[i]);
printf("%02x ", _uid[i]);
}
printf("\r\n");
Q_EMIT cardRead(QString::fromUtf8(_uidArr.toHex()).toUpper());
_uidArr.clear();
QThread::sleep(1);
}
}
}