-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08bfd56
commit 65183ae
Showing
7 changed files
with
785 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,81 @@ | ||
/* | ||
******************************************************************************* | ||
* Copyright (c) 2021 by M5Stack | ||
* Equipped with M5StickC sample source code | ||
* 配套 M5StickC 示例源代码 | ||
* 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 <M5StickC.h> | ||
#include "M5_FPC1020A.h" | ||
#include "finger.h" | ||
|
||
uint8_t userNum; //User number | ||
FingerPrint FP_M; | ||
|
||
void CleanScreen() | ||
{ | ||
M5.Lcd.setTextColor(WHITE); | ||
M5.Lcd.fillRect(0,50,400,300,BLACK); | ||
M5.Lcd.setCursor(0, 10); | ||
userNum = FP_M.fpm_getUserNum(); | ||
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(); | ||
Serial2.begin(19200, SERIAL_8N1, 33, 32); | ||
M5.Lcd.setRotation(3); | ||
M5.Lcd.setCursor(0, 0); | ||
M5.Lcd.println("Finger example"); | ||
M5.Lcd.setTextColor(WHITE); | ||
M5.Lcd.setCursor(0, 10); | ||
userNum = FP_M.fpm_getUserNum(); | ||
M5.begin(); | ||
//Serial.begin(19200); | ||
Serial2.begin(19200, SERIAL_8N1, 33, 32); | ||
M5.Lcd.setRotation(3); | ||
//M5.Lcd.clear(BLACK); | ||
//M5.Lcd.setTextColor(YELLOW); | ||
//M5.Lcd.setTextFont(2); | ||
//M5.Lcd.setTextSize(3); | ||
M5.Lcd.setCursor(0, 0); | ||
M5.Lcd.println("Finger example"); | ||
|
||
M5.Lcd.setTextColor(WHITE); | ||
M5.Lcd.setCursor(0, 50); | ||
userNum = FP_M.fpm_getUserNum(); | ||
M5.Lcd.print("userNum:"); | ||
M5.Lcd.println(userNum); | ||
|
||
} | ||
|
||
//ButtonA: Add user | ||
//ButtonB: Matching | ||
void loop(){ | ||
uint8_t res1; | ||
//ButtonA: Add user. 添加用户 | ||
M5.Lcd.setCursor(0, 10); | ||
M5.Lcd.setTextSize(1); | ||
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"); | ||
|
||
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++; | ||
} | ||
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(res1 == ACK_NOUSER){ | ||
M5.Lcd.println("No Such User"); | ||
} | ||
if(res1 == ACK_TIMEOUT){ | ||
M5.Lcd.println("Timeout"); | ||
|
||
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"); | ||
} | ||
} | ||
} | ||
M5.update(); | ||
|
||
M5.update(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
#include <M5StickC.h> | ||
#include "finger.h" | ||
|
||
|
||
FingerPrint::FingerPrint(void){ | ||
|
||
} | ||
|
||
FingerPrint FP; | ||
|
||
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 (FP.RxCnt < 8 && 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 FP.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 && 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(30000); | ||
|
||
if(res == ACK_SUCCESS) { | ||
if(FP.RxBuf[Q3] == ACK_SUCCESS) { | ||
FP.TxBuf[CMD] = CMD_ADD_2; | ||
|
||
res = fpm_sendAndReceive(30000); | ||
|
||
if(res == ACK_SUCCESS) { | ||
if(FP.RxBuf[Q3] == ACK_SUCCESS) { | ||
FP.TxBuf[CMD] = CMD_ADD_3; | ||
|
||
res = fpm_sendAndReceive(30000); | ||
|
||
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(30000); | ||
|
||
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; | ||
} | ||
|
||
|
Oops, something went wrong.