summaryrefslogtreecommitdiffstats
path: root/lock/bend.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2025-04-15 20:53:49 +0800
committerSadeep Madurange <sadeep@asciimx.com>2025-04-15 20:53:49 +0800
commit969f168756db0623ce269d7897d0c532a00c79b7 (patch)
treebd3ef58fbd9ad33f221769067e5e67395374799c /lock/bend.c
parent065594d8b1344ed8110f7e7e1ff4b7281e8eb291 (diff)
downloadsmart-home-969f168756db0623ce269d7897d0c532a00c79b7.tar.gz
Handle btn press in the main().
Diffstat (limited to 'lock/bend.c')
-rw-r--r--lock/bend.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/lock/bend.c b/lock/bend.c
index a830c5e..44d8713 100644
--- a/lock/bend.c
+++ b/lock/bend.c
@@ -45,6 +45,7 @@ static char tab[] = {
static uint8_t syn = 0;
static volatile uint8_t rxdr = 0;
+static volatile uint8_t btn_press = 0;
static uint16_t tablen = sizeof(tab) / sizeof(tab[0]);
static inline void keygen(char *buf, uint8_t n)
@@ -129,7 +130,6 @@ int main(void)
_delay_ms(500);
if (rxdr) {
- rxdr = 0;
n = radio_recv(buf, WDLEN);
buf[n] = '\0';
if (!syn) {
@@ -149,6 +149,15 @@ int main(void)
unlock();
keydel(buf, WDLEN);
}
+ rxdr = 0;
+ }
+
+ if (btn_press) {
+ if (is_btn_pressed(BTN_PIN, LOCK_BTN))
+ lock();
+ else if (is_btn_pressed(BTN_PIN, UNLOCK_BTN))
+ unlock();
+ btn_press = 0;
}
// todo: sleep
@@ -163,8 +172,5 @@ ISR(RX_PCINTVEC)
ISR(BTN_PCINTVEC)
{
- if (is_btn_pressed(BTN_PIN, LOCK_BTN))
- lock();
- else if (is_btn_pressed(BTN_PIN, UNLOCK_BTN))
- unlock();
+ btn_press = 1;
}