X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=firmware%2Ftuer.pde;h=5cde5471ba8b355c7705239269411ded6bee4f66;hb=0ee06169ba0b63def2038e16b605d1e2dce6250a;hp=c4bfcb4ddf32924300bc43f9e7b116b7bda86daa;hpb=4bb3eba50f61cc7f57d0ad279ab310ea5368a88d;p=svn42.git diff --git a/firmware/tuer.pde b/firmware/tuer.pde index c4bfcb4..5cde547 100644 --- a/firmware/tuer.pde +++ b/firmware/tuer.pde @@ -21,6 +21,8 @@ byte next_led = 0; #define LIMIT_CLOSED_PIN 19 // A5: limit switch for close #define AJAR_PIN 14 // input pin for reed relais (door ajar/shut) +boolean ajar_last_state = false; +boolean ajar_state_changed = false; #define MANUAL_OPEN_PIN 12 // keys for manual open and close #define MANUAL_CLOSE_PIN 13 // @@ -83,6 +85,7 @@ void init_ajar() { pinMode(AJAR_PIN, INPUT); // set pin to input digitalWrite(AJAR_PIN, HIGH); // turn on pullup resistors + ajar_last_state = digitalRead(AJAR_PIN); } boolean get_ajar_status() // shut = true, ajar = false @@ -458,6 +461,10 @@ void init_heartbeat() // while running this gets called every ~10ms ISR(TIMER2_COMPA_vect) { + boolean a = get_ajar_status(); + if(a != ajar_last_state) + ajar_state_changed = true; + ajar_last_state = a; heartbeat_cnt++; if(heartbeat_cnt == HEARTBEAT_DURATION) heartbeat_off(); @@ -549,6 +556,7 @@ void setup() current_state = CLOSING; start_step_timer(); } + Serial.println("init complete"); } void loop() @@ -564,8 +572,8 @@ void loop() } else if (command == CMD_OPEN) { if(current_state == IDLE) { - if(is_opened()) - Serial.println("Already open"); + if(is_opened()) + Serial.println("Already open"); else { start_open(); Serial.println("Ok"); @@ -576,8 +584,8 @@ void loop() } else if (command == CMD_CLOSE) { if(current_state == IDLE) { - if(is_closed()) - Serial.println("Already closed"); + if(is_closed()) + Serial.println("Already closed"); else { start_close(); Serial.println("Ok"); @@ -588,11 +596,11 @@ void loop() } else if (command == CMD_TOGGLE) { if(current_state == IDLE) { - if(is_closed()) - start_open(); - else - start_close(); - Serial.println("Ok"); + if(is_closed()) + start_open(); + else + start_close(); + Serial.println("Ok"); } else Serial.println("Error: Operation in progress"); @@ -610,7 +618,7 @@ void loop() Serial.println("close forced manually"); start_close(); } - if (current_state == IDLE) { + if(current_state == IDLE) { if(is_opened()) { leds_green(); PORTD = LEDS_ON; @@ -620,4 +628,8 @@ void loop() PORTD = LEDS_ON; } } + if(ajar_state_changed) { + ajar_state_changed = false; + print_status(); + } }