diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2025-04-24 09:36:51 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2025-04-24 09:36:51 +0800 |
| commit | 4bd8f90cb08f15403125fdeef175a3800b9dabd5 (patch) | |
| tree | 00d81680fc133998c916a2b1431c3ec90099e0af /lock/bend.c | |
| parent | 46454fc1b4194d34a40b87be4c0bb526c06fd15a (diff) | |
| download | smart-home-4bd8f90cb08f15403125fdeef175a3800b9dabd5.tar.gz | |
Fix recv index bug.
Diffstat (limited to 'lock/bend.c')
| -rw-r--r-- | lock/bend.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/lock/bend.c b/lock/bend.c index 759ba9e..d4e936d 100644 --- a/lock/bend.c +++ b/lock/bend.c @@ -1,6 +1,7 @@ /* Lock back, connected to the servo */ #include <stdint.h> +#include <stdlib.h> #include <string.h> #include <avr/interrupt.h> @@ -86,27 +87,14 @@ static inline void init_btns(void) static inline void init_servo(void) { - DDRB |= (1 << SERVO_PIN); - - TCCR1A |= (1 << WGM11) | (1 << COM1A1); - TCCR1B |= (1 << WGM13) | (1 << CS11); - ICR1 = PWM_TOP; } static inline void lock(void) { - OCR1A = PWM_MID; - _delay_ms(100); - OCR1A = PWM_TOP; - uart_write_line("locked"); } static inline void unlock(void) { - OCR1A = PWM_MAX - 50; - _delay_ms(100); - OCR1A = PWM_TOP; - uart_write_line("unlocked"); } int main(void) @@ -115,6 +103,7 @@ int main(void) uint8_t rxaddr[ADDRLEN] = { 194, 178, 83 }; uint8_t txaddr[ADDRLEN] = { 194, 178, 82 }; + char s[3]; s[2] = 0; char buf[WDLEN + 1], key[WDLEN + 1], msg[WDLEN + 1]; init_rx(); @@ -137,12 +126,19 @@ int main(void) if (rxd) { n = radio_recv(buf, WDLEN); buf[n] = '\0'; + uart_write("recv: "); + uart_write(buf); + itoa(n, s, 10); + uart_write(s); + uart_write_line(" bytes"); if (!sync) { xor(KEY, buf, msg, WDLEN); if (strncmp(msg, SYN, WDLEN) == 0) { keygen(key, WDLEN + 1); xor(KEY, key, buf, WDLEN); sync = radio_sendto(txaddr, buf, WDLEN); + } else { + uart_write_line("not syn"); } } else { sync = 0; |
