summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2011-09-29 00:37:35 +0200
committerNicolas Schodet2011-09-29 00:37:35 +0200
commitcba9577eee62547945757ddb998d3bb5d4c64442 (patch)
tree3df3eb29d84b814f256bbc983e3667e09b21b57e
parentd69ab26ce85f23a17753a70760bdb5334a3bed8f (diff)
src/common: get button press duration
-rw-r--r--src/common/button.c8
-rw-r--r--src/common/button.h5
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. */