-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdm6300.h
72 lines (63 loc) · 1.65 KB
/
rdm6300.h
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
/*
* A simple library to interface with rdm6300 rfid reader.
*
* Arad Eizen (https://github.com/arduino12).
*/
#ifndef _RDM6300_h_
#define _RDM6300_h_
#include <Arduino.h>
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_SAMD)
#define RDM6300_HARDWARE_SERIAL
#endif
#if !(defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_SAMD))
#define RDM6300_SOFTWARE_SERIAL
#endif
#ifdef RDM6300_HARDWARE_SERIAL
#ifdef ARDUINO_ARCH_SAMD
#include <Uart.h>
#define HardwareSerial_t Uart
#else
#include <HardwareSerial.h>
#define HardwareSerial_t HardwareSerial
#endif
#endif
#ifdef RDM6300_SOFTWARE_SERIAL
#include <SoftwareSerial.h>
#endif
#include <Stream.h>
#define RDM6300_BAUDRATE (9600)
#define RDM6300_PACKET_SIZE (14)
#define RDM6300_PACKET_BEGIN (0x02)
#define RDM6300_PACKET_END (0x03)
#define RDM6300_DEFAULT_TAG_TIMEOUT_MS (300)
#define RDM6300_READ_TIMEOUT (20)
class Rdm6300
{
public:
void begin(Stream *stream);
void begin(int rx_pin, uint8_t uart_nr=1);
void end(void);
void set_tag_timeout(uint32_t tag_timeout_ms);
uint32_t get_tag_id(void);
uint32_t get_new_tag_id(void);
#ifdef RDM6300_SOFTWARE_SERIAL
void listen(void);
bool is_listening(void);
#endif
private:
void _update(void);
uint32_t _read_tag_id(void);
#ifdef RDM6300_HARDWARE_SERIAL
HardwareSerial_t *_hardware_serial = NULL;
#endif
#ifdef RDM6300_SOFTWARE_SERIAL
SoftwareSerial *_software_serial = NULL;
#endif
Stream *_stream = NULL;
uint32_t _tag_id = 0;
uint32_t _new_tag_id = 0;
uint32_t _last_tag_id = 0;
uint32_t _last_tag_ms = 0;
uint32_t _tag_timeout_ms = RDM6300_DEFAULT_TAG_TIMEOUT_MS;
};
#endif