common: Store distance travelled in Logger instance.
authorTilman Sauerbeck <tilman@code-monkey.de>
Sat, 28 Mar 2020 16:30:49 +0000 (17:30 +0100)
committerTilman Sauerbeck <tilman@code-monkey.de>
Sat, 28 Mar 2020 16:31:13 +0000 (17:31 +0100)
src/application/main.rs
src/common/logger.rs

index 4fa0c96513e974bab1d0f31e29b414dd524213cd..dc955ce7af46fb39fc5b37721e4b12c5b7cbcbd3 100644 (file)
@@ -225,8 +225,6 @@ pub unsafe extern "C" fn _start() -> ! {
 
     let mut prev_tap = gps::TimeAndPos::new();
 
-    let mut total_distance_cm = 0;
-
     loop {
         let mut tap = gps::TimeAndPos::new();
         let mut show_time = false;
@@ -237,8 +235,6 @@ pub unsafe extern "C" fn _start() -> ! {
             if is_recording {
                 logger.log(&prev_tap, &tap);
 
-                total_distance_cm += tap.distance_cm(&prev_tap) as u32;
-
                 show_distance = true;
             }
 
@@ -282,7 +278,8 @@ pub unsafe extern "C" fn _start() -> ! {
         if show_distance {
             let mut distance_m_s = [b' '; 8];
 
-            common::fmt::fmt_u32(&mut distance_m_s, total_distance_cm / 100);
+            common::fmt::fmt_u32(&mut distance_m_s,
+                                 logger.total_distance_cm / 100);
 
             screen.clear();
             screen.draw_text(&distance_m_s);
@@ -320,8 +317,6 @@ pub unsafe extern "C" fn _start() -> ! {
             } else {
                 logger.stop_recording(&prev_tap);
             }
-
-            total_distance_cm = 0;
         }
 
         if reset_requested() {
index 9b498ce64a5cec5e7f76be504fab5395a80ac41c..ea84bc23d4e23ad71d73f6ec6859977e1f913a6b 100644 (file)
@@ -116,6 +116,9 @@ pub struct Logger<'a> {
 
     recording_started: u32,
 
+    // The total distance logged of the currently running recording.
+    pub total_distance_cm: u32,
+
     // The number of slots filled in num_flight.
     num_in_flight: usize,
 
@@ -290,6 +293,7 @@ impl<'a> Logger<'a> {
             recording_id: 0,
             first_sector: 0,
             recording_started: 0,
+            total_distance_cm: 0,
             num_in_flight: 0,
 
             in_flight: [InFlight::new(); 7],
@@ -357,6 +361,7 @@ impl<'a> Logger<'a> {
 
         self.sectors_written = 0;
         self.recording_started = tap.unix_time;
+        self.total_distance_cm = 0;
         self.num_in_flight = 0;
 
         self.prepare_write_buffer(true);
@@ -367,6 +372,8 @@ impl<'a> Logger<'a> {
     }
 
     pub fn log(&mut self, prev_tap: &TimeAndPos, tap: &TimeAndPos) {
+        self.total_distance_cm += tap.distance_cm(&prev_tap) as u32;
+
         let d_time_ms = elapsed_ms(tap.system_time, prev_tap.system_time);
 
         // We know that our hardware cannot deliver updates more often