From 099a4f80e6e869582b5abc6d12d381bf6c48780f Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Wed, 7 May 2025 17:51:32 +0800 Subject: Match print. --- main.c | 11 +++++++++-- r503.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- r503.h | 8 ++++++-- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 858034f..155cca7 100644 --- a/main.c +++ b/main.c @@ -42,10 +42,9 @@ int main(void) fpm_init(); fpm_get_cfg(&cfg); - fpm_clear_db(); if (fpm_get_count() == 0) { - // todo: check againstr capacity in prod + // todo: check against capacity in prod if (fpm_enroll(1)) { fpm_led_on(BLUE); _delay_ms(500); @@ -61,6 +60,14 @@ int main(void) while (1) { + if (fpm_match()) { + fpm_led_on(BLUE); + _delay_ms(500); + fpm_led_off(); + _delay_ms(500); + } + + _delay_ms(2000); } return 0; diff --git a/r503.c b/r503.c index f78b0ac..4a7b90f 100644 --- a/r503.c +++ b/r503.c @@ -228,13 +228,18 @@ uint8_t fpm_get_cfg(struct fpm_cfg *cfg) return 0; } -uint8_t fpm_clear_db(void) +uint8_t fpm_set_pwd(uint32_t pwd) { uint16_t n; uint8_t buf[MAXPDLEN]; - buf[0] = 0x0D; - send(0x01, buf, 1); + buf[0] = 0x12; + buf[1] = (uint8_t)(pwd >> 24); + buf[2] = (uint8_t)(pwd >> 16); + buf[3] = (uint8_t)(pwd >> 8); + buf[4] = (uint8_t)(pwd & 0xFF); + + send(0x01, buf, 5); recv(buf, &n); return buf[0] == OK; } @@ -291,3 +296,41 @@ uint8_t fpm_enroll(uint16_t id) return buf[0] == OK; } + +uint8_t fpm_match(void) +{ + struct fpm_cfg cfg; + uint16_t n; + uint8_t buf[MAXPDLEN]; + + if (!fpm_get_cfg(&cfg)) + return 0; + + if (!scan()) + return 0; + + if (!img2tz(1)) + return 0; + + buf[0] = 0x04; + buf[1] = 1; + buf[2] = 0x00; + buf[3] = 0x00; + buf[4] = (uint8_t)(cfg.cap >> 8); + buf[5] = (uint8_t)(cfg.cap & 0xFF); + + send(0x01, buf, 6); + recv(buf, &n); + return buf[0] == OK; +} + +uint8_t fpm_clear_db(void) +{ + uint16_t n; + uint8_t buf[MAXPDLEN]; + + buf[0] = 0x0D; + send(0x01, buf, 1); + recv(buf, &n); + return buf[0] == OK; +} diff --git a/r503.h b/r503.h index 9cf4909..936e4f6 100644 --- a/r503.h +++ b/r503.h @@ -23,14 +23,18 @@ uint8_t fpm_init(void); uint8_t fpm_get_cfg(struct fpm_cfg *cfg); +uint8_t fpm_set_pwd(uint32_t pwd); + void fpm_led_on(COLOR color); void fpm_led_off(void); -uint8_t fpm_clear_db(void); - uint16_t fpm_get_count(void); uint8_t fpm_enroll(uint16_t id); +uint8_t fpm_match(void); + +uint8_t fpm_clear_db(void); + #endif /* FPM_R50_H */ -- cgit v1.2.3