summaryrefslogtreecommitdiffstats
path: root/lock
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2025-05-24 15:56:35 +0800
committerSadeep Madurange <sadeep@asciimx.com>2025-05-24 15:56:35 +0800
commite62586ef42984a2ff644235cab033c6a09fe8662 (patch)
tree694a8eb4851efa409c570d115ea7756883c64f1c /lock
parent31c70ef771e5954dffc5629700e28a89e8ecd493 (diff)
downloadsmart-home-e62586ef42984a2ff644235cab033c6a09fe8662.tar.gz
FPM enroll function.
Diffstat (limited to 'lock')
-rw-r--r--lock/client.c35
-rw-r--r--lock/fpm.c8
-rw-r--r--lock/fpm.h2
3 files changed, 39 insertions, 6 deletions
diff --git a/lock/client.c b/lock/client.c
index 2173987..b67bb47 100644
--- a/lock/client.c
+++ b/lock/client.c
@@ -50,11 +50,28 @@ static inline void init_rx(void)
static inline void init_btns(void)
{
- DDRD &= ~((1 << LOCK_PIN) | (1 << UNLOCK_PIN));
- PORTD |= ((1 << LOCK_PIN) | (1 << UNLOCK_PIN));
+ DDRD &= ~((1 << LOCK_PIN) | (1 << UNLOCK_PIN) | ENROLL_PIN);
+ PORTD |= ((1 << LOCK_PIN) | (1 << UNLOCK_PIN) | ENROLL_PIN);
EICRA = 0b00000000;
EIMSK = (1 << INT0) | (1 << INT1);
+
+ PCICR |= (1 << PCIE2);
+ PCMSK2 |= (1 << PCINT20);
+}
+
+static inline void fpm_ok(void)
+{
+ fpm_led_on(BLUE);
+ _delay_ms(500);
+ fpm_led_off();
+}
+
+static inline void fpm_nok(void)
+{
+ fpm_led_on(RED);
+ _delay_ms(1000);
+ fpm_led_off();
}
int main(void)
@@ -85,8 +102,11 @@ int main(void)
if (isunlock) {
if (!fpm_match()) {
isunlock = 0;
+ fpm_nok();
continue;
}
+ else
+ fpm_ok();
}
xor(KEY, SYN, buf, WDLEN);
@@ -163,8 +183,17 @@ ISR(INT1_vect)
ISR(PCINT2_vect)
{
+ uint16_t id;
+
if (is_btn_pressed(PIND, ENROLL_PIN)) {
- // enroll
+ id = fpm_match();
+ if (id == 1 || id == 2) {
+ fpm_ok();
+ _delay_ms(1000);
+ if (fpm_enroll())
+ fpm_ok();
+ } else
+ fpm_nok();
}
}
diff --git a/lock/fpm.c b/lock/fpm.c
index 57e9ac0..73a175a 100644
--- a/lock/fpm.c
+++ b/lock/fpm.c
@@ -293,7 +293,7 @@ uint8_t fpm_enroll(void)
return buf[0] == OK;
}
-uint8_t fpm_match(void)
+uint16_t fpm_match(void)
{
struct fpm_cfg cfg;
uint8_t buf[MAXPDLEN];
@@ -316,5 +316,9 @@ uint8_t fpm_match(void)
send(buf, 6);
recv(buf);
- return buf[0] == OK;
+
+ if (buf[0] != OK)
+ return 0;
+
+ return ((uint16_t)buf[1] << 8) | buf[2];
}
diff --git a/lock/fpm.h b/lock/fpm.h
index 1deca46..31f53eb 100644
--- a/lock/fpm.h
+++ b/lock/fpm.h
@@ -33,6 +33,6 @@ uint16_t fpm_get_count(void);
uint8_t fpm_enroll(void);
-uint8_t fpm_match(void);
+uint16_t fpm_match(void);
#endif /* FPM_R50_H */