- #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長度
- #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ù)不同的開發(fā)環(huán)境實現(xiàn)延時
- }
- }
- 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過后,確保手指要抬起來以后,再次按壓
- FingerLeaveLabel:
- FP_action_check_finger_is_touch(&isTouch, &errorCode);
- if(0 != isTouch || COMP_CODE_OK != errorCode)
- {
- // 當isTouch不是0的時候,意味著手指在上,
- //提示用戶手指離開sensor再次按壓
- //printf("lift your finger please !");
- //延時 200 ms
- Delay_ms(200);
- goto FingerLeaveLabel;
- }
- //開始注冊
- EnrollStartLabel:
- ret = FP_action_enroll_start(index, &errorCode);
- if(COMP_CODE_OK != errorCode || FP_OK != ret)
- {
- Delay_ms(100);
- //可能上電初始化未完成或睡眠喚醒初始化中
- goto EnrollStartLabel;
- }
- else
- {
- //可延時100ms后發(fā)送獲取注冊結(jié)果命令,采圖后需要大概這么長時間處理
- Delay_ms(100);
- }
- //獲取注冊結(jié)果
- EnrollResultLabel:
- ret = FP_action_get_enroll_result(&enrollResult, &errorCode);
- if(FP_DEVICE_TIMEOUT_ERROR == ret)
- {
- //接受數(shù)據(jù)超時,根據(jù)接受數(shù)據(jù)所設(shè)超時時間適當延時。
- Delay_ms(100);
- goto EnrollResultLabel;
- }
- if(COMP_CODE_OK == errorCode)
- {
- //如果errorCode 是COMP_CODE_OK,說明本次enroll執(zhí)行完成,
- //此時可以查看enrollResult.progress是否增加,如果增加,說明本次enroll成功
- //如果progress >= 100 ,說明整個注冊流程成功結(jié)束,開始根據(jù)enrollResult.fingerID保存指紋
- if(enrollResult.progress >= 0x64)
- {
- goto SaveStartLabel;
- }
- else
- {
- //如果progress < 100, 手指離開sensor,再次按壓,繼續(xù)注冊
- index++;
- //延時 100 ms
- Delay_ms(100);
- goto FingerLeaveLabel;
- }
- }
- else if(COMP_CODE_CMD_NOT_FINISHED == errorCode)
- {
- //errorCode == COMP_CODE_CMD_NOT_FINISHED意味著sensor還沒有處理完指紋數(shù)據(jù)或沒有按壓手指,
- //適當延時,再次獲取結(jié)果
- //延時 100 ms
- Delay_ms(100);
- goto EnrollResultLabel;
- }
- else if(COMP_CODE_SAME_ID == errorCode)
- {
- //errorCode == COMP_CODE_SAME_ID意味著與已注冊指紋重復,需換手指注冊
- //適當延時,再次獲取結(jié)果
- //延時 100 ms
- Delay_ms(100);
- goto EnrollResultLabel;
- }
- else if(COMP_CODE_NO_FINGER_DETECT == errorCode)
- {
- //errorCode == COMP_CODE_NO_FINGER_DETECT意味著超時還沒按壓手指
- //重新注冊
- }
- else if(COMP_CODE_OTHER_ERROR == errorCode)
- {
- goto EnrollStartLabel;
- }
- else if(COMP_CODE_NO_REQ_CMD == errorCode)
- {
- goto EnrollStartLabel;
- }
- else
- {
- //圖像質(zhì)量不好,手指可能按壓過重、過輕、或者太過潮濕等,繼續(xù)enrollStart即可,也可根據(jù)Elock用戶手冊細化處理
- //延時 200 ms
- Delay_ms(200);
- goto EnrollStartLabel;
- }
- //保存指紋開始
- //enrollResult.fingerID會根據(jù)模組回復的推薦id去保存,編號從00開始
- 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://【保存指紋開始命令】發(fā)送后,模組需操作flash,這期間大概200ms發(fā)送【獲取保存指紋結(jié)果】沒有數(shù)據(jù)回復,可超時重發(fā)
- ret = FP_action_get_save_result(&errorCode, &SaveID);
- if(FP_DEVICE_TIMEOUT_ERROR == ret)
- {
- //接受數(shù)據(jù)超時,根據(jù)接受數(shù)據(jù)所設(shè)超時時間適當延時。
- Delay_ms(100);
- goto SaveResultLabel;
- }
-
- if(COMP_CODE_OK == errorCode)
- {
- //查看保存成功的SaveID
- //保存完成
- }
- else if(COMP_CODE_CMD_NOT_FINISHED == errorCode)
- {
- //還未保存完成,延時適當時間,再次獲取結(jié)果
- //延時 100 ms
- Delay_ms(100);
- goto SaveResultLabel;
- }
- else if(COMP_CODE_STORAGE_IS_FULL == errorCode)
- {
- //flash存儲已滿,不能保存指紋
- }
- else
- {
- //其他錯誤,比如硬件錯誤等。
- }
- return;
- }
- void match(void)
- {
- U32Bit errorCode;
- S32Bit ret;
- U8Bit isTouch;
- FP_matchResult_t matchResult;
- /***********************
- 為了提速,也可以不先檢查手指在位,
- 不同的模組回復時間不同(FPM08X系列模組大約耗時30ms左右)
- ************************/
- checkFingeronLabel:
- FP_action_check_finger_is_touch(&isTouch, &errorCode);
- if((0 != isTouch) && (COMP_CODE_OK == errorCode))
- {
- //當isTouch是1的時候,意味著手指在上,
- //播放語音“滴”
- }
- else
- {
- //延時 50 ms
- Delay_ms(50);
- goto checkFingeronLabel;
- }
- /**********************/
- matchStartLabel:
- //開始match
- ret = FP_action_match_start(&errorCode);
- if(COMP_CODE_OK != errorCode || FP_OK != ret)
- {
- //延時 50 ms
- //可能上電初始化未完成或睡眠喚醒初始化中
- Delay_ms(50);
- goto matchStartLabel;
- }
- //匹配處理固定大于300ms;
- Delay_ms(300);
- //獲取注冊結(jié)果
- matchResultLabel:
- ret = FP_action_get_match_result(&matchResult,&errorCode);
- if(FP_DEVICE_TIMEOUT_ERROR == ret)
- {
- //接受數(shù)據(jù)超時,根據(jù)接受數(shù)據(jù)所設(shè)超時時間適當延時。
- Delay_ms(100);
- goto matchResultLabel;
- }
- if(COMP_CODE_OK == errorCode)
- {
- //match動作完成
- /* typedef struct {
- * U16Bit isPass;
- * U16Bit matchScore;
- * U16Bit matchID;
- * } FP_matchResult_t, *FP_matchResult_p;
- */
- // isPass是1的話,代表已經(jīng)匹配到了指紋,這時,matchID是匹配到的指紋ID
- // matchScore是具體匹配的分數(shù)
- if(1 == matchResult.isPass)
- {
- //匹配到指紋
- }
- else
- {
- //未匹配到指紋
- }
- }
- else if(COMP_CODE_CMD_NOT_FINISHED == errorCode)
- {
- //還未匹配完成,延時適當時間,再次獲取結(jié)果,處理指紋需要一些時間
- //延時 30 ms
- Delay_ms(30);
- goto matchResultLabel;
- }
- else if(COMP_CODE_NO_FINGER_DETECT == errorCode)
- {
- //errorCode == COMP_CODE_NO_FINGER_DETECT意味著超時還沒按壓手指
- //重新匹配
- }
- else if(COMP_CODE_NO_REQ_CMD == errorCode)
- {
- goto matchStartLabel;
- }
- else if(COMP_CODE_HARDWARE_ERROR == errorCode)
- {
- //延時 200 ms
- Delay_ms(200);
- goto matchStartLabel;
- }
- else
- {
- return;
- }
- }
- /***匹配成功后執(zhí)行更新指紋特征(模組自學習),有利于優(yōu)化體驗*
- 該命令可在匹配成功以后直接發(fā)送,模組自身會判斷是否要自學習,
- 如果不需要會返回錯誤碼
- **/
- 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)
- {
- //需要更新,延時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)
- {
- //適當延時100ms,再次獲取
- Delay_ms(100);
- goto updateResultLabel;
- }
- else
- {
- //更新失敗,重新更新,或者退出
- goto updatestartLabel;
- }
-
- return;
- }
- void deleteFp(void)
- {
- U32Bit errorCode;
- S32Bit ret;
- S16Bit delete_id = -1;
- //開始刪除,delete_id > 0 的時候,刪除指定id的指紋。
- //delete_id == -1的時候,刪除所有指紋,
- deleteStartLabel:
- ret = FP_action_delete_start(delete_id, &errorCode);
- if(COMP_CODE_OK != errorCode || FP_OK != ret)
- {
- //延時 100 ms
- //可能上電初始化未完成或睡眠喚醒初始化中
- Delay_ms(100);
- goto deleteStartLabel;
- }
- //獲取刪除結(jié)果
- deleteResultLabel:
- Delay_ms(100); //延時 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
- {
- //其他錯誤,比如指紋ID不存在等、flash硬件錯誤等。
- }
- return;
- }
- void Sleep(void)
- {
- U32Bit errorCode;
- S32Bit ret;
- SleepStartLabel:
- ret = FP_action_sleep(sleep_type_normal, &errorCode);
- if(FP_OK == ret && 0 == errorCode)
- {
- //休眠成功,模組進入休眠
- }
- else
- {
- //延時 200 ms, 繼續(xù)發(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è)為10s
- enrollPara.fingerID_high = 0xFF; //可修改ID,若 ID 為 0xFFFF 則由系統(tǒng)自動分配指紋 ID 。
- enrollPara.fingerID_low = 0xFF; //可修改ID,若 ID 為 0xFFFF 則由系統(tǒng)自動分配指紋 ID 。
-
- enrollPara.enroll_mode = 0x01; //設(shè)置為 1則表示按壓后需要等待手指抬起再次才可以進行下次注冊,設(shè)置為0則不需要。
- enrollPara.times = 3; //可修改注冊次數(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)
- {
- //可能在等待手指按壓,或者正在處理注冊,再重新查詢是否接收到
- goto GetEnrollResultLabel;
- }
- if(errorCode == COMP_CODE_CMD_DATA_LEN_ERROR || errorCode == COMP_CODE_CMD_DATA_ERROR)
- {
- //檢查命令是否發(fā)錯,重新開始注冊
- goto SendEnrollStartLabel;
- }
- if(errorCode == COMP_CODE_STORAGE_IS_FULL)
- {
- //指紋容量已滿,退出
- return;
- }
- if((100 == EnrollResult.progress) && (EnrollResult.state == 0xff))
- {
- if(COMP_CODE_OK == errorCode)
- {
- // 進度100,state=0XFF時才認為注冊成功
- // 注冊成功
- }
- else
- {
- //存儲出了問題,重新開始注冊
- goto SendEnrollStartLabel;
- }
- }
- else
- {
- if(errorCode == COMP_CODE_OK)
- {
- //單次注冊成功,繼續(xù)按壓
- }
- else if(errorCode == COMP_CODE_SAME_ID)
- {
- //重復指紋,可提示用戶換手指按壓
- }
- else if(errorCode == COMP_CODE_UNQUALIFIED_IMAGE_ERROR)
- {
- //采圖質(zhì)量不好,繼續(xù)按壓直到成功
- }
- else if(errorCode == COMP_CODE_NO_FINGER_DETECT)
- {
- //8S超時還沒按壓手指,繼續(xù)按壓直到注冊成功;
- }
- else
- {
- //其他問題,繼續(xù)按壓
- }
- //繼續(xù)獲取下一次結(jié)果
- goto GetEnrollResultLabel;
- }
- return;
- }
- void matchSyn(void)
- {
- U32Bit errorCode;
- S32Bit ret;
- U32Bit timeout = 10000; //建議超時時間設(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)
- {
- //可能在等待手指按壓,或者正在處理匹配,再重新查詢是否接收到
- goto getMatchSynResultLabel;
- }
- if((FP_OK == ret) && (COMP_CODE_OK == errorCode))
- {
- if(1 == matchResult.isPass)
- {
- //匹配成功
- //同步匹配會自帶自學習功能,所以耗時會相對于分步匹配長一點
- }
- else
- {
- //匹配失敗
- }
- }
- else if(COMP_CODE_NO_FINGER_DETECT == errorCode)
- {
- //沒有手指按壓
- }
- else if(COMP_CODE_UNQUALIFIED_IMAGE_ERROR == errorCode)
- {
- //采圖質(zhì)量不佳
- goto matchSynSendLabel;
- }
- else
- {
- //其他錯誤
- }
- }
- void deleteSyn(void)
- {
- U32Bit errorCode;
- S32Bit ret;
- U32Bit timeout = 1000; //建議超時時間設(shè)為1s
- S16Bit delete_id = -1;
- //delete_id > 0 的時候,刪除指定id的指紋。
- //delete_id == -1的時候,刪除所有指紋,
- 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
- {
- //其他錯誤,比如指紋ID不存在等、flash硬件錯誤等。
- }
- return;
- }
- /**********************************************************************************************
- 上傳指紋特征:適用于FPM08X系列軟件版本大于118的模組(如版本號為:FPM083-00-118);
- 一般的,分為三種應(yīng)用場景:
- 1、上傳模組內(nèi)正在注冊的id:替代保存指紋命令(0x13)+ 查詢保存結(jié)果命令(0x14),
- 直接將指紋數(shù)據(jù)上傳至上位機;
- 2、上傳模組內(nèi)存儲的指定一個id:上傳之前,需確認id是否存在,如果存在則繼續(xù)上傳;
- 3、上傳模組內(nèi)存儲的所有id;上傳之前,需獲取指紋模板分布,然后根據(jù)分布指定id號,一個一個上傳;
- *********************************************************************************************/
- 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]; //每幀命令回復的buffer
- U8Bit err_num = 0;
- /*
- typedef struct {
- U16Bit id; //待上傳的指紋id
- U16Bit length; //待上傳的指紋數(shù)據(jù)長度
- U8Bit *data;
- }FP_ftrData_t, *FP_ftrData_p;
- */
- uploadftrData.data = s_ftrDataBuffer;
- uploadftrData.id = 0x00;
- /******上傳模組內(nèi)正在注冊的id*************
- //注冊進度100%
- //保存指紋開始
- uploadftrData.id = 0xFFFF; //當id為0XFFFF時,可直接上傳
- goto UploadFtrGetInfoLabel;
- *****************************************/
- UploadFtrCheckFtrLabel:
- ret = FP_action_get_ftr_distribution(&distribution, &errorCode);
- if(FP_OK != ret || errorCode != FP_OK)
- {
- //錯誤,重新發(fā)送
- Delay_ms(100);
- goto UploadFtrCheckFtrLabel;
- }
- /*****************上傳模組內(nèi)存儲的指定一個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號
- Delay_ms(100);
- goto UploadFtrCheckFtrLabel;
- }
- /****************************************************/
- /*********上傳模組內(nèi)存儲的所有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
- {
- //如果超過3次,報錯退出
- return;
- }
- }
- else
- {
- err_num = 0;
- memcpy(uploadftrData.data + 128*i, ftrReceiveBuffer, 128); //模組每幀回復的數(shù)據(jù)長度其實是固定的128字節(jié)
- }
- }
- s_ftrDataLength = ftrLength;
- /*
- FTR存儲在上位機數(shù)據(jù)庫前
- 需對ftrData的長度ftrLength進行記錄,作為該指紋下載時的長度;
- 可把ftrData打包一下(加一個CRC或奇偶校驗)
- */
- }
- /*********************************************************************************************
- 下載指紋特征:適用于FPM08X系列軟件版本大于118的模組(如版本號為: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ù)長度
- 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ā)最后一幀,由于模組需要存儲指紋,命令超時時間需久一點, 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
- {
- //如果超過3次,報錯退出
- 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次,亮的時間為200ms,滅的時間為200ms*/
- stLEDCtrlInfo.ucLEDCtrlMode = EM_LED_CTRL_BLINK;
- stLEDCtrlInfo.ucLEDColor = EM_LED_GREEN;
- stLEDCtrlInfo.usLEDpara1 = 0x14; //點亮時長
- stLEDCtrlInfo.usLEDpara2 = 0x14; //熄滅時長
- stLEDCtrlInfo.usLEDpara3 = 0x5; //閃爍次數(shù)
- /***/
- /**燈的模式與顏色按需求設(shè)置,以下為參考范例2:藍燈呼吸,最大占空比100,最小占空比0,占空比每秒變化50%)*
- stLEDCtrlInfo.ucLEDCtrlMode = EM_LED_CTRL_PWM;
- stLEDCtrlInfo.ucLEDColor = EM_LED_BLUE;
- stLEDCtrlInfo.usLEDpara1 = 0x64; //最大占空比
- stLEDCtrlInfo.usLEDpara2 = 0x00; //熄滅時長
- stLEDCtrlInfo.usLEDpara3 = 0x32; //閃爍次數(shù)
- ***/
- ret = FP_action_set_led(&stLEDCtrlInfo, &errorCode);
- if(FP_OK == ret && 0 == errorCode)
- {
- //點燈成功
- }
- else
- {
- //延時 50 ms, 繼續(xù)發(fā)送點燈命令,或者直接退出
- Delay_ms(50);
- goto setLedStartLabel;
- }
- }
- /*********************************************************************************************
- 設(shè)置系統(tǒng)策略:用于設(shè)置模組默認的功能;如關(guān)閉重復指紋檢查功能
- */
- void setSysPolicy(void)
- {
- U32Bit errorCode;
- S32Bit ret;
- U32Bit SysPolicy_value;
- U32Bit SysPolicy_bit_selflearn = 0x00000002; //重復指紋檢查功能的位
- U32Bit timeout = 1000; //建議超時時間設(shè)為1s
- /**設(shè)置系統(tǒng)策略之前,先獲取系統(tǒng)策略*/
- getSysPolicyLabel:
- ret = FP_action_get_SysPolicy(&SysPolicy_value, &errorCode);
- if(FP_OK == ret && 0 == errorCode)
- {
- //獲取策略成功
- }
- else
- {
- //延時 50 ms, 繼續(xù)發(fā)送點燈命令,或者直接退出
- 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)
- {
- //獲取策略成功后,模組會自行復位
- Delay_ms(200);
- return;
- }
- else
- {
- //延時 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;
- }
- }
復制代碼
|