application: Start and stop recordings by pressing the play button.
authorTilman Sauerbeck <tilman@code-monkey.de>
Thu, 9 Jan 2020 14:14:40 +0000 (15:14 +0100)
committerTilman Sauerbeck <tilman@code-monkey.de>
Thu, 9 Jan 2020 20:00:04 +0000 (21:00 +0100)
src/application/main.rs

index e11aaf71cc5a9f538c9794cf570f87f9ac245bf8..a8101f74f80542373a896f54730b7db90a4e933e 100644 (file)
@@ -124,6 +124,10 @@ fn configure_push_buttons() {
     port::set_pull(port::PORTE, 31, port::Pull::Up);
 }
 
+fn poll_pta12() -> bool {
+    (gpio::get(gpio::GPIOA) & (1 << 12)) == 0
+}
+
 fn uart0_try_read() -> Option<u8> {
     extern {
         static mut uart0_rx_buf: Ringbuf;
@@ -211,6 +215,10 @@ pub unsafe extern "C" fn _start() -> ! {
     let mut logger = Logger::new(&mut mx25l);
     logger.init();
 
+    let mut pta1_start_press_ticks = 0;
+    let mut pta12_was_pressed = poll_pta12();
+    let mut is_recording = false;
+
     let mut gps = gps::Gps::new();
 
     let mut gps_has_fix = false;
@@ -227,6 +235,10 @@ pub unsafe extern "C" fn _start() -> ! {
         let old_gps_has_fix = gps_has_fix;
 
         while gps.update(&mut tap, uart0_try_read) {
+            if is_recording {
+                logger.log(&prev_tap, &tap);
+            }
+
             prev_tap = tap;
 
             show_time = true;
@@ -288,6 +300,24 @@ pub unsafe extern "C" fn _start() -> ! {
 
         shell.update(&mut logger);
 
+        let pta12_is_pressed = poll_pta12();
+
+        if !pta12_was_pressed && pta12_is_pressed {
+            pta1_start_press_ticks = systick::now();
+        } else if pta12_was_pressed && !pta12_is_pressed {
+            if systick::has_timeout_ms(pta1_start_press_ticks, 1500) {
+                is_recording = !is_recording;
+
+                if is_recording {
+                    logger.start_recording(&prev_tap);
+                } else {
+                    logger.stop_recording(&prev_tap);
+                }
+            }
+        }
+
+        pta12_was_pressed = pta12_is_pressed;
+
         if reset_requested() {
             nvic::system_reset();
         }