]> www.fi.muni.cz Git - openparking.git/commitdiff
Make running averaging optional.
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Sat, 23 May 2015 15:27:39 +0000 (17:27 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Sat, 23 May 2015 15:50:27 +0000 (17:50 +0200)
firmware/firmware.c

index f890c15c9608429926a555adf0709d9bf2134090..5400714f48b10645dc196673493eb88d7a321871 100644 (file)
@@ -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
                        }
                }
        }