X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fapplication%2Fmain.rs;h=4cad3e326ee1720361a991c263b6e7ec3db33d16;hb=727108edeb96e0b534c86d52ad3f7515b26c1798;hp=74f199906853468fd5c6ac22fd41f25bc333480d;hpb=45b7bcb737ad4bedf4f93548869f5037a6a2c1c2;p=gps-watch.git diff --git a/src/application/main.rs b/src/application/main.rs index 74f1999..4cad3e3 100644 --- a/src/application/main.rs +++ b/src/application/main.rs @@ -40,6 +40,8 @@ use common::uart; use common::usb_serial; use common::display; use common::gps; +use common::screen; +use common::time::Time; extern { fn enable_interrupts(); @@ -73,6 +75,13 @@ impl Timer { } } +#[inline(never)] +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + loop { + } +} + #[no_mangle] pub unsafe extern "C" fn _start() -> ! { clock::configure(); @@ -117,6 +126,8 @@ pub unsafe extern "C" fn _start() -> ! { display.init(); display.clear(); + let mut screen = screen::Screen::new(); + // Hold GPS in reset while configuring its UART. gpio::clear(gpio::GPIOB, 1); systick::delay_ms(50); @@ -128,12 +139,67 @@ pub unsafe extern "C" fn _start() -> ! { let mut gps = gps::Gps::new(); + let mut gps_has_fix = false; + let mut gps_has_fix_ticks = 0; + let mut heart_icon_timer = Timer::new(1000); + let mut gps_icon_timer = Timer::new(500); + + let mut prev_tap = gps::TimeAndPos::new(); loop { let mut tap = gps::TimeAndPos::new(); + let mut show_time = false; + let old_gps_has_fix = gps_has_fix; while gps.update(&mut tap) { + prev_tap = tap; + + show_time = true; + + gps_has_fix = true; + gps_has_fix_ticks = systick::now(); + } + + // Did GPS fix information expire? + if gps_has_fix && systick::has_timeout_ms(gps_has_fix_ticks, 1500) { + gps_has_fix = false; + } + + if gps_has_fix && !old_gps_has_fix { + display.show_icon(display::Icon::SatelliteBody); + display.show_icon(display::Icon::SatelliteWave1); + display.show_icon(display::Icon::SatelliteWave2); + } else if !gps_has_fix { + gps_icon_timer.update(|state| { + if state == 1 { + display.show_icon(display::Icon::SatelliteWave1); + 2 + } else if state == 2 { + display.show_icon(display::Icon::SatelliteWave2); + 3 + } else if state == 3 { + display.hide_icon(display::Icon::SatelliteBody); + display.hide_icon(display::Icon::SatelliteWave1); + display.hide_icon(display::Icon::SatelliteWave2); + 0 + } else { + display.show_icon(display::Icon::SatelliteBody); + 1 + } + }); + } + + 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); + + screen.clear(); + screen.draw_text(&time_s); + + display.draw(&screen); + } } heart_icon_timer.update(|state| {