X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fapplication%2Fmain.rs;h=dc955ce7af46fb39fc5b37721e4b12c5b7cbcbd3;hb=70fb2fadd8688fdc11ba1d398661ac99aaa1b02a;hp=3523b885fe9a907b081c9b85da75f9d8b3380643;hpb=aa0f0d612a03799423e87e9137765ecb90146f48;p=gps-watch.git diff --git a/src/application/main.rs b/src/application/main.rs index 3523b88..dc955ce 100644 --- a/src/application/main.rs +++ b/src/application/main.rs @@ -28,8 +28,10 @@ extern crate common; mod uart0; +mod button; use common::buffer::Buffer; +use common::ringbuf::Ringbuf; use common::clock; use common::systick; use common::port; @@ -45,6 +47,7 @@ use common::screen; use common::time::Time; use common::mx25l::Mx25l; use common::shell::Shell; +use common::logger::Logger; extern { fn enable_interrupts(); @@ -122,6 +125,20 @@ fn configure_push_buttons() { port::set_pull(port::PORTE, 31, port::Pull::Up); } +fn uart0_try_read() -> Option { + extern { + static mut uart0_rx_buf: Ringbuf; + } + + unsafe { + if uart0_rx_buf.is_empty() { + None + } else { + Some(uart0_rx_buf.read()) + } + } +} + #[no_mangle] pub unsafe extern "C" fn _start() -> ! { clock::configure(); @@ -192,6 +209,12 @@ pub unsafe extern "C" fn _start() -> ! { let mut mx25l = Mx25l::new(gpio::GPIOD, 1 << 0); + let mut logger = Logger::new(&mut mx25l); + logger.init(); + + let mut pta12 = button::Button::new(gpio::GPIOA, 1 << 12); + let mut is_recording = false; + let mut gps = gps::Gps::new(); let mut gps_has_fix = false; @@ -205,9 +228,16 @@ pub unsafe extern "C" fn _start() -> ! { 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) { + while gps.update(&mut tap, uart0_try_read) { + if is_recording { + logger.log(&prev_tap, &tap); + + show_distance = true; + } + prev_tap = tap; show_time = true; @@ -245,7 +275,17 @@ 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, + logger.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); @@ -267,7 +307,17 @@ pub unsafe extern "C" fn _start() -> ! { } }); - shell.update(&mut mx25l); + shell.update(&mut logger); + + if pta12.has_been_held_for_ms(1500) { + is_recording = !is_recording; + + if is_recording { + logger.start_recording(&prev_tap); + } else { + logger.stop_recording(&prev_tap); + } + } if reset_requested() { nvic::system_reset();