summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--n/es-2007/src/sharp.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/n/es-2007/src/sharp.c b/n/es-2007/src/sharp.c
index 167b86b..f98a6ea 100644
--- a/n/es-2007/src/sharp.c
+++ b/n/es-2007/src/sharp.c
@@ -33,7 +33,6 @@ uint16_t sharp_values[SHARP_NUMBER];
/** Thresholds */
uint16_t sharp_threshold_high_[SHARP_NUMBER],
sharp_threshold_low_[SHARP_NUMBER];
-uint8_t sharp_old_state[SHARP_NUMBER];
/** Init this module. */
void
@@ -73,22 +72,27 @@ sharp_update_values (uint8_t sharp_num)
int8_t
sharp_analyse_values (uint8_t sharp_num)
{
+ static int8_t compt = 0;
/* Check sharp exists (prevent kernel panic) */
if (sharp_num < SHARP_NUMBER)
{
- // XXX Check more often first
if (sharp_values[sharp_num] < sharp_threshold_low_[sharp_num])
{
- sharp_old_state[sharp_num] = SHARP_CLEAR;
+ compt = 0;
return SHARP_CLEAR;
}
- if (sharp_values[sharp_num] > sharp_threshold_high_[sharp_num])
+ else
{
- sharp_old_state[sharp_num] = SHARP_OBSTACLE;
- return SHARP_OBSTACLE;
+ if (compt == 10)
+ {
+ return SHARP_OBSTACLE;
+ }
+ else
+ {
+ compt++;
+ return SHARP_CLEAR;
+ }
}
- /* If we are here, we are inside the threshold, look at previous value */
- return sharp_old_state[sharp_num];
}
return -1;
}