diff options
| -rw-r--r-- | fpm.c | 57 | ||||
| -rw-r--r-- | fpm.h | 8 | ||||
| -rw-r--r-- | main.c | 32 |
3 files changed, 91 insertions, 6 deletions
@@ -129,6 +129,24 @@ static inline uint8_t check_pwd(void) return buf[0] == OK; } +static inline void scan(uint8_t bufid) +{ + uint16_t n; + uint8_t buf[MAXPDLEN]; + + do { + buf[0] = 0x01; + send(0x01, buf, 1); + recv(buf, &n); + if (buf[0] == OK) { + buf[0] = 0x02; + buf[1] = bufid; + send(0x01, buf, 2); + recv(buf, &n); + } + } while (buf[0] != OK); +} + uint8_t fpm_init(void) { UBRR0H = UBRRH_VALUE; @@ -145,7 +163,7 @@ uint8_t fpm_init(void) return check_pwd(); } -uint8_t fpm_getcfg(struct fpm_config *cfg) +uint8_t fpm_getcfg(struct fpm_cfg *cfg) { uint16_t n; uint8_t buf[MAXPDLEN]; @@ -205,3 +223,40 @@ uint16_t fpm_getcount(void) } return count; } + +uint8_t fpm_enroll(void) +{ + uint16_t n, retries; + uint8_t buf[MAXPDLEN]; + + retries = 0; + do { + _delay_ms(100); + buf[0] = 0x10; + send(0x01, buf, 1); + recv(buf, &n); + retries++; + } while (buf[0] != OK && retries < 50); + + return buf[0] == OK; +} + +uint8_t fpm_match(void) +{ + uint16_t n, count; + uint8_t buf[MAXPDLEN]; + + scan(1); + count = fpm_getcount(); + + buf[0] = 0x04; + buf[1] = 1; + buf[2] = 0x00; + buf[3] = 0x00; + buf[4] = (uint8_t)(count >> 8); + buf[5] = (uint8_t)(count & 0xFF); + + send(0x01, buf, 6); + recv(buf, &n); + return buf[0] == OK; +} @@ -3,7 +3,7 @@ #include <stdint.h> -struct fpm_config { +struct fpm_cfg { uint16_t status; uint16_t sysid; uint16_t cap; @@ -15,10 +15,14 @@ struct fpm_config { uint8_t fpm_init(void); -uint8_t fpm_getcfg(struct fpm_config *cfg); +uint8_t fpm_getcfg(struct fpm_cfg *cfg); uint8_t fpm_setpwd(uint32_t pwd); uint16_t fpm_getcount(void); +uint8_t fpm_enroll(void); + +uint8_t fpm_match(void); + #endif /* FPM_H */ @@ -36,7 +36,7 @@ static inline void print_config(void) const int SLEN = 25; char s[SLEN]; - struct fpm_config cfg; + struct fpm_cfg cfg; if (fpm_getcfg(&cfg)) { uart_write("FPM config:"); @@ -85,7 +85,8 @@ static inline void print_config(void) int main(void) { - char s[20]; + char s[30]; + uint8_t ismatch; uint16_t template_count; cli(); @@ -96,8 +97,33 @@ int main(void) if (fpm_init()) { print_config(); template_count = fpm_getcount(); - snprintf(s, 20, "Template count: %d", template_count); + snprintf(s, 30, "Template count: %d", template_count); uart_write(s); + + uart_write("Enroll fingerprint"); + _delay_ms(2000); + if (fpm_enroll()) { + uart_write("Enrolled fingerprint"); + } else { + uart_write("Enrollment error"); + } + + template_count = fpm_getcount(); + snprintf(s, 30, "New template count: %d", template_count); + uart_write(s); + + //uart_write("Authentcate"); + //_delay_ms(1000); + // + //do { + // ismatch = fpm_match(); + // if (ismatch) + // uart_write("Matched!"); + // else { + // uart_write("No match!"); + // _delay_ms(1500); + // } + //} while (!ismatch); } while (1) |
