From 5465893d6d77bfb69fb7846b12401c949f317b30 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Wed, 23 Nov 2011 21:30:22 +0000 Subject: [PATCH] software ajar sensor low pass --- firmware/tuer.pde | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/firmware/tuer.pde b/firmware/tuer.pde index 3813e00..5466ba7 100644 --- a/firmware/tuer.pde +++ b/firmware/tuer.pde @@ -82,12 +82,21 @@ boolean is_closed() //**********// +#define AJAR_LOW_PASS_TAU 200 +byte ajar_low_pass_counter = 0; +byte ajar_low_pass_last_value = ajar_last_state; byte get_ajar_status() { - if(digitalRead(AJAR_PIN) == LOW) - return SHUT; - - return AJAR; + b = ( (digitalRead(AJAR_PIN) == LOW)? SHUT : AJAR ); + ajar_low_pass_counter = ( (b == ajar_low_pass_last_value)? ajar_low_pass_counter + 1 : 0 ); + ajar_low_pass_last_value = b; + if (ajar_low_pass_counter >= AJAR_LOW_PASS_TAU) + { + ajar_low_pass_counter = 0; + return b; + } + else + return ajar_last_state; } void init_ajar() -- 1.7.10.4