From 7e11f4bdd0db25840484419b483308258d1ab566 Mon Sep 17 00:00:00 2001 From: Jérémy Dufour Date: Fri, 28 Mar 2008 02:03:09 +0100 Subject: * digital/io/src - correct the use of hysteresis with filter; - correct use of an identifier for sharps (thanks to ni). --- digital/io/src/sharp.c | 24 ++++++++++++------------ digital/io/src/sharp.h | 8 ++++---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/digital/io/src/sharp.c b/digital/io/src/sharp.c index 9f99087a..f5524067 100644 --- a/digital/io/src/sharp.c +++ b/digital/io/src/sharp.c @@ -40,14 +40,14 @@ uint16_t sharp_values_[SHARP_NUMBER]; uint16_t sharp_threshold[SHARP_NUMBER][2]; /** - * Hysteresis. + * Filter counter for each sharp. */ -uint8_t sharp_hysteresis_[SHARP_NUMBER]; +uint8_t sharp_filter_[SHARP_NUMBER]; /** - * Hysteresis threshold. + * Filter number value before changing state. */ -#define SHARP_HYSTERESIS_THRESHOLD 3 +#define SHARP_FILTER_NUMBER 3 /** * Previous sharp interpreted values. @@ -133,24 +133,24 @@ sharp_get_interpreted (uint8_t sharp_id) /* Return the previous value */ return sharp_previous_values_[sharp_id]; - /* Manage the hysteresis */ + /* Filter the value */ /* Check if previous value is the current state */ if (sharp_previous_values_[sharp_id] == current_state) { - /* Reset hysteresis */ - sharp_hysteresis_[sharp_id] = SHARP_HYSTERESIS_THRESHOLD; + /* Reset filter counter */ + sharp_filter_[sharp_id] = SHARP_FILTER_NUMBER; /* Return current state */ return current_state; } /* Otherwise, check if this sharp value has been the same - * SHARP_HYSTERESIS_THRESHOLD times */ - else if (sharp_hysteresis_[sharp_id]-- == 0) + * SHARP_FILTER_NUMBER times */ + else if (sharp_filter_[sharp_id]-- == 0) { - /* Current value change (for SHARP_HYSTERESIS_THRESHOLD times)! */ + /* Current value change (for SHARP_FILTER_NUMBER times)! */ /* Update previous value */ sharp_previous_values_[sharp_id] = current_state; - /* Reset hysteresis */ - sharp_hysteresis_[sharp_id] = SHARP_HYSTERESIS_THRESHOLD; + /* Reset filter counter */ + sharp_filter_[sharp_id] = SHARP_FILTER_NUMBER; /* Return current state */ return current_state; } diff --git a/digital/io/src/sharp.h b/digital/io/src/sharp.h index c3f64284..9f0abd8a 100644 --- a/digital/io/src/sharp.h +++ b/digital/io/src/sharp.h @@ -42,22 +42,22 @@ /** * Front left sharp. */ -#define SHARP_FRONT_LEFT _BV(0) +#define SHARP_FRONT_LEFT 0 /** * Front right sharp. */ -#define SHARP_FRONT_RIGHT _BV(1) +#define SHARP_FRONT_RIGHT 1 /** * Back left sharp. */ -#define SHARP_BACK_LEFT _BV(2) +#define SHARP_BACK_LEFT 2 /** * Back right sharp. */ -#define SHARP_BACK_RIGHT _BV(3) +#define SHARP_BACK_RIGHT 3 /** * Low (0 index) and high (1 index) thresholds for interpreted sharp values. -- cgit v1.2.3