標(biāo)題:
FPM32C指紋模塊源程序
[打印本頁(yè)]
作者:
jia23011
時(shí)間:
2023-7-20 19:52
標(biāo)題:
FPM32C指紋模塊源程序
#include <string.h>
#include "fingerprint_action.h"
#include "fingerprint_type.h"
#include "fingerprint_protocol.h"
static U8Bit s_recv_buffer[256];
static U8Bit s_send_buffer[256];
static U8Bit s_ftrDataBuffer[8196]; //待上傳下載的指紋數(shù)據(jù)buffer
static U32Bit s_ftrDataLength = 0; //待上傳下載的指紋數(shù)據(jù)buffer長(zhǎng)度
#define CHECK_BIT(value, x) ((value) & (1 << (x)))
void Delay_ms(U32Bit delaytime)
{
U32Bit i;
U32Bit j;
for (j = 0; j < delaytime; j++)
{
for (i = 0; i < 10000; i++)
{
//根據(jù)不同的開(kāi)發(fā)環(huán)境實(shí)現(xiàn)延時(shí)
}
}
i=j;
}
void getID(void)
{
U32Bit errorCode;
S32Bit ret;
FP_moduleID_t moduleID;
ret = FP_action_getID(&moduleID, &errorCode);
if(FP_OK == ret && 0 == errorCode)
{
//get ID ok
}
}
void enroll(void)
{
U32Bit errorCode;
S32Bit ret;
U8Bit index = 1;
U8Bit isTouch;
U16Bit SaveID;
FP_enrollResult_t enrollResult;
enrollResult.fingerID = 0;
enrollResult.progress = 0;
//第一次直接enrollStart
goto EnrollStartLabel;
//
//每次enroll過(guò)后,確保手指要抬起來(lái)以后,再次按壓
FingerLeaveLabel:
FP_action_check_finger_is_touch(&isTouch, &errorCode);
if(0 != isTouch || COMP_CODE_OK != errorCode)
{
// 當(dāng)isTouch不是0的時(shí)候,意味著手指在上,
//提示用戶(hù)手指離開(kāi)sensor再次按壓
//printf("lift your finger please !");
//延時(shí) 200 ms
Delay_ms(200);
goto FingerLeaveLabel;
}
//開(kāi)始注冊(cè)
EnrollStartLabel:
ret = FP_action_enroll_start(index, &errorCode);
if(COMP_CODE_OK != errorCode || FP_OK != ret)
{
Delay_ms(100);
//可能上電初始化未完成或睡眠喚醒初始化中
goto EnrollStartLabel;
}
else
{
//可延時(shí)100ms后發(fā)送獲取注冊(cè)結(jié)果命令,采圖后需要大概這么長(zhǎng)時(shí)間處理
Delay_ms(100);
}
//獲取注冊(cè)結(jié)果
EnrollResultLabel:
ret = FP_action_get_enroll_result(&enrollResult, &errorCode);
if(FP_DEVICE_TIMEOUT_ERROR == ret)
{
//接受數(shù)據(jù)超時(shí),根據(jù)接受數(shù)據(jù)所設(shè)超時(shí)時(shí)間適當(dāng)延時(shí)。
Delay_ms(100);
goto EnrollResultLabel;
}
if(COMP_CODE_OK == errorCode)
{
//如果errorCode 是COMP_CODE_OK,說(shuō)明本次enroll執(zhí)行完成,
//此時(shí)可以查看enrollResult.progress是否增加,如果增加,說(shuō)明本次enroll成功
//如果progress >= 100 ,說(shuō)明整個(gè)注冊(cè)流程成功結(jié)束,開(kāi)始根據(jù)enrollResult.fingerID保存指紋
if(enrollResult.progress >= 0x64)
{
goto SaveStartLabel;
}
else
{
//如果progress < 100, 手指離開(kāi)sensor,再次按壓,繼續(xù)注冊(cè)
index++;
//延時(shí) 100 ms
Delay_ms(100);
goto FingerLeaveLabel;
}
}
else if(COMP_CODE_CMD_NOT_FINISHED == errorCode)
{
//errorCode == COMP_CODE_CMD_NOT_FINISHED意味著sensor還沒(méi)有處理完指紋數(shù)據(jù)或沒(méi)有按壓手指,
//適當(dāng)延時(shí),再次獲取結(jié)果
//延時(shí) 100 ms
Delay_ms(100);
goto EnrollResultLabel;
}
else if(COMP_CODE_SAME_ID == errorCode)
{
//errorCode == COMP_CODE_SAME_ID意味著與已注冊(cè)指紋重復(fù),需換手指注冊(cè)
//適當(dāng)延時(shí),再次獲取結(jié)果
//延時(shí) 100 ms
Delay_ms(100);
goto EnrollResultLabel;
}
else if(COMP_CODE_NO_FINGER_DETECT == errorCode)
{
//errorCode == COMP_CODE_NO_FINGER_DETECT意味著超時(shí)還沒(méi)按壓手指
//重新注冊(cè)
}
else if(COMP_CODE_OTHER_ERROR == errorCode)
{
goto EnrollStartLabel;
}
else if(COMP_CODE_NO_REQ_CMD == errorCode)
{
goto EnrollStartLabel;
}
else
{
//圖像質(zhì)量不好,手指可能按壓過(guò)重、過(guò)輕、或者太過(guò)潮濕等,繼續(xù)enrollStart即可,也可根據(jù)Elock用戶(hù)手冊(cè)細(xì)化處理
//延時(shí) 200 ms
Delay_ms(200);
goto EnrollStartLabel;
}
//保存指紋開(kāi)始
//enrollResult.fingerID會(huì)根據(jù)模組回復(fù)的推薦id去保存,編號(hào)從00開(kāi)始
SaveStartLabel:
ret = FP_action_save_start(enrollResult.fingerID, &errorCode);
if(COMP_CODE_OK != errorCode || FP_OK != ret)
{
Delay_ms(100);
goto SaveStartLabel;
}
Delay_ms(200);
//獲取保存指紋結(jié)果
SaveResultLabel://【保存指紋開(kāi)始命令】發(fā)送后,模組需操作flash,這期間大概200ms發(fā)送【獲取保存指紋結(jié)果】沒(méi)有數(shù)據(jù)回復(fù),可超時(shí)重發(fā)
ret = FP_action_get_save_result(&errorCode, &SaveID);
if(FP_DEVICE_TIMEOUT_ERROR == ret)
{
//接受數(shù)據(jù)超時(shí),根據(jù)接受數(shù)據(jù)所設(shè)超時(shí)時(shí)間適當(dāng)延時(shí)。
Delay_ms(100);
goto SaveResultLabel;
}
if(COMP_CODE_OK == errorCode)
{
//查看保存成功的SaveID
//保存完成
}
else if(COMP_CODE_CMD_NOT_FINISHED == errorCode)
{
//還未保存完成,延時(shí)適當(dāng)時(shí)間,再次獲取結(jié)果
//延時(shí) 100 ms
Delay_ms(100);
goto SaveResultLabel;
}
else if(COMP_CODE_STORAGE_IS_FULL == errorCode)
{
//flash存儲(chǔ)已滿(mǎn),不能保存指紋
}
else
{
//其他錯(cuò)誤,比如硬件錯(cuò)誤等。
}
return;
}
void match(void)
{
U32Bit errorCode;
S32Bit ret;
U8Bit isTouch;
FP_matchResult_t matchResult;
/***********************
為了提速,也可以不先檢查手指在位,
不同的模組回復(fù)時(shí)間不同(FPM08X系列模組大約耗時(shí)30ms左右)
************************/
checkFingeronLabel:
FP_action_check_finger_is_touch(&isTouch, &errorCode);
if((0 != isTouch) && (COMP_CODE_OK == errorCode))
{
//當(dāng)isTouch是1的時(shí)候,意味著手指在上,
//播放語(yǔ)音“滴”
}
else
{
//延時(shí) 50 ms
Delay_ms(50);
goto checkFingeronLabel;
}
/**********************/
matchStartLabel:
//開(kāi)始match
ret = FP_action_match_start(&errorCode);
if(COMP_CODE_OK != errorCode || FP_OK != ret)
{
//延時(shí) 50 ms
//可能上電初始化未完成或睡眠喚醒初始化中
Delay_ms(50);
goto matchStartLabel;
}
//匹配處理固定大于300ms;
Delay_ms(300);
//獲取注冊(cè)結(jié)果
matchResultLabel:
ret = FP_action_get_match_result(&matchResult,&errorCode);
if(FP_DEVICE_TIMEOUT_ERROR == ret)
{
//接受數(shù)據(jù)超時(shí),根據(jù)接受數(shù)據(jù)所設(shè)超時(shí)時(shí)間適當(dāng)延時(shí)。
Delay_ms(100);
goto matchResultLabel;
}
if(COMP_CODE_OK == errorCode)
{
//match動(dòng)作完成
/* typedef struct {
* U16Bit isPass;
* U16Bit matchScore;
* U16Bit matchID;
* } FP_matchResult_t, *FP_matchResult_p;
*/
// isPass是1的話(huà),代表已經(jīng)匹配到了指紋,這時(shí),matchID是匹配到的指紋ID
// matchScore是具體匹配的分?jǐn)?shù)
if(1 == matchResult.isPass)
{
//匹配到指紋
}
else
{
//未匹配到指紋
}
}
else if(COMP_CODE_CMD_NOT_FINISHED == errorCode)
{
//還未匹配完成,延時(shí)適當(dāng)時(shí)間,再次獲取結(jié)果,處理指紋需要一些時(shí)間
//延時(shí) 30 ms
Delay_ms(30);
goto matchResultLabel;
}
else if(COMP_CODE_NO_FINGER_DETECT == errorCode)
{
//errorCode == COMP_CODE_NO_FINGER_DETECT意味著超時(shí)還沒(méi)按壓手指
//重新匹配
}
else if(COMP_CODE_NO_REQ_CMD == errorCode)
{
goto matchStartLabel;
}
else if(COMP_CODE_HARDWARE_ERROR == errorCode)
{
//延時(shí) 200 ms
Delay_ms(200);
goto matchStartLabel;
}
else
{
return;
}
}
/***匹配成功后執(zhí)行更新指紋特征(模組自學(xué)習(xí)),有利于優(yōu)化體驗(yàn)*
該命令可在匹配成功以后直接發(fā)送,模組自身會(huì)判斷是否要自學(xué)習(xí),
如果不需要會(huì)返回錯(cuò)誤碼
**/
void updateFeature(void)
{
U32Bit errorCode;
S32Bit ret;
S32Bit updateID = 0;//傳入的ID必須與匹配成功后的ID一致
updatestartLabel:
ret = FP_action_update_start(updateID, &errorCode);
if(COMP_CODE_OK == errorCode)
{
//需要更新,延時(shí)100毫秒
Delay_ms(100);
}
else
{
//不需要更新,直接結(jié)束
return;
}
updateResultLabel:
ret = FP_action_get_update_result(&errorCode);
if(ret == FP_DEVICE_TIMEOUT_ERROR)
{
Delay_ms(100);
goto updateResultLabel;
}
if(COMP_CODE_OK == errorCode)
{
//更新成功;
}
else if(COMP_CODE_CMD_NOT_FINISHED == errorCode)
{
//適當(dāng)延時(shí)100ms,再次獲取
Delay_ms(100);
goto updateResultLabel;
}
else
{
//更新失敗,重新更新,或者退出
goto updatestartLabel;
}
return;
}
void deleteFp(void)
{
U32Bit errorCode;
S32Bit ret;
S16Bit delete_id = -1;
//開(kāi)始刪除,delete_id > 0 的時(shí)候,刪除指定id的指紋。
//delete_id == -1的時(shí)候,刪除所有指紋,
deleteStartLabel:
ret = FP_action_delete_start(delete_id, &errorCode);
if(COMP_CODE_OK != errorCode || FP_OK != ret)
{
//延時(shí) 100 ms
//可能上電初始化未完成或睡眠喚醒初始化中
Delay_ms(100);
goto deleteStartLabel;
}
//獲取刪除結(jié)果
deleteResultLabel:
Delay_ms(100); //延時(shí) 100 ms
ret = FP_action_get_delete_result(&errorCode);
if(ret == FP_DEVICE_TIMEOUT_ERROR)
{
goto deleteResultLabel;
}
if(COMP_CODE_OK == errorCode)
{
//刪除成功
}
else if(COMP_CODE_CMD_NOT_FINISHED == errorCode)
{
//還未刪除完成,再次獲取結(jié)果
goto deleteResultLabel;
}
else
{
//其他錯(cuò)誤,比如指紋ID不存在等、flash硬件錯(cuò)誤等。
}
return;
}
void Sleep(void)
{
U32Bit errorCode;
S32Bit ret;
SleepStartLabel:
ret = FP_action_sleep(sleep_type_normal, &errorCode);
if(FP_OK == ret && 0 == errorCode)
{
//休眠成功,模組進(jìn)入休眠
}
else
{
//延時(shí) 200 ms, 繼續(xù)發(fā)送休眠命令,直到回復(fù)休眠成功為止
Delay_ms(200);
goto SleepStartLabel;
}
}
void autoEnroll(void)
{
U32Bit errorCode;
S32Bit ret;
FP_auto_enroll_t enrollPara;
FP_enrollResult_t EnrollResult;
U32Bit timeout = 10000; //建議超時(shí)時(shí)間設(shè)為10s
enrollPara.fingerID_high = 0xFF; //可修改ID,若 ID 為 0xFFFF 則由系統(tǒng)自動(dòng)分配指紋 ID 。
enrollPara.fingerID_low = 0xFF; //可修改ID,若 ID 為 0xFFFF 則由系統(tǒng)自動(dòng)分配指紋 ID 。
enrollPara.enroll_mode = 0x01; //設(shè)置為 1則表示按壓后需要等待手指抬起再次才可以進(jìn)行下次注冊(cè),設(shè)置為0則不需要。
enrollPara.times = 3; //可修改注冊(cè)次數(shù),范圍:1~6次
SendEnrollStartLabel:
ret = FP_action_auto_enroll_send(enrollPara);
if(FP_OK != ret)
{
goto SendEnrollStartLabel;
}
GetEnrollResultLabel:
ret = FP_action_auto_enroll_recv( &EnrollResult , &errorCode, timeout); //處理返回碼
if(0 != ret)
{
//可能在等待手指按壓,或者正在處理注冊(cè),再重新查詢(xún)是否接收到
goto GetEnrollResultLabel;
}
if(errorCode == COMP_CODE_CMD_DATA_LEN_ERROR || errorCode == COMP_CODE_CMD_DATA_ERROR)
{
//檢查命令是否發(fā)錯(cuò),重新開(kāi)始注冊(cè)
goto SendEnrollStartLabel;
}
if(errorCode == COMP_CODE_STORAGE_IS_FULL)
{
//指紋容量已滿(mǎn),退出
return;
}
if((100 == EnrollResult.progress) && (EnrollResult.state == 0xff))
{
if(COMP_CODE_OK == errorCode)
{
// 進(jìn)度100,state=0XFF時(shí)才認(rèn)為注冊(cè)成功
// 注冊(cè)成功
}
else
{
//存儲(chǔ)出了問(wèn)題,重新開(kāi)始注冊(cè)
goto SendEnrollStartLabel;
}
}
else
{
if(errorCode == COMP_CODE_OK)
{
//單次注冊(cè)成功,繼續(xù)按壓
}
else if(errorCode == COMP_CODE_SAME_ID)
{
//重復(fù)指紋,可提示用戶(hù)換手指按壓
}
else if(errorCode == COMP_CODE_UNQUALIFIED_IMAGE_ERROR)
{
//采圖質(zhì)量不好,繼續(xù)按壓直到成功
}
else if(errorCode == COMP_CODE_NO_FINGER_DETECT)
{
//8S超時(shí)還沒(méi)按壓手指,繼續(xù)按壓直到注冊(cè)成功;
}
else
{
//其他問(wèn)題,繼續(xù)按壓
}
//繼續(xù)獲取下一次結(jié)果
goto GetEnrollResultLabel;
}
return;
}
void matchSyn(void)
{
U32Bit errorCode;
S32Bit ret;
U32Bit timeout = 10000; //建議超時(shí)時(shí)間設(shè)為10s
FP_matchResult_t matchResult;
matchSynSendLabel:
ret = FP_action_match_syn_send();
if(FP_OK != ret)
{
goto matchSynSendLabel;
}
getMatchSynResultLabel:
ret = FP_action_match_syn_recv(&matchResult, &errorCode, timeout);
if(FP_DEVICE_TIMEOUT_ERROR == ret)
{
//可能在等待手指按壓,或者正在處理匹配,再重新查詢(xún)是否接收到
goto getMatchSynResultLabel;
}
if((FP_OK == ret) && (COMP_CODE_OK == errorCode))
{
if(1 == matchResult.isPass)
{
//匹配成功
//同步匹配會(huì)自帶自學(xué)習(xí)功能,所以耗時(shí)會(huì)相對(duì)于分步匹配長(zhǎng)一點(diǎn)
}
else
{
//匹配失敗
}
}
else if(COMP_CODE_NO_FINGER_DETECT == errorCode)
{
//沒(méi)有手指按壓
}
else if(COMP_CODE_UNQUALIFIED_IMAGE_ERROR == errorCode)
{
//采圖質(zhì)量不佳
goto matchSynSendLabel;
}
else
{
//其他錯(cuò)誤
}
}
void deleteSyn(void)
{
U32Bit errorCode;
S32Bit ret;
U32Bit timeout = 1000; //建議超時(shí)時(shí)間設(shè)為1s
S16Bit delete_id = -1;
//delete_id > 0 的時(shí)候,刪除指定id的指紋。
//delete_id == -1的時(shí)候,刪除所有指紋,
SendDeleteStartLabel:
ret = FP_action_delete_syn_send(delete_id);
if(FP_OK != ret)
{
goto SendDeleteStartLabel;
}
GetDeleteResultLabel:
ret = FP_action_delete_syn_recv(&errorCode, timeout);
if(ret == FP_DEVICE_TIMEOUT_ERROR)
{
goto GetDeleteResultLabel;
}
if((FP_OK == ret) && (COMP_CODE_OK == errorCode))
{
//刪除成功
}
else
{
//其他錯(cuò)誤,比如指紋ID不存在等、flash硬件錯(cuò)誤等。
}
return;
}
/**********************************************************************************************
上傳指紋特征:適用于FPM08X系列軟件版本大于118的模組(如版本號(hào)為:FPM083-00-118);
一般的,分為三種應(yīng)用場(chǎng)景:
1、上傳模組內(nèi)正在注冊(cè)的id:替代保存指紋命令(0x13)+ 查詢(xún)保存結(jié)果命令(0x14),
直接將指紋數(shù)據(jù)上傳至上位機(jī);
2、上傳模組內(nèi)存儲(chǔ)的指定一個(gè)id:上傳之前,需確認(rèn)id是否存在,如果存在則繼續(xù)上傳;
3、上傳模組內(nèi)存儲(chǔ)的所有id;上傳之前,需獲取指紋模板分布,然后根據(jù)分布指定id號(hào),一個(gè)一個(gè)上傳;
*********************************************************************************************/
void uploadFTR(void)
{
FP_ftrData_t uploadftrData;
FP_ftrDistribution_t distribution;
U32Bit errorCode;
S32Bit ret;
U16Bit ftrLength;
S32Bit i = 0;
U16Bit frameCount;
U8Bit ftrReceiveBuffer[128]; //每幀命令回復(fù)的buffer
U8Bit err_num = 0;
/*
typedef struct {
U16Bit id; //待上傳的指紋id
U16Bit length; //待上傳的指紋數(shù)據(jù)長(zhǎng)度
U8Bit *data;
}FP_ftrData_t, *FP_ftrData_p;
*/
uploadftrData.data = s_ftrDataBuffer;
uploadftrData.id = 0x00;
/******上傳模組內(nèi)正在注冊(cè)的id*************
//注冊(cè)進(jìn)度100%
//保存指紋開(kāi)始
uploadftrData.id = 0xFFFF; //當(dāng)id為0XFFFF時(shí),可直接上傳
goto UploadFtrGetInfoLabel;
*****************************************/
UploadFtrCheckFtrLabel:
ret = FP_action_get_ftr_distribution(&distribution, &errorCode);
if(FP_OK != ret || errorCode != FP_OK)
{
//錯(cuò)誤,重新發(fā)送
Delay_ms(100);
goto UploadFtrCheckFtrLabel;
}
/*****************上傳模組內(nèi)存儲(chǔ)的指定一個(gè)id**********/
// Printf("distribution[] = 0x%x\r\n", distribution.distributon[check_id >> 3]);
if(0 == CHECK_BIT(distribution.distributon[uploadftrData.id >> 3], (uploadftrData.id & 0x7)))
{
//id不存在,重新輸出正確id號(hào)
Delay_ms(100);
goto UploadFtrCheckFtrLabel;
}
/****************************************************/
/*********上傳模組內(nèi)存儲(chǔ)的所有id********************
S16Bit upload_id[100] = 0; //待上傳的id,用于上傳所有指紋
U8Bit currentByte = 0;
S16Bit *p = &upload_id[0];
for(int i = 0; i <= (distribution.ftrMaxCount >> 3); i++)
{
currentByte = distribution.distributon[i];
for(int j = 0; j < 8; j++)
{
if(CHECK_BIT(currentByte,j))
{
*p = i*8 + j;
p++;
}
}
}
**************************************************/
UploadFtrGetInfoLabel:
ret= FP_action_get_ftr_info(&uploadftrData, &errorCode);
if( FP_OK != ret)
{
Delay_ms(100);
goto UploadFtrGetInfoLabel;
}
ftrLength = uploadftrData.length;
frameCount = ((ftrLength - 1) >> 7) + 1;
UploadFtrGetDataLabel:
for(; i < frameCount; i++)
{
ret = FP_action_get_ftr_data(i, ftrReceiveBuffer, &errorCode);
if(ret != FP_OK || errorCode != FP_OK)
{
err_num++;
if(err_num < 3)
{
//數(shù)據(jù)接收有誤重新發(fā)送該幀
goto UploadFtrGetDataLabel;
}
else
{
//如果超過(guò)3次,報(bào)錯(cuò)退出
return;
}
}
else
{
err_num = 0;
memcpy(uploadftrData.data + 128*i, ftrReceiveBuffer, 128); //模組每幀回復(fù)的數(shù)據(jù)長(zhǎng)度其實(shí)是固定的128字節(jié)
}
}
s_ftrDataLength = ftrLength;
/*
FTR存儲(chǔ)在上位機(jī)數(shù)據(jù)庫(kù)前
需對(duì)ftrData的長(zhǎng)度f(wàn)trLength進(jìn)行記錄,作為該指紋下載時(shí)的長(zhǎng)度;
可把ftrData打包一下(加一個(gè)CRC或奇偶校驗(yàn))
*/
}
/*********************************************************************************************
下載指紋特征:適用于FPM08X系列軟件版本大于118的模組(如版本號(hào)為:FPM083-00-118);
將指紋數(shù)據(jù)分發(fā)到模組中
*/
void downloadFTR(void)
{
FP_ftrData_t downloadftrData;
U8Bit ftrSentBuffer[128]; //每幀命令發(fā)送的buffer
U16Bit i = 0;
U16Bit remainLength;
U16Bit currentLength;
U16Bit frameCount;
U32Bit errorCode;
U32Bit ret;
U32Bit timeout = DEFAULT_TIME_OUT;
U8Bit err_num = 0;
/*
typedef struct {
U16Bit id; //待下載的指紋id
U16Bit length; //待下載的指紋數(shù)據(jù)長(zhǎng)度
U8Bit *data;
}FP_ftrData_t, *FP_ftrData_p;
*/
downloadftrData.data = s_ftrDataBuffer;
downloadftrData.length = s_ftrDataLength;
downloadftrData.id = 0;
DownloadFtrSentInfoLabel:
ret = FP_action_write_ftr_info(&downloadftrData, &errorCode);
if(FP_OK != ret || errorCode != FP_OK)
{
Delay_ms(100);
goto DownloadFtrSentInfoLabel;
}
remainLength = downloadftrData.length;
currentLength = 128;
frameCount = ((downloadftrData.length - 1) >> 7) + 1;
DownloadFtrSentDataLabel:
for(; i < frameCount; i++)
{
memcpy(ftrSentBuffer, downloadftrData.data + 128*i, currentLength);
//如果發(fā)最后一幀,由于模組需要存儲(chǔ)指紋,命令超時(shí)時(shí)間需久一點(diǎn), 1S比較合適
if (i == frameCount - 1)
{
timeout = 1000;
}
ret = FP_action_write_ftr_data(i, ftrSentBuffer, currentLength, &errorCode, timeout);
if(FP_OK != ret || errorCode != FP_OK)
{
err_num++;
if(err_num < 3)
{
//數(shù)據(jù)發(fā)送有誤,重新發(fā)送該幀
Delay_ms(100);
goto DownloadFtrSentDataLabel;
}
else
{
//如果超過(guò)3次,報(bào)錯(cuò)退出
return;
}
}
else
{
err_num = 0;
remainLength -= currentLength;
if(remainLength < 128)
{
currentLength = remainLength;
}
}
}
}
/*********************************************************************************************
設(shè)置 LED 控制信息:適用于帶LED燈的模組;
*/
void setLed(void)
{
U32Bit errorCode;
S32Bit ret;
FP_LED_CTRL_INFO stLEDCtrlInfo;
setLedStartLabel:
/**燈的模式與顏色按需求設(shè)置,以下為參考范例1:閃爍綠燈5次,亮的時(shí)間為200ms,滅的時(shí)間為200ms*/
stLEDCtrlInfo.ucLEDCtrlMode = EM_LED_CTRL_BLINK;
stLEDCtrlInfo.ucLEDColor = EM_LED_GREEN;
stLEDCtrlInfo.usLEDpara1 = 0x14; //點(diǎn)亮?xí)r長(zhǎng)
stLEDCtrlInfo.usLEDpara2 = 0x14; //熄滅時(shí)長(zhǎng)
stLEDCtrlInfo.usLEDpara3 = 0x5; //閃爍次數(shù)
/***/
/**燈的模式與顏色按需求設(shè)置,以下為參考范例2:藍(lán)燈呼吸,最大占空比100,最小占空比0,占空比每秒變化50%)*
stLEDCtrlInfo.ucLEDCtrlMode = EM_LED_CTRL_PWM;
stLEDCtrlInfo.ucLEDColor = EM_LED_BLUE;
stLEDCtrlInfo.usLEDpara1 = 0x64; //最大占空比
stLEDCtrlInfo.usLEDpara2 = 0x00; //熄滅時(shí)長(zhǎng)
stLEDCtrlInfo.usLEDpara3 = 0x32; //閃爍次數(shù)
***/
ret = FP_action_set_led(&stLEDCtrlInfo, &errorCode);
if(FP_OK == ret && 0 == errorCode)
{
//點(diǎn)燈成功
}
else
{
//延時(shí) 50 ms, 繼續(xù)發(fā)送點(diǎn)燈命令,或者直接退出
Delay_ms(50);
goto setLedStartLabel;
}
}
/*********************************************************************************************
設(shè)置系統(tǒng)策略:用于設(shè)置模組默認(rèn)的功能;如關(guān)閉重復(fù)指紋檢查功能
*/
void setSysPolicy(void)
{
U32Bit errorCode;
S32Bit ret;
U32Bit SysPolicy_value;
U32Bit SysPolicy_bit_selflearn = 0x00000002; //重復(fù)指紋檢查功能的位
U32Bit timeout = 1000; //建議超時(shí)時(shí)間設(shè)為1s
/**設(shè)置系統(tǒng)策略之前,先獲取系統(tǒng)策略*/
getSysPolicyLabel:
ret = FP_action_get_SysPolicy(&SysPolicy_value, &errorCode);
if(FP_OK == ret && 0 == errorCode)
{
//獲取策略成功
}
else
{
//延時(shí) 50 ms, 繼續(xù)發(fā)送點(diǎn)燈命令,或者直接退出
Delay_ms(50);
goto getSysPolicyLabel;
}
setSysPolicyLabel:
SysPolicy_value &= ~SysPolicy_bit_selflearn;
ret = FP_action_set_SysPolicy(&SysPolicy_value, &errorCode, timeout); //處理返回碼
if(FP_OK == ret && 0 == errorCode)
{
//獲取策略成功后,模組會(huì)自行復(fù)位
Delay_ms(200);
return;
}
else
{
//延時(shí) 50 ms, 繼續(xù)發(fā)送
Delay_ms(50);
goto setSysPolicyLabel;
}
}
void demo_main(U8Bit command)
{
//設(shè)置指紋收發(fā)的buffer
FP_action_set_send_buffer(s_send_buffer);
FP_action_set_recv_buffer(s_recv_buffer);
switch(command)
{
case 0:
getID();
break;
case 1:
enroll();
break;
case 2:
match();
break;
case 3:
deleteFp();
break;
case 4:
Sleep();
break;
case 5:
updateFeature();
break;
case 6:
autoEnroll();
break;
case 7:
matchSyn();
break;
case 8:
deleteSyn();
break;
case 9:
uploadFTR();
break;
case 10:
downloadFTR();
break;
case 11:
setLed();
break;
case 12:
setSysPolicy();
break;
default:
break;
}
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1