From 13db6cae32995a2f76fb4b4f1c5f40cea2470a55 Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Thu, 10 Dec 2015 22:39:01 +0300 Subject: [PATCH] count interrupts, disable for 100ms --- Hal/Hal.c | 13 +++++++------ Hal/Hal.h | 2 -- Pulsecounter-Prog.c | 4 +++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Hal/Hal.c b/Hal/Hal.c index 00b8c6b..ef498ba 100644 --- a/Hal/Hal.c +++ b/Hal/Hal.c @@ -24,6 +24,8 @@ #define BUTTON_CONFIG() (P1DIR &= ~BIT3, P1REN |= BIT3, P1OUT |= BIT3, P1IES |= BIT3); #define BUTTON_ENABLE() (P1IFG &= ~BIT3, P1IE |= BIT3) +#define BUTTON_DISABLE() (P1IE &= ~BIT3, P1IFG &= ~BIT3) +#define BUTTON_FIRED() (P1IFG & BIT3) #define BUTTON_PRESSED() (!(P1IN & BIT3)) #define BUTTON_DEBOUNCE_MSECS 100 @@ -90,8 +92,6 @@ #define TICK_HANDLER_ID 1 #define DISPATCH_HANDLER_ID 2 -int32_t buttonCnt = 0; - static void buttonHandler(void); static void postEvent(uint8_t handlerId); @@ -327,10 +327,11 @@ void Em_Hal_watchOn(void) { /* -------- INTERNAL FUNCTIONS -------- */ static void buttonHandler(void) { - Hal_delay(100); + Hal_delay(BUTTON_DEBOUNCE_MSECS); if (BUTTON_PRESSED() && appButtonHandler) { appButtonHandler(); } + BUTTON_ENABLE(); } static void postEvent(uint8_t handlerId) { @@ -348,9 +349,9 @@ static void postEvent(uint8_t handlerId) { #pragma vector=PORT1_VECTOR #endif INTERRUPT void buttonIsr(void) { - buttonCnt++; - postEvent(BUTTON_HANDLER_ID); - BUTTON_ENABLE(); + if (BUTTON_FIRED()) + postEvent(BUTTON_HANDLER_ID); + BUTTON_DISABLE(); WAKEUP(); } diff --git a/Hal/Hal.h b/Hal/Hal.h index 374daf5..8ec28c9 100644 --- a/Hal/Hal.h +++ b/Hal/Hal.h @@ -26,8 +26,6 @@ extern "C" { #endif -extern int32_t buttonCnt; - typedef void (*Hal_Handler)(void); /** diff --git a/Pulsecounter-Prog.c b/Pulsecounter-Prog.c index 2c3256d..f507178 100644 --- a/Pulsecounter-Prog.c +++ b/Pulsecounter-Prog.c @@ -4,6 +4,7 @@ static void buttonHandler(void); static void tickHandler(void); static bool connected = false; +static int32_t buttonCnt = 0; void main() { Hal_init(); @@ -16,6 +17,7 @@ void main() { static void buttonHandler(void) { uint8_t i; + buttonCnt++; if (connected) Pulsecounter_event3_indicate(); else @@ -23,7 +25,7 @@ static void buttonHandler(void) { for (i = 0; i < 3; i++) { Hal_greenLedOn(); Hal_redLedOn(); - Hal_delay(100); + Hal_delay(10); Hal_greenLedOff(); Hal_redLedOff(); } -- 2.39.2