From 6217519d22c4398706bd316f74103909c1d268ec Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Wed, 7 May 2025 14:55:01 +0800 Subject: Get template count. --- fpm.c | 2 +- main.c | 10 ++++++++-- r503.c | 18 ++++++++++++++++++ r503.h | 2 ++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/fpm.c b/fpm.c index 657a1a8..a58045e 100644 --- a/fpm.c +++ b/fpm.c @@ -195,7 +195,7 @@ uint8_t fpm_setpwd(uint32_t pwd) return buf[0] == OK; } -uint16_t fpm_getcount(void) +uint16_t fpm_get_count(void) { uint16_t n, count; uint8_t buf[MAXPDLEN]; diff --git a/main.c b/main.c index 5b616b3..ba5f6e6 100644 --- a/main.c +++ b/main.c @@ -39,8 +39,14 @@ int main(void) sei(); fpm_init(); - if (fpm_clear_db()) - fpm_led_on(PURPLE); + if (fpm_get_count() == 0) { + for (;;) { + fpm_led_on(PURPLE); + _delay_ms(500); + fpm_led_off(); + _delay_ms(500); + } + } while (1) { diff --git a/r503.c b/r503.c index e970c59..434e3fe 100644 --- a/r503.c +++ b/r503.c @@ -182,3 +182,21 @@ uint8_t fpm_clear_db(void) recv(buf, &n); return buf[0] == OK; } + +uint16_t fpm_get_count(void) +{ + uint16_t n, count; + uint8_t buf[MAXPDLEN]; + + buf[0] = 0x1D; + send(0x01, buf, 1); + recv(buf, &n); + + count = 0; + if (buf[0] == OK && n >= 2) { + count = buf[1]; + count <<= 8; + count |= buf[2]; + } + return count; +} diff --git a/r503.h b/r503.h index f941cb9..e12b8f2 100644 --- a/r503.h +++ b/r503.h @@ -17,4 +17,6 @@ void fpm_led_off(void); uint8_t fpm_clear_db(void); +uint16_t fpm_get_count(void); + #endif /* FPM_R50_H */ -- cgit v1.2.3