X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fapplication%2Fmain.rs;h=dc955ce7af46fb39fc5b37721e4b12c5b7cbcbd3;hb=70fb2fadd8688fdc11ba1d398661ac99aaa1b02a;hp=f1eb522a739068dda8977821c694e7bf768d215a;hpb=b00dd201b1c26fbd72c4930e26e3420ad8c276a0;p=gps-watch.git diff --git a/src/application/main.rs b/src/application/main.rs index f1eb522..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; @@ -43,6 +45,9 @@ use common::display; use common::gps; use common::screen; use common::time::Time; +use common::mx25l::Mx25l; +use common::shell::Shell; +use common::logger::Logger; extern { fn enable_interrupts(); @@ -120,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(); @@ -186,6 +205,16 @@ pub unsafe extern "C" fn _start() -> ! { nvic::enable_irq(12); // UART0 + let mut shell = Shell::new(&mut cdc_tx_buf); + + 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; @@ -199,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; @@ -239,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); @@ -261,6 +307,18 @@ pub unsafe extern "C" fn _start() -> ! { } }); + 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(); }