-
Notifications
You must be signed in to change notification settings - Fork 0
/
BMA_R30X.h
90 lines (76 loc) · 2.25 KB
/
BMA_R30X.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
BMA-R30X.h - Library for iterfacing with r30x series fingerprint scanners.
Created by Batman - CEO Meem Ent.
Created on April 18, 2021.
*/
#ifndef BMA_R30X_h
#define BMA_R30X_h
#include "Arduino.h"
#include <Adafruit_SSD1306.h>
#include <EEPROM.h>
// EEPROM data locations.
#define NETWORK_LENGTH 0
#define PASSWORD_LENGTH 1
// OLED screen resolution ('0.96)
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// default module password and address.
#define M_PASSWORD 0x00000000
#define M_ADDRESS 0xFFFFFFFF
// packet IDs.
#define HEADER 0xEF01
#define PID_COMMAND 0x01
#define PID_DATA 0x02
#define PID_ACKNOWLEDGE 0x07
#define PID_PACKET_END 0x08
#define PID_DATA_END 0x08
// Module command codes
#define CMD_VERIFY_PASSWORD 0x13
#define CMD_COLLECT_FINGER_IMAGE 0x01
#define CMD_GEN_CHAR_FILE 0x02
#define CMD_REG_MODEL 0x05
#define CMD_STORE_TEMPLATE 0x06
#define CMD_UPLOAD_TEMPLATE 0x08
#define CMD_SEARCH_LIBRARY 0x04
#define CMD_READ_TEMPLATE 0x07
// length of buffer used to read serial data
#define FPS_DEFAULT_SERIAL_BUFFER_LENGTH 300
// default timeout to wait for response from scanner
#define DEFAULT_TIMEOUT 2000
class BMA{
public:
uint8_t *rx_data = NULL;
uint8_t *template_file = NULL;
int finger_location = 0;
int attendance_count = 0;
uint8_t attendance_store = 0;
uint16_t rx_data_length = 0;
uint16_t template_length = 0;
String organizationID = "";
String ssid = "";
String password = "";
Adafruit_SSD1306 *display = NULL;
BMA();
bool sendPacket(uint8_t pid, uint8_t cmd, uint8_t* data, uint16_t data_length, bool print_data = false);
uint8_t receivePacket(uint32_t timeout = DEFAULT_TIMEOUT, bool print_data = false);
uint8_t receiveTemplate();
bool verifyPassword(uint32_t password = M_PASSWORD);
uint16_t enrollFinger();
bool fingerSearch();
bool uploadTemplate();
bool readTemplateFromLib();
void displayOLED(char* msg);
private:
uint8_t collectFingerImage();
uint8_t generateCharacterFile(uint8_t bufferId[]);
};
struct Attendance{
uint16_t authID;
uint16_t current_year;
uint8_t current_month;
uint8_t current_date;
uint8_t current_hour;
uint8_t current_minute;
uint8_t current_second;
};
#endif