mirror of
https://github.com/m5stack/M5Stack.git
synced 2026-05-20 10:06:46 -07:00
fix some error
This commit is contained in:
@@ -1,99 +1,92 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2021 by M5Stack
|
||||
* Equipped with M5Core sample source code
|
||||
* 配套 M5Core 示例源代码
|
||||
* Visit the website for more information:https://docs.m5stack.com/en/unit/finger
|
||||
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/finger
|
||||
*
|
||||
* describe: Finger.
|
||||
* date:2021/8/26
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <M5Stack.h>
|
||||
#include "M5_FPC1020A.h"
|
||||
#include "finger.h"
|
||||
|
||||
uint8_t userNum; //User number
|
||||
FingerPrint FP_M;
|
||||
|
||||
void CleanScreen()
|
||||
{
|
||||
M5.Lcd.fillRect(0,50,400,300,BLACK);
|
||||
M5.Lcd.setCursor(0, 50);
|
||||
M5.Lcd.setTextSize(2);
|
||||
userNum = FP_M.fpm_getUserNum(); //Get users Numbers. 获取用户数量
|
||||
M5.Lcd.print("userNum:");
|
||||
M5.Lcd.println(userNum);
|
||||
M5.Lcd.setTextColor(WHITE);
|
||||
M5.Lcd.fillRect(0,50,400,300,BLACK);
|
||||
M5.Lcd.setCursor(0, 50);
|
||||
M5.Lcd.setTextSize(2);
|
||||
userNum = FP_M.fpm_getUserNum();
|
||||
M5.Lcd.print("userNum:");
|
||||
M5.Lcd.println(userNum);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
M5.begin();
|
||||
M5.Power.begin();
|
||||
Serial.begin(115200);
|
||||
Serial2.begin(19200, SERIAL_8N1, 16, 17);
|
||||
M5.Lcd.clear(BLACK);
|
||||
M5.Lcd.setTextColor(YELLOW);
|
||||
M5.Lcd.setTextSize(3);
|
||||
M5.Lcd.setCursor(20, 0);
|
||||
M5.Lcd.println("Finger example");
|
||||
M5.Lcd.setTextColor(WHITE);
|
||||
M5.Lcd.fillRect(0,50,400,300,BLACK);
|
||||
M5.Lcd.setCursor(0, 50);
|
||||
M5.Lcd.setTextSize(2);
|
||||
userNum = FP_M.fpm_getUserNum();
|
||||
M5.Lcd.print("userNum:");
|
||||
M5.Lcd.println(userNum);
|
||||
M5.begin();
|
||||
M5.Power.begin();
|
||||
Serial.begin(115200);
|
||||
Serial2.begin(19200, SERIAL_8N1, 16, 17);
|
||||
M5.Lcd.clear(BLACK);
|
||||
M5.Lcd.setTextColor(YELLOW);
|
||||
M5.Lcd.setTextFont(2);
|
||||
M5.Lcd.setTextSize(3);
|
||||
M5.Lcd.setCursor(20, 0);
|
||||
M5.Lcd.println("Finger example");
|
||||
Serial.printf("Finger example\n");
|
||||
M5.Lcd.setTextColor(WHITE);
|
||||
M5.Lcd.fillRect(0,50,400,300,BLACK);
|
||||
M5.Lcd.setCursor(0, 50);
|
||||
M5.Lcd.setTextSize(2);
|
||||
userNum = FP_M.fpm_getUserNum();
|
||||
M5.Lcd.print("userNum:");
|
||||
M5.Lcd.println(userNum);
|
||||
}
|
||||
|
||||
//ButtonA: Add user
|
||||
//ButtonB: Matching
|
||||
//ButtonC: Delete All User
|
||||
void loop(){
|
||||
M5.update();
|
||||
uint8_t res1;
|
||||
//ButtonA: Add user. 添加用户
|
||||
if(M5.BtnA.wasPressed()){
|
||||
CleanScreen();
|
||||
M5.Lcd.println("Fingerprint Typing");
|
||||
uint8_t res1;
|
||||
if(M5.BtnA.wasPressed()){
|
||||
CleanScreen();
|
||||
M5.Lcd.println("Fingerprint Typing");
|
||||
|
||||
res1 = FP_M.fpm_addUser(userNum,1);
|
||||
if(res1 == ACK_SUCCESS){
|
||||
M5.Lcd.println("Success");
|
||||
}
|
||||
else if(res1 == ACK_FAIL){
|
||||
M5.Lcd.println("Fail");
|
||||
}
|
||||
else if(res1 == ACK_FULL){
|
||||
M5.Lcd.println("Full");
|
||||
}
|
||||
else{
|
||||
M5.Lcd.println("Timeout");
|
||||
}
|
||||
userNum++;
|
||||
}
|
||||
|
||||
res1 = FP_M.fpm_addUser(userNum,1);
|
||||
if(res1 == ACK_SUCCESS){
|
||||
M5.Lcd.println("Success");
|
||||
if(M5.BtnB.wasPressed()){
|
||||
CleanScreen();
|
||||
M5.Lcd.println("Matching");
|
||||
|
||||
res1 = FP_M.fpm_compareFinger();
|
||||
if(res1 == ACK_SUCCESS){
|
||||
M5.Lcd.println("Success");
|
||||
}
|
||||
if(res1 == ACK_NOUSER){
|
||||
M5.Lcd.println("No Such User");
|
||||
}
|
||||
if(res1 == ACK_TIMEOUT){
|
||||
M5.Lcd.println("Timeout");
|
||||
}
|
||||
}
|
||||
else if(res1 == ACK_FAIL){
|
||||
M5.Lcd.println("Fail");
|
||||
}
|
||||
else if(res1 == ACK_FULL){
|
||||
M5.Lcd.println("Full");
|
||||
}
|
||||
else{
|
||||
M5.Lcd.println("Timeout");
|
||||
}
|
||||
userNum++;
|
||||
}
|
||||
//ButtonB: Matching. 匹配指纹
|
||||
if(M5.BtnB.wasPressed()){
|
||||
CleanScreen();
|
||||
M5.Lcd.println("Matching");
|
||||
|
||||
res1 = FP_M.fpm_compareFinger();
|
||||
if(res1 == ACK_SUCCESS){
|
||||
M5.Lcd.println("Success");
|
||||
if(M5.BtnC.wasPressed()){
|
||||
res1 = FP_M.fpm_deleteAllUser();
|
||||
CleanScreen();
|
||||
|
||||
if(res1 == ACK_SUCCESS){
|
||||
M5.Lcd.println("Delete All User Successful");
|
||||
}
|
||||
else{
|
||||
M5.Lcd.println("Delete All User Failed");
|
||||
}
|
||||
}
|
||||
if(res1 == ACK_NOUSER){
|
||||
M5.Lcd.println("No Such User");
|
||||
}
|
||||
if(res1 == ACK_TIMEOUT){
|
||||
M5.Lcd.println("Timeout");
|
||||
}
|
||||
}
|
||||
//ButtonC: Delete All User. 删除所有用户
|
||||
if(M5.BtnC.wasPressed()){
|
||||
res1 = FP_M.fpm_deleteAllUser();
|
||||
CleanScreen();
|
||||
|
||||
if(res1 == ACK_SUCCESS){
|
||||
M5.Lcd.println("Delete All User Successful");
|
||||
}
|
||||
else{
|
||||
M5.Lcd.println("Delete All User Failed");
|
||||
}
|
||||
}
|
||||
M5.update();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
Description: FINGER UNIT use case: Press the left button to enter the fingerprint entry mode. Press the middle button to enter the fingerprint identification mode.
|
||||
*/
|
||||
|
||||
#include <M5Stack.h>
|
||||
#include "finger.h"
|
||||
|
||||
|
||||
FingerPrint::FingerPrint(void){
|
||||
|
||||
}
|
||||
|
||||
FingerPrint FP;
|
||||
|
||||
#define F_Time 10000
|
||||
|
||||
uint8_t FingerPrint::fpm_sendAndReceive(uint16_t timeout)
|
||||
{
|
||||
uint8_t i, j;
|
||||
uint8_t checkSum = 0;
|
||||
|
||||
FP.RxCnt = 0;
|
||||
FP.TxBuf[5] = 0;
|
||||
|
||||
Serial2.write(CMD_HEAD);
|
||||
for (i = 1; i < 6; i++)
|
||||
{
|
||||
Serial2.write(FP.TxBuf[i]);
|
||||
checkSum ^= FP.TxBuf[i];
|
||||
}
|
||||
Serial2.write(checkSum);
|
||||
Serial2.write(CMD_TAIL);
|
||||
|
||||
while ((!Serial2.available()) && timeout > 0)
|
||||
{
|
||||
delay(1);
|
||||
timeout--;
|
||||
}
|
||||
|
||||
uint8_t ch;
|
||||
for(i=0;i<8;i++)
|
||||
{
|
||||
if(Serial2.available()){
|
||||
ch = Serial2.read();
|
||||
FP.RxCnt++;
|
||||
FP.RxBuf[i] = ch;
|
||||
}
|
||||
}
|
||||
|
||||
if (FP.RxCnt != 8) {FP.RxCnt = 0;return ACK_TIMEOUT;}
|
||||
if (FP.RxBuf[HEAD] != CMD_HEAD) return ACK_FAIL;
|
||||
if (FP.RxBuf[TAIL] != CMD_TAIL) return ACK_FAIL;
|
||||
if (FP.RxBuf[CMD] != (FP.TxBuf[CMD])) return ACK_FAIL;
|
||||
|
||||
checkSum = 0;
|
||||
for (j = 1; j < CHK; j++) {
|
||||
checkSum ^= FP.RxBuf[j];
|
||||
}
|
||||
if (checkSum != FP.RxBuf[CHK]) {
|
||||
return ACK_FAIL;
|
||||
}
|
||||
return ACK_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t FingerPrint::fpm_sleep(void)
|
||||
{
|
||||
uint8_t res;
|
||||
|
||||
FP.TxBuf[CMD] = CMD_SLEEP_MODE;
|
||||
FP.TxBuf[P1] = 0;
|
||||
FP.TxBuf[P2] = 0;
|
||||
FP.TxBuf[P3] = 0;
|
||||
|
||||
res = fpm_sendAndReceive(500);
|
||||
|
||||
if(res == ACK_SUCCESS) {
|
||||
return ACK_SUCCESS;
|
||||
}
|
||||
else {
|
||||
return ACK_FAIL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint8_t FingerPrint::fpm_setAddMode(uint8_t fpm_mode)
|
||||
{
|
||||
uint8_t res;
|
||||
|
||||
FP.TxBuf[CMD] = CMD_ADD_MODE;
|
||||
FP.TxBuf[P1] = 0;
|
||||
FP.TxBuf[P2] = fpm_mode;
|
||||
FP.TxBuf[P3] = 0;
|
||||
|
||||
res = fpm_sendAndReceive(200);
|
||||
|
||||
if(res == ACK_SUCCESS && RxBuf[Q3] == ACK_SUCCESS) {
|
||||
return ACK_SUCCESS;
|
||||
}
|
||||
else {
|
||||
return ACK_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t FingerPrint::fpm_readAddMode(void)
|
||||
{
|
||||
FP.TxBuf[CMD] = CMD_ADD_MODE;
|
||||
FP.TxBuf[P1] = 0;
|
||||
FP.TxBuf[P2] = 0;
|
||||
FP.TxBuf[P3] = 0X01;
|
||||
|
||||
fpm_sendAndReceive(200);
|
||||
|
||||
return RxBuf[Q2];
|
||||
}
|
||||
|
||||
uint16_t FingerPrint::fpm_getUserNum(void)
|
||||
{
|
||||
uint8_t res;
|
||||
|
||||
FP.TxBuf[CMD] = CMD_USER_CNT;
|
||||
FP.TxBuf[P1] = 0;
|
||||
FP.TxBuf[P2] = 0;
|
||||
FP.TxBuf[P3] = 0;
|
||||
|
||||
res = fpm_sendAndReceive(200);
|
||||
|
||||
if(res == ACK_SUCCESS && FP.RxBuf[Q3] == ACK_SUCCESS) {
|
||||
return FP.RxBuf[Q2];
|
||||
}
|
||||
else {
|
||||
return 0XFF;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint8_t FingerPrint::fpm_deleteAllUser(void)
|
||||
{
|
||||
uint8_t res;
|
||||
|
||||
FP.TxBuf[CMD] = CMD_DEL_ALL;
|
||||
FP.TxBuf[P1] = 0;
|
||||
FP.TxBuf[P2] = 0;
|
||||
FP.TxBuf[P3] = 0;
|
||||
|
||||
res = fpm_sendAndReceive(200);
|
||||
|
||||
if(res == ACK_SUCCESS && RxBuf[Q3] == ACK_SUCCESS) {
|
||||
return ACK_SUCCESS;
|
||||
}
|
||||
else {
|
||||
return ACK_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t FingerPrint::fpm_deleteUser(uint8_t userNum)
|
||||
{
|
||||
uint8_t res;
|
||||
|
||||
FP.TxBuf[CMD] = CMD_DEL;
|
||||
FP.TxBuf[P1] = 0;
|
||||
FP.TxBuf[P2] = userNum;
|
||||
FP.TxBuf[P3] = 0;
|
||||
|
||||
res = fpm_sendAndReceive(200);
|
||||
|
||||
if(res == ACK_SUCCESS && RxBuf[Q3] == ACK_SUCCESS) {
|
||||
return ACK_SUCCESS;
|
||||
}
|
||||
else {
|
||||
return ACK_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t FingerPrint::fpm_addUser(uint8_t userNum, uint8_t userPermission)
|
||||
{
|
||||
uint8_t res;
|
||||
|
||||
FP.TxBuf[CMD] = CMD_ADD_1;
|
||||
FP.TxBuf[P1] = 0;
|
||||
FP.TxBuf[P2] = userNum;
|
||||
FP.TxBuf[P3] = userPermission;
|
||||
|
||||
res = fpm_sendAndReceive(F_Time);
|
||||
|
||||
if(res == ACK_SUCCESS) {
|
||||
if(FP.RxBuf[Q3] == ACK_SUCCESS) {
|
||||
FP.TxBuf[CMD] = CMD_ADD_2;
|
||||
|
||||
res = fpm_sendAndReceive(F_Time);
|
||||
|
||||
if(res == ACK_SUCCESS) {
|
||||
if(FP.RxBuf[Q3] == ACK_SUCCESS) {
|
||||
FP.TxBuf[CMD] = CMD_ADD_3;
|
||||
|
||||
res = fpm_sendAndReceive(F_Time);
|
||||
|
||||
if(res == ACK_SUCCESS) {
|
||||
return FP.RxBuf[Q3];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
uint8_t FingerPrint::fpm_compareFinger(void)
|
||||
{
|
||||
uint8_t res;
|
||||
|
||||
FP.TxBuf[CMD] = CMD_MATCH;
|
||||
FP.TxBuf[P1] = 0;
|
||||
FP.TxBuf[P2] = 0;
|
||||
FP.TxBuf[P3] = 0;
|
||||
|
||||
res = fpm_sendAndReceive(8000);
|
||||
|
||||
if(res == ACK_SUCCESS)
|
||||
{
|
||||
if(FP.RxBuf[Q3] == ACK_NOUSER) {
|
||||
return ACK_NOUSER;
|
||||
}
|
||||
if(FP.RxBuf[Q3] == ACK_TIMEOUT) {
|
||||
return ACK_TIMEOUT;
|
||||
}
|
||||
if((FP.RxBuf[Q2] != 0) && (FP.RxBuf[Q3] == 1 || FP.RxBuf[Q3] == 2 || FP.RxBuf[Q3] == 3)) {
|
||||
return ACK_SUCCESS;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#ifndef __TFS_M64_H
|
||||
#define __TFS_M64_H
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
#define ACK_SUCCESS 0x00
|
||||
#define ACK_FAIL 0x01
|
||||
#define ACK_FULL 0x04
|
||||
#define ACK_NOUSER 0x05
|
||||
#define ACK_USER_EXIST 0x07
|
||||
#define ACK_TIMEOUT 0x08
|
||||
|
||||
#define ACK_GO_OUT 0x0F
|
||||
|
||||
#define ACK_ALL_USER 0x00
|
||||
#define ACK_GUEST_USER 0x01
|
||||
#define ACK_NORMAL_USER 0x02
|
||||
#define ACK_MASTER_USER 0x03
|
||||
|
||||
#define USER_MAX_CNT 50
|
||||
|
||||
#define HEAD 0
|
||||
#define CMD 1
|
||||
#define CHK 6
|
||||
#define TAIL 7
|
||||
|
||||
#define P1 2
|
||||
#define P2 3
|
||||
#define P3 4
|
||||
#define Q1 2
|
||||
#define Q2 3
|
||||
#define Q3 4
|
||||
|
||||
#define CMD_HEAD 0xF5
|
||||
#define CMD_TAIL 0xF5
|
||||
#define CMD_ADD_1 0x01
|
||||
#define CMD_ADD_2 0x02
|
||||
#define CMD_ADD_3 0x03
|
||||
#define CMD_MATCH 0x0C
|
||||
#define CMD_DEL 0x04
|
||||
#define CMD_DEL_ALL 0x05
|
||||
#define CMD_USER_CNT 0x09
|
||||
#define CMD_SLEEP_MODE 0x2C
|
||||
#define CMD_ADD_MODE 0x2D
|
||||
|
||||
#define CMD_FINGER_DETECTED 0x14
|
||||
|
||||
|
||||
class FingerPrint {
|
||||
|
||||
public:
|
||||
FingerPrint(void);
|
||||
uint8_t fpm_sendAndReceive(uint16_t delayMs);
|
||||
uint8_t fpm_sleep(void);
|
||||
uint8_t fpm_setAddMode(uint8_t fpm_mode);
|
||||
uint8_t fpm_readAddMode(void);
|
||||
uint16_t fpm_getUserNum(void);
|
||||
uint8_t fpm_deleteAllUser(void);
|
||||
uint8_t fpm_deleteUser(uint8_t userNum);
|
||||
uint8_t fpm_addUser(uint8_t userNum, uint8_t userPermission);
|
||||
uint8_t fpm_compareFinger(void);
|
||||
public:
|
||||
uint8_t TxBuf[9];
|
||||
uint8_t RxBuf[9];
|
||||
uint8_t RxCnt;
|
||||
private:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* __TFS-M64_H */
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user