From c2f159b63f3c013e82ed3e79e9d1fb4a55982cde Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Wed, 6 Mar 2019 23:03:06 +0100 Subject: [PATCH] Add a flip() helper method for LedDirection; use it --- src/main.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1227f19..3b462e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,15 @@ pub enum LedDirection { CounterClockwise, } +impl LedDirection { + fn flip(&self) -> LedDirection { + match self { + LedDirection::Clockwise => LedDirection::CounterClockwise, + LedDirection::CounterClockwise => LedDirection::Clockwise, + } + } +} + #[app(device = hal::stm32)] const APP: () = { static mut button: UserButton = (); @@ -68,10 +77,8 @@ const APP: () = { #[interrupt(binds = EXTI0, resources = [button, exti, led_cycle_direction])] fn button_pressed() { - *resources.led_cycle_direction = match *resources.led_cycle_direction { - LedDirection::Clockwise => LedDirection::CounterClockwise, - LedDirection::CounterClockwise => LedDirection::Clockwise, - }; + *resources.led_cycle_direction = resources.led_cycle_direction.flip(); + resources.button.clear_interrupt_pending_bit(resources.exti); }