summaryrefslogtreecommitdiffstats
path: root/rf_test/recv.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2024-11-24 15:16:10 +0800
committerSadeep Madurange <sadeep@asciimx.com>2024-11-24 15:16:10 +0800
commit343a139e10436d074a8d94a63b26ee0fe74280be (patch)
tree2e5e6bd7a0b560e163419a7b1d06b0a69ecc16c7 /rf_test/recv.c
parent965ba924daf988946a39a49926d0e8d61c2ae805 (diff)
downloadsmart-home-343a139e10436d074a8d94a63b26ee0fe74280be.tar.gz
Updated send and recv files to use rfm.
Diffstat (limited to 'rf_test/recv.c')
-rw-r--r--rf_test/recv.c43
1 files changed, 19 insertions, 24 deletions
diff --git a/rf_test/recv.c b/rf_test/recv.c
index 9cb3daa..010a432 100644
--- a/rf_test/recv.c
+++ b/rf_test/recv.c
@@ -2,6 +2,9 @@
#include <avr/interrupt.h>
#include <util/delay.h>
+#include "rfm.h"
+#include "serial.h"
+
#define TEST_LED PB1
#define LOCK_LED PD6
#define UNLOCK_LED PD7
@@ -11,9 +14,6 @@
#define UNLOCK 0xAE
#define SIGPIN PB3
-#define SIGLEN 200
-
-static volatile unsigned char data = 0;
static inline void led_init(void)
{
@@ -33,35 +33,30 @@ int main(void)
PORTB &= ~(1 << SIGPIN);
led_init();
+ serial_init();
pcint2_init();
sei();
- for (;;) {
- if (data == LOCK) {
- PORTD |= (1 << LOCK_LED);
- PORTD &= ~(1 << UNLOCK_LED);
- }
-
- if (data == UNLOCK) {
- PORTD &= ~(1 << LOCK_LED);
- PORTD |= (1 << UNLOCK_LED);
- }
-
- data = 0;
- _delay_ms(100);
- }
+ for (;;)
+ ;
return 0;
}
ISR(PCINT2_vect)
{
- int n, bit;
-
- for (n = 7; n >= 0; n--) {
- _delay_ms(SIGLEN);
- bit = ((PINB >> SIGPIN) & 1);
- data = bit == 1 ? (data | (1 << n)) : (data & ~(1 << n));
- }
+ char *s;
+ uint8_t buf[2], n;
+
+ n = rfm_recvfrom(0x00, buf, 2);
+
+ if (buf[1] == LOCK)
+ s = "LOCK";
+ else if (buf[1] == UNLOCK)
+ s = "UNLOCK";
+ else
+ s = "Garbage";
+
+ serial_write_line(s);
}