1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 18:34:25 +01:00

Improved klackering mechanism

This commit is contained in:
Ralf Ramsauer 2015-05-20 22:42:20 +02:00
parent 2e41661dbf
commit b498e58ea7
2 changed files with 48 additions and 40 deletions

View File

@ -26,9 +26,8 @@
#define IS_RESCUE (!(PIND & (1<<PD3))) #define IS_RESCUE (!(PIND & (1<<PD3)))
#define IS_SWITCH (!(PIND & (1<<PD2))) #define IS_SWITCH (!(PIND & (1<<PD2)))
#define IS_SCK (!(PINB & (1<<PB7))) static uint8_t open = 0;
static uint8_t klacker = 0;
uint8_t open = 0;
void open_door() void open_door()
{ {
@ -36,7 +35,15 @@ void open_door()
GREEN_ON; GREEN_ON;
OPEN_BOLZEN; OPEN_BOLZEN;
DOORLIGHT_ON; DOORLIGHT_ON;
_delay_ms(200); }
void close_door()
{
RED_ON;
GREEN_OFF;
DOORLIGHT_OFF;
CLOSE_SCHNAPPER;
CLOSE_BOLZEN;
} }
void schnapper(unsigned int i) void schnapper(unsigned int i)
@ -50,23 +57,20 @@ void schnapper(unsigned int i)
} }
} }
void close_door()
{
RED_ON;
GREEN_OFF;
DOORLIGHT_OFF;
CLOSE_SCHNAPPER;
CLOSE_BOLZEN;
}
uint8_t klacker = 0;
ISR(USI_OVERFLOW_vect) ISR(USI_OVERFLOW_vect)
{ {
USISR = (1<<USIOIF); // Clear interrupt flag
open = 1; USISR |= (1<<USIOIF);
// Reset counter
TCNT1 = 0; TCNT1 = 0;
klacker = USIDR ? 0 : 1; open = 1;
uint8_t in = USIDR;
// Depending on the clock, a klacker either can be 10101010 or 01010101
if (in == 0x55 || in == 0xAA)
{
klacker = 1;
}
} }
ISR(TIMER1_OVF_vect) ISR(TIMER1_OVF_vect)
@ -78,34 +82,33 @@ int main(void) {
// disable all interrupts // disable all interrupts
cli(); cli();
// PD5, PD4, PD6 Output // PD4-6 as Output
DDRD = (1<<PD5)|(1<<PD4)|(1<<PD6); DDRD = (1<<PD5)|(1<<PD4)|(1<<PD6);
// PD2,3 Pullup
PORTD |= (1<<PD2)|(1<<PD3);
// PB0-1 as Output
DDRB = (1<<PB0)|(1<<PB1); DDRB = (1<<PB0)|(1<<PB1);
// PB5,7 Pullup
PORTB |= (1<<PB7)|(1<<PB5); PORTB |= (1<<PB7)|(1<<PB5);
// PD2,3 as input + pull up // first action: close door
DDRD &= ~((1<<PD2)|(1<<PD3)); close_door();
PORTD |= (1<<PD3)|(1<<PD3);
// Configure USI
USICR = (1<<USICS1) | (1<<USIOIE) | (1<<USIWM0); USICR = (1<<USICS1) | (1<<USIOIE) | (1<<USIWM0);
// Configure Timer
TIMSK |= (1<<TOIE1); TIMSK |= (1<<TOIE1);
TIFR |= (1<<TOV1); TIFR |= (1<<TOV1);
TCNT1 = 0; TCNT1 = 0;
TCCR1A = 0; TCCR1A = 0;
TCCR1B = (1<<CS01)|(1<<CS00); TCCR1B = (1<<CS01)|(1<<CS00);
// wait a bit to settle down
_delay_ms(1000); _delay_ms(1000);
CLOSE_BOLZEN; // enable interrupts
CLOSE_SCHNAPPER;
GREEN_OFF;
RED_ON;
DOORLIGHT_OFF;
_delay_ms(1000);
sei(); sei();
for(;;) { for(;;) {
@ -113,13 +116,12 @@ int main(void) {
close_door(); close_door();
} else if (open == 1) { } else if (open == 1) {
open_door(); open_door();
} if (klacker == 1)
if (open == 1 && klacker == 1)
{ {
schnapper(20); schnapper(20);
klacker = 0; klacker = 0;
} }
}
if (IS_RESCUE) { if (IS_RESCUE) {
cli(); cli();

View File

@ -53,18 +53,24 @@ void Door::unlock()
_open = true; _open = true;
_heartbeat = std::thread([this] () { _heartbeat = std::thread([this] () {
digitalWrite(_SCHNAPPER, HIGH);
auto beat = [] () { auto beat = [] () {
digitalWrite(_LOCKPIN, HIGH); digitalWrite(_LOCKPIN, HIGH);
usleep(10000); usleep(10000);
digitalWrite(_LOCKPIN, LOW); digitalWrite(_LOCKPIN, LOW);
usleep(10000); usleep(10000);
}; };
digitalWrite(_SCHNAPPER, HIGH);
while (_open) { while (_open) {
if (_schnapper == true) if (_schnapper == true)
{
for (int i = 0; i < 32 ; i++)
{ {
digitalWrite(_SCHNAPPER, LOW); digitalWrite(_SCHNAPPER, LOW);
for (int i = 0; i < 32 ; i++) beat(); beat();
digitalWrite(_SCHNAPPER, HIGH);
beat();
}
digitalWrite(_SCHNAPPER, HIGH); digitalWrite(_SCHNAPPER, HIGH);
_schnapper = false; _schnapper = false;
} }