diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2025-04-29 17:04:38 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2025-04-29 17:04:38 +0800 |
| commit | a9ce750c420813b1e7dab5eb4e0340d107a34b20 (patch) | |
| tree | b0bab3f5247b3c3cf9cfb2e72dcc4da993c0772a | |
| parent | 775d4a84f36d4d5d0700e9c44dfa4114a0cc022c (diff) | |
| download | smart-home-a9ce750c420813b1e7dab5eb4e0340d107a34b20.tar.gz | |
Delete the old door_lock directory.
| -rw-r--r-- | door_lock/README.txt | 18 | ||||
| -rw-r--r-- | door_lock/Servo.Makefile | 42 | ||||
| -rw-r--r-- | door_lock/cmd.c | 59 | ||||
| -rw-r--r-- | door_lock/cmd.h | 13 | ||||
| -rw-r--r-- | door_lock/serial.c | 33 | ||||
| -rw-r--r-- | door_lock/serial.h | 7 | ||||
| -rw-r--r-- | door_lock/servo.c | 82 |
7 files changed, 0 insertions, 254 deletions
diff --git a/door_lock/README.txt b/door_lock/README.txt deleted file mode 100644 index c565b71..0000000 --- a/door_lock/README.txt +++ /dev/null @@ -1,18 +0,0 @@ -ELECTRICAL CONNECTIONS - -Following connections puts the atmega328p in a configuration that mirrors the -configuration of an Arduino Uno [1]. - - 1. Pin 1 of the IC connects to the 5V via a 10k resistor to prevent the - atmega328p from resetting. - 2. A 16MHz crystal oscillator connects to pins 9 and 10, and each pin of the - crystal oscillator connects to ground via 22pF capacitors. - 3. Pins 7, 20 and 21 (counted clockwise from the bottom left of the IC) - connect to 5V. - 4. Pins 8 and 22 connect to ground. - -Now connect the PWM line of the servo to pin 15 of the IC. - -LINKS - -[1] https://www.youtube.com/watch?v=J3DYgzRvLT8 diff --git a/door_lock/Servo.Makefile b/door_lock/Servo.Makefile deleted file mode 100644 index 018960a..0000000 --- a/door_lock/Servo.Makefile +++ /dev/null @@ -1,42 +0,0 @@ -CC = avr-gcc -MCU = atmega328p -TARGET = app - -SRC = servo.c cmd.c serial.c -OBJ = $(SRC:.c=.o) - -CFLAGS = -std=gnu99 -CFLAGS += -Os -CFLAGS += -Wall -CFLAGS += -mmcu=$(MCU) -CFLAGS += -DBAUD=115200 -CFLAGS += -DF_CPU=16000000UL -CFLAGS += -ffunction-sections -fdata-sections - -LDFLAGS = -mmcu=$(MCU) -LDFLAGS += -Wl,--gc-sections - -HEX_FLAGS = -O ihex -HEX_FLAGS += -j .text -j .data - -AVRDUDE_FLAGS = -p $(MCU) -AVRDUDE_FLAGS += -c arduino -AVRDUDE_FLAGS += -P /dev/cuaU0 -AVRDUDE_FLAGS += -D -U - -%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - -elf: $(OBJ) - $(CC) $(LDFLAGS) $(OBJ) -o $(TARGET).elf - -hex: elf - avr-objcopy $(HEX_FLAGS) $(TARGET).elf $(TARGET).hex - -upload: hex - avrdude $(AVRDUDE_FLAGS) flash:w:$(TARGET).hex:i - -.PHONY: clean - -clean: - rm *.o *.elf *.hex diff --git a/door_lock/cmd.c b/door_lock/cmd.c deleted file mode 100644 index fb9ae9c..0000000 --- a/door_lock/cmd.c +++ /dev/null @@ -1,59 +0,0 @@ -#include <string.h> - -#include "cmd.h" - -#define XORLEN 32 - -#define KEY "dM>}jdb,6gsnC$J^K 8(I5vyPemPs%;K" -#define LOCK_CMD "43iqr5$NB8SpN?Z/52{iVl>o|i!.'dsT" -#define UNLOCK_CMD "R,I7l^E4j]KyLR9'*Q{Jd'zu.~!84}Ij" - -static char cmd[XORLEN]; - -static inline void xor(const char *s, char *d, int n) -{ - int i; - - for (i = 0; i < n && s[i]; i++) - d[i] = s[i] ^ KEY[i]; -} - -int cmd_cmp(const char *s, enum command c) -{ - int rc; - char buf[XORLEN + 1]; - - xor(s, buf, XORLEN); - buf[XORLEN] = 0; - - switch (c) { - case DOOR_LOCK: - rc = strcmp(LOCK_CMD, buf) == 0; - break; - case DOOR_UNLOCK: - rc = strcmp(UNLOCK_CMD, buf) == 0; - break; - default: - rc = 0; - break; - } - - return rc; -} - -char * cmd_hash(enum command c) -{ - switch (c) { - case DOOR_LOCK: - xor(LOCK_CMD, cmd, XORLEN); - break; - case DOOR_UNLOCK: - xor(UNLOCK_CMD, cmd, XORLEN); - break; - default: - cmd[0] = 0; - break; - } - - return cmd; -} diff --git a/door_lock/cmd.h b/door_lock/cmd.h deleted file mode 100644 index ec21ed6..0000000 --- a/door_lock/cmd.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef SA_CMD_H -#define SA_CMD_H - -enum command { - DOOR_LOCK, - DOOR_UNLOCK -}; - -int cmd_cmp(const char *s, enum command c); - -char * cmd_hash(enum command c); - -#endif /* SA_CMD_H */ diff --git a/door_lock/serial.c b/door_lock/serial.c deleted file mode 100644 index 0b9aecf..0000000 --- a/door_lock/serial.c +++ /dev/null @@ -1,33 +0,0 @@ -#include <avr/io.h> -#include <util/setbaud.h> - -#include "serial.h" - -void serial_init(void) -{ - UBRR0H = UBRRH_VALUE; - UBRR0L = UBRRL_VALUE; -#if USE_2X - UCSR0A |= (1 << U2X0); -#else - UCSR0A &= ~(1 << U2X0); -#endif - UCSR0B = (1 << TXEN0) | (1 << RXEN0); - UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); -} - -static void serial_write(unsigned char data) -{ - while (!(UCSR0A & (1 << UDRE0))) - ; - UDR0 = data; -} - -void serial_write_line(const char *s) -{ - for (; *s; s++) - serial_write(*s); - - serial_write('\r'); - serial_write('\n'); -} diff --git a/door_lock/serial.h b/door_lock/serial.h deleted file mode 100644 index 6128623..0000000 --- a/door_lock/serial.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef SA_SERIAL_H -#define SA_SERIAL_H - -void serial_init(void); -void serial_write_line(const char *s); - -#endif /* SA_SERIAL_H */ diff --git a/door_lock/servo.c b/door_lock/servo.c deleted file mode 100644 index 28b669f..0000000 --- a/door_lock/servo.c +++ /dev/null @@ -1,82 +0,0 @@ -#include <avr/io.h> -#include <avr/interrupt.h> -#include <util/delay.h> - -#include "cmd.h" -#include "serial.h" - -#define PWM_MIN 500 -#define PWM_MID 1500 -#define PWM_MAX 2500 -#define PWM_TOP 20000 - -#define SERVO_PIN PB1 -#define LOCK_BTN PD6 -#define UNLOCK_BTN PD7 - -static inline void lock(void) -{ - OCR1A = PWM_MID; - _delay_ms(100); - OCR1A = PWM_TOP; -} - -static inline void unlock(void) -{ - OCR1A = PWM_MAX - 50; - _delay_ms(100); - OCR1A = PWM_TOP; -} - -static inline int is_btn_pressed(unsigned char btn) -{ - if (!((PIND >> btn) & 0x01)) { - _delay_us(2000); - return !((PIND >> btn) & 0x01); - } - - return 0; -} - -static inline void pcint2_init(void) -{ - PCICR |= (1 << PCIE2); - PCMSK2 |= ((1 << PCINT22) | (1 << PCINT23)); -} - -static inline void servo_init(void) -{ - DDRB |= (1 << SERVO_PIN); - - TCCR1A |= (1 << WGM11) | (1 << COM1A1); - TCCR1B |= (1 << WGM13) | (1 << CS11); - - ICR1 = PWM_TOP; - - DDRD &= ~((1 << LOCK_BTN) | (1 << UNLOCK_BTN)); - PORTD |= (1 << LOCK_BTN) | (1 << UNLOCK_BTN); -} - -int main(void) -{ - servo_init(); - pcint2_init(); - serial_init(); - - sei(); - - for(;;) { - // todo: power down - } - - return 0; -} - -ISR(PCINT2_vect) -{ - if (is_btn_pressed(LOCK_BTN)) - lock(); - - if (is_btn_pressed(UNLOCK_BTN)) - unlock(); -} |
