#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
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;
- old_d
) >> MEASUREMENT_SHIFT;
}
+#else
+ distances[idx] = new_d;
+#endif
}
}
}