From 957f92d17712d24a3030d03e7cfab71e96483c57 Mon Sep 17 00:00:00 2001 From: Astro Date: Sat, 14 Sep 2019 02:18:33 +0200 Subject: [PATCH] main: fight jitter --- firmware/src/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/firmware/src/main.rs b/firmware/src/main.rs index 5b50f25..878d450 100644 --- a/firmware/src/main.rs +++ b/firmware/src/main.rs @@ -219,7 +219,13 @@ fn main() -> ! { }); let now = get_time(); if now >= last_report + REPORT_INTERVAL { - last_report = now; + if now < last_report + 2 * REPORT_INTERVAL { + // Try to keep interval constant + last_report += REPORT_INTERVAL; + } else { + // Bad jitter, catch up + last_report = now; + } // TODO: calculate med instead of avg? report = Some((now, [ sample[0].0 / (sample[0].1 as u64),