From 0910372c57f24036c568f2c35f9c88dc6d1f2d71 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Mon, 23 Mar 2020 12:52:21 +0100 Subject: [PATCH] application: Use the previous/next buttons to cycle the current view. --- src/application/main.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/application/main.rs b/src/application/main.rs index 2b2f8f6..6e8d37d 100644 --- a/src/application/main.rs +++ b/src/application/main.rs @@ -88,6 +88,20 @@ impl Timer { } } +fn next_view(view: View) -> View { + match view { + View::Time => View::Distance, + View::Distance => View::Time, + } +} + +fn previous_view(view: View) -> View { + match view { + View::Time => View::Distance, + View::Distance => View::Time, + } +} + fn reset_requested() -> bool { let pta1 = gpio::get(gpio::GPIOA) & (1 << 1); let pte25 = gpio::get(gpio::GPIOE) & (1 << 25); @@ -220,6 +234,8 @@ pub unsafe extern "C" fn _start() -> ! { logger.init(); let mut pta12 = button::Button::new(gpio::GPIOA, 1 << 12); + let mut pte24 = button::Button::new(gpio::GPIOE, 1 << 24); + let mut pta01 = button::Button::new(gpio::GPIOA, 1 << 1); let mut is_recording = false; let mut gps = gps::Gps::new(); @@ -328,6 +344,23 @@ pub unsafe extern "C" fn _start() -> ! { model.reset(); } + let new_view = if pte24.has_been_held_for_ms(250) { + previous_view(view) + } else if pta01.has_been_held_for_ms(250) { + next_view(view) + } else { + view + }; + + if view != new_view { + view = new_view; + + match view { + View::Time => time_view.invalidate(), + View::Distance => distance_view.invalidate(), + } + } + if reset_requested() { nvic::system_reset(); } -- 2.30.2