From cba9577eee62547945757ddb998d3bb5d4c64442 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Thu, 29 Sep 2011 00:37:35 +0200 Subject: src/common: get button press duration --- src/common/button.c | 8 +++++++- src/common/button.h | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/common/button.c b/src/common/button.c index adcda43..a733772 100644 --- a/src/common/button.c +++ b/src/common/button.c @@ -40,7 +40,7 @@ button_init (void) /* Button is shared with leds, no PORT init. */ } -void +uint16_t button_wait (void) { /* Wait until button is pressed. */ @@ -53,6 +53,7 @@ button_wait (void) /* Remove pull-up to save battery and shut off leds. */ led_no_pull_up (); /* Wait until button is really released. */ + uint16_t press_ms = 0; uint8_t debounce_ms = 0; while (debounce_ms < BUTTON_DEBOUNCE_MS) { @@ -60,8 +61,13 @@ button_wait (void) if (IO_GET (BUTTON_IO)) debounce_ms++; else + { debounce_ms = 0; + if (press_ms < 60000) + press_ms++; + } } + return press_ms; } SIGNAL (PCINT0_vect) diff --git a/src/common/button.h b/src/common/button.h index f7c1238..d3717f1 100644 --- a/src/common/button.h +++ b/src/common/button.h @@ -32,8 +32,9 @@ void button_init (void); -/** Wait until the button is pressed and released. */ -void +/** Wait until the button is pressed and released, return press duration in + * milliseconds. */ +uint16_t button_wait (void); /** Return true if button is currently pressed. */ -- cgit v1.2.3