BMLite_Nordic/BMLite_example/src/main.c
Andrey Perminov ce69dec56f Moved LEDs control completely to HAL
Change-Id: Ie420cd40d969d1776804dd837caf970c1b4e4c0b
2020-04-23 09:37:44 -07:00

120 lines
3.1 KiB
C

/*
* Copyright (c) 2020 Fingerprint Cards AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Modified by Andrey Perminov for running on microcontrollers
*/
/**
* @file main.c
* @brief Main file for FPC BM-Lite Communication example.
*/
#include <unistd.h>
#include <string.h>
#include "bep_host_if.h"
#include "com_common.h"
#include "platform.h"
#include "bmlite_hal.h"
void bmlite_on_error(bmlite_error_t error, int32_t value)
{
if(value != FPC_BEP_RESULT_TIMEOUT) {
hal_set_leds(BMLITE_LED_STATUS_ERROR, false);
} else {
// Timeout - not really an error here
hal_set_leds(BMLITE_LED_STATUS_ERROR, true);
}
}
// void bmlite_on_start_capture();
// void bmlite_on_finish_capture();
void bmlite_on_start_enroll()
{
hal_set_leds(BMLITE_LED_STATUS_ENROLL, true);
}
void bmlite_on_finish_enroll()
{
hal_set_leds(BMLITE_LED_STATUS_ENROLL, false);
}
void bmlite_on_start_enrollcapture()
{
hal_set_leds(BMLITE_LED_STATUS_WAITTOUCH, true);
}
void bmlite_on_finish_enrollcapture()
{
hal_set_leds(BMLITE_LED_STATUS_READY, false);
}
void bmlite_on_identify_start()
{
hal_set_leds(BMLITE_LED_STATUS_READY, true);
}
// void bmlite_on_identify_finish();
int main (int argc, char **argv)
{
int baudrate = 4000000;
uint8_t buffer[512];
uint16_t size[2] = { 256, 256 };
fpc_com_chain_t hcp_chain;
platform_init(baudrate);
init_com_chain(&hcp_chain, buffer, size, NULL);
hcp_chain.channel = 1;
{
char version[100];
uint16_t template_id;
uint32_t current_id = 0;
bool match;
// These two lines for debug purpose only
memset(version, 0, 100);
fpc_bep_result_t res = bep_version(&hcp_chain, version, 99);
while (1)
{
uint32_t btn_time = platform_get_button_press_time();
hal_set_leds(BMLITE_LED_STATUS_READY,0);
if (btn_time < 200) {
// nothing hapened
} else if (btn_time < 5000) {
// Enroll
res = bep_enroll_finger(&hcp_chain);
res = bep_save_template(&hcp_chain, current_id++);
} else {
// Erase All templates
hal_set_leds(BMLITE_LED_STATUS_DELETE_TEMPLATES, true);
res = bep_delete_template(&hcp_chain, REMOVE_ID_ALL_TEMPLATES);
}
res = bep_identify_finger(&hcp_chain, &template_id, &match);
if (res != FPC_BEP_RESULT_OK)
continue;
hal_set_leds(BMLITE_LED_STATUS_MATCH, match);
}
}
}