From 0bbaad8dc171999d4aeabae9b5b222364f066388 Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Sat, 23 May 2015 17:27:39 +0200 Subject: [PATCH] Make running averaging optional. --- firmware/firmware.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/firmware/firmware.c b/firmware/firmware.c index f890c15..5400714 100644 --- a/firmware/firmware.c +++ b/firmware/firmware.c @@ -7,7 +7,7 @@ #define ECHO_TIMEOUT (CLOCK_HZ/10) // 100 ms #define MEASUREMENT_WAIT (2*ECHO_TIMEOUT) -#define MEASUREMENT_SHIFT 2 // running avg (1 << M_SHIFT) +#define MEASUREMENT_SHIFT 0 // running avg (1 << M_SHIFT) #define N_TRIGGERS 3 #define N_SENSORS 12 @@ -72,16 +72,20 @@ static void do_measurement(unsigned char trig) to_start &= ~mask; to_measure |= mask; } else if ((to_measure & mask) && !(bits & mask)) { - uint16_t old_d, new_d; +#if MEASUREMENT_SHIFT > 0 + uint16_t old_d; +#endif + uint16_t new_d; uint8_t idx = trig*N_TRIG_SENSORS+i; // echo end to_measure &= ~mask; new_d = now - starttimes[i]; - old_d = distances[idx]; - if (new_d > max_distances[idx]) max_distances[idx] = new_d; +#if MEASUREMENT_SHIFT > 0 + old_d = distances[idx]; + if (old_d == 0 || old_d == -1) { distances[idx] = new_d; @@ -92,6 +96,9 @@ static void do_measurement(unsigned char trig) - old_d ) >> MEASUREMENT_SHIFT; } +#else + distances[idx] = new_d; +#endif } } } -- 2.43.5