From d5e72b4ce575bcec2699edad4c9420cbc05855a3 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 23 Nov 2011 20:28:35 +0000 Subject: [PATCH] ajar-state: boolean vs. byte --- firmware/tuer.pde | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/firmware/tuer.pde b/firmware/tuer.pde index 20639fe..3813e00 100644 --- a/firmware/tuer.pde +++ b/firmware/tuer.pde @@ -21,7 +21,9 @@ 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; +#define SHUT 0 +#define AJAR 1 +byte ajar_last_state = SHUT; #define MANUAL_OPEN_PIN 12 // keys for manual open and close #define MANUAL_CLOSE_PIN 13 // @@ -80,9 +82,12 @@ boolean is_closed() //**********// -boolean get_ajar_status() // shut = true, ajar = false +byte get_ajar_status() { - return (digitalRead(AJAR_PIN) == LOW); + if(digitalRead(AJAR_PIN) == LOW) + return SHUT; + + return AJAR; } void init_ajar() @@ -387,7 +392,7 @@ ISR(TIMER1_COMPA_vect) else if(is_closed()) Serial.print("closed"); Serial.print(", idle"); - if(get_ajar_status()) + if(get_ajar_status() == SHUT) Serial.println(", shut"); else Serial.println(", ajar"); @@ -520,7 +525,7 @@ void print_status() case WAIT: Serial.print(", waiting"); break; default: Serial.print(", "); break; } - if(get_ajar_status()) + if(get_ajar_status() == SHUT) Serial.println(", shut"); else Serial.println(", ajar"); @@ -620,8 +625,8 @@ void loop() PORTD = LEDS_ON; } } - boolean a = get_ajar_status(); - if (a != ajar_last_state) + byte a = get_ajar_status(); + if(a != ajar_last_state) { print_status(); ajar_last_state = a; -- 1.7.10.4