summaryrefslogtreecommitdiff
path: root/n/es-2006/src/sharp.c
diff options
context:
space:
mode:
Diffstat (limited to 'n/es-2006/src/sharp.c')
-rw-r--r--n/es-2006/src/sharp.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/n/es-2006/src/sharp.c b/n/es-2006/src/sharp.c
index 62b0719..167b86b 100644
--- a/n/es-2006/src/sharp.c
+++ b/n/es-2006/src/sharp.c
@@ -30,13 +30,24 @@
/** Array of sharp values. */
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
sharp_init (void)
{
+ uint8_t compt;
/* Init ADC module */
adc_init ();
/* All pins are on the right direction, nothing to do */
+ for (compt = 0; compt < SHARP_NUMBER; compt++)
+ {
+ sharp_threshold_high_[compt] = 5000;
+ sharp_threshold_low_[compt] = 4000;
+ }
}
/** Read data from sharp sensors. */
@@ -57,3 +68,39 @@ sharp_update_values (uint8_t sharp_num)
sharp_values[sharp_num] = adc_read ();
}
}
+
+/** Analyse a sharp value. */
+int8_t
+sharp_analyse_values (uint8_t sharp_num)
+{
+ /* 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;
+ return SHARP_CLEAR;
+ }
+ if (sharp_values[sharp_num] > sharp_threshold_high_[sharp_num])
+ {
+ sharp_old_state[sharp_num] = SHARP_OBSTACLE;
+ return SHARP_OBSTACLE;
+ }
+ /* If we are here, we are inside the threshold, look at previous value */
+ return sharp_old_state[sharp_num];
+ }
+ return -1;
+}
+
+/** Configure sharp threshold. */
+void
+sharp_config_threshold (uint8_t sharp_num, uint16_t high, uint16_t low)
+{
+ /* Check sharp exists (prevent kernel panic) */
+ if (sharp_num < SHARP_NUMBER)
+ {
+ sharp_threshold_high_[sharp_num] = high;
+ sharp_threshold_low_[sharp_num] = low;
+ }
+}