From 7082fe8c97faaf6cc4789fb9f66fd4a1c716979e Mon Sep 17 00:00:00 2001 From: Vidister Date: Tue, 4 Jul 2017 23:22:50 +0200 Subject: (hopefully) fix false positives --- main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 38ff79f..58f633d 100644 --- a/main.c +++ b/main.c @@ -7,11 +7,11 @@ #define HZ 15625ULL #define TIMEOUT_SEC 4 -#define MIN_PULSE_WIDTH_MS 10 -#define RING_DURATION_SEC 20 -#define OPEN_DURATION_SEC 3 -#define THURSDAY_TIMEOUT_MIN 300UL -#define THURSDAY_OPEN_DELAY 750UL +#define MIN_PULSE_WIDTH_MS 25 +#define RING_DURATION_SEC 20 // Time the lamp lights up +#define OPEN_DURATION_SEC 4 // Door open duration +#define THURSDAY_TIMEOUT_MIN 420UL // Minutes till Thursday is disabled +#define THURSDAY_OPEN_DELAY 750UL // Time till the door is opened when the doorbell is pressed #define PRESSED_MIN_MS 50UL #define RELEASED_MIN_MS 50UL -- cgit From fa146e1fe1a5107070520a0af40dcdca4cdbc9bd Mon Sep 17 00:00:00 2001 From: Vidister Date: Tue, 4 Jul 2017 23:35:34 +0200 Subject: add documentation --- main.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/main.c b/main.c index 58f633d..c5e4f3f 100644 --- a/main.c +++ b/main.c @@ -5,16 +5,16 @@ #include #include -#define HZ 15625ULL -#define TIMEOUT_SEC 4 -#define MIN_PULSE_WIDTH_MS 25 -#define RING_DURATION_SEC 20 // Time the lamp lights up -#define OPEN_DURATION_SEC 4 // Door open duration +#define HZ 15625ULL // Frequency +#define TIMEOUT_SEC 4 // time after clicking once till the lamp/bell goes on +#define MIN_PULSE_WIDTH_MS 25 // Time the button needs to be pressed till in ms +#define RING_DURATION_SEC 20 // Time the lamp lights up in sec +#define OPEN_DURATION_SEC 4 // Door open duration in sec #define THURSDAY_TIMEOUT_MIN 420UL // Minutes till Thursday is disabled #define THURSDAY_OPEN_DELAY 750UL // Time till the door is opened when the doorbell is pressed -#define PRESSED_MIN_MS 50UL -#define RELEASED_MIN_MS 50UL +#define PRESSED_MIN_MS 50UL // Time slots between Code Input +#define RELEASED_MIN_MS 50UL // Time slots between Code Input static uint8_t global_thursday_mode = 0; static uint16_t global_thursday_timectr_sec = 0; @@ -56,7 +56,7 @@ void open(void) { PORTC &= ~0x02; /* Opener relay */ } -uint8_t handle_open_button(void) { +uint8_t handle_open_button(void) { // Open when the Open-Button is pressed if (PINC&0x20) return 0; tx_str(PSTR("OPEN Manual open\r\n")); @@ -64,7 +64,7 @@ uint8_t handle_open_button(void) { return 1; } -void ring(void) { +void ring(void) { // RING RING RING RING!!! tx_str(PSTR("RING Ringing\r\n")); PORTB |= 0x20; PORTC |= 0x04; @@ -74,18 +74,18 @@ void ring(void) { PORTC &= ~0x04; } -void code(void) { +void code(void) { // Open the door when the button was pressed x times tx_str(PSTR("CODE Code access granted\r\n")); open(); } -void set_thursday_mode(uint8_t mode) { +void set_thursday_mode(uint8_t mode) { // Toggle the thursday mode (/Enable till it is disabled or timeout is reached) global_thursday_mode = mode; global_thursday_timectr_sec = 0; tx_str(mode ? PSTR("THU1 Thursday mode set to on\r\n") : PSTR("THU0 Thursday mode set to off\r\n")); - if (mode) + if (mode) // toggle PORTC |= 0x10; else PORTC &= ~0x10; @@ -123,6 +123,8 @@ int main(void) { * A4/PC4 OUT thursday mode signal */ /* use 115200Bd */ + + // Initialize UBRR0H = 0; UBRR0L = 16; UCSR0A = (1< TIMEOUT_SEC*HZ) { /* Doorbell button timeout */ - if (pidx != 0 || codefail) + if (TCNT1 > TIMEOUT_SEC*HZ) { /* Thursday Button Timeout (Disables Thursday after X hours */ + if (pidx != 0 || codefail) ring(); pidx = 0; codefail = 0; @@ -165,17 +168,17 @@ int main(void) { TCNT1 = 0; global_thursday_timectr_sec += TIMEOUT_SEC; - if (global_thursday_timectr_sec >= THURSDAY_TIMEOUT_MIN*60UL) { + if (global_thursday_timectr_sec >= THURSDAY_TIMEOUT_MIN*60UL) { // Check if timeout is reached tx_str(PSTR("TOUT Thursday mode timeout\r\n")); set_thursday_mode(0); } - } else { + } else { // When no control button on the front of the door-system is pressed uint8_t st = PINC&1; - if (global_thursday_mode && !st) { + if (global_thursday_mode && !st) { // Open if thursday tx_str(PSTR("THUA Thursday mode auto open\r\n")); _delay_ms(THURSDAY_OPEN_DELAY); open(); - } else if (st == (pidx&1)) { + } else if (st == (pidx&1)) { // Doorcode uint16_t val = TCNT1; if (val > HZ*MIN_PULSE_WIDTH_MS/1000ULL) { pattern[pidx++] = val; -- cgit From 2c1466425c39faedce5aed0ffe0e9ba7b4e6875c Mon Sep 17 00:00:00 2001 From: David Date: Tue, 4 Jul 2017 23:38:00 +0200 Subject: Create Readme --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..98fa706 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# CCCB Doorbell System + +Shitty pile of code for the Arduino in the Bread Box for controlling the door opener. + +## Thursday Mode +When the mode is enabled, the door will be opened after the first click on the Door Bell +It will be disabled with a timeout, so you can't forget to turn it off. + +## Code Opener +When the Door Bell ist pressed 3 Times in a Row, the door will open. -- cgit From f5f7a5ce9b81324f7fb18d178de3897b2ca0632b Mon Sep 17 00:00:00 2001 From: Vidister Date: Tue, 18 Jul 2017 23:32:30 +0200 Subject: Second approach --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index c5e4f3f..34a2107 100644 --- a/main.c +++ b/main.c @@ -7,7 +7,7 @@ #define HZ 15625ULL // Frequency #define TIMEOUT_SEC 4 // time after clicking once till the lamp/bell goes on -#define MIN_PULSE_WIDTH_MS 25 // Time the button needs to be pressed till in ms +#define MIN_PULSE_WIDTH_MS 50 // Time the button needs to be pressed till in ms #define RING_DURATION_SEC 20 // Time the lamp lights up in sec #define OPEN_DURATION_SEC 4 // Door open duration in sec #define THURSDAY_TIMEOUT_MIN 420UL // Minutes till Thursday is disabled -- cgit