application: Show distance travelled while recording.
authorTilman Sauerbeck <tilman@code-monkey.de>
Sun, 19 Jan 2020 11:16:48 +0000 (12:16 +0100)
committerTilman Sauerbeck <tilman@code-monkey.de>
Sun, 19 Jan 2020 20:34:38 +0000 (21:34 +0100)
src/application/main.rs

index a8101f74f80542373a896f54730b7db90a4e933e..ac87977963aa8c4411c10ecef9ffc6adabd88ca8 100644 (file)
@@ -229,14 +229,21 @@ 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;
+        let mut show_distance = false;
         let old_gps_has_fix = gps_has_fix;
 
         while gps.update(&mut tap, uart0_try_read) {
             if is_recording {
                 logger.log(&prev_tap, &tap);
+
+                total_distance_cm += tap.distance_cm(&prev_tap) as u32;
+
+                show_distance = true;
             }
 
             prev_tap = tap;
@@ -276,7 +283,16 @@ pub unsafe extern "C" fn _start() -> ! {
             });
         }
 
-        if show_time {
+        if show_distance {
+            let mut distance_m_s = [b' '; 8];
+
+            common::fmt::fmt_u32(&mut distance_m_s, total_distance_cm / 100);
+
+            screen.clear();
+            screen.draw_text(&distance_m_s);
+
+            display.draw(&screen);
+        } else if show_time {
             if let Some(tm) = Time::from_unix_time(prev_tap.unix_time) {
                 let mut time_s = [b' '; 8];
                 tm.fmt_time(&mut time_s);
@@ -313,6 +329,8 @@ pub unsafe extern "C" fn _start() -> ! {
                 } else {
                     logger.stop_recording(&prev_tap);
                 }
+
+                total_distance_cm = 0;
             }
         }