diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2025-04-16 17:21:15 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2025-04-16 17:21:15 +0800 |
| commit | d0f895105f41c40f9a6a000b3437ad55b1ef9bc6 (patch) | |
| tree | b26b9cae7fd82a293e99d33b4d04f95140fd0413 /lock/fend.c | |
| parent | 3049eede70c7209459ce2df811802c5d49d0d0c1 (diff) | |
| download | smart-home-d0f895105f41c40f9a6a000b3437ad55b1ef9bc6.tar.gz | |
Function to flush RX buffers.
Diffstat (limited to 'lock/fend.c')
| -rw-r--r-- | lock/fend.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lock/fend.c b/lock/fend.c index 853fa24..340daeb 100644 --- a/lock/fend.c +++ b/lock/fend.c @@ -21,7 +21,7 @@ #define RX_PCMSK PCMSK2 #define RX_PCINTVEC PCINT2_vect -uint8_t synced = 0; +uint8_t sync = 0; static volatile uint8_t rxd = 0; static volatile uint8_t islock = 0; static volatile uint8_t isunlock = 0; @@ -61,17 +61,17 @@ int main(void) sei(); for (;;) { - if ((islock || isunlock) && !synced) { + if ((islock || isunlock) && !sync) { xor(KEY, SYN, buf, WDLEN); do { - synced = radio_sendto(txaddr, buf, WDLEN); + sync = radio_sendto(txaddr, buf, WDLEN); _delay_ms(10); - } while (!synced); - synced = 1; + } while (!sync); + sync = 1; } if (rxd) { - if (synced) { + if (sync) { n = radio_recv(buf, WDLEN); buf[n] = '\0'; xor(KEY, buf, key, WDLEN); @@ -83,7 +83,9 @@ int main(void) xor(key, UNLOCK, buf, WDLEN); } radio_sendto(txaddr, buf, WDLEN); - synced = 0; + sync = 0; + } else { + radio_flush_rx(); } rxd = 0; } |
