#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
#define TICK_HANDLER_ID 1
#define DISPATCH_HANDLER_ID 2
-int32_t buttonCnt = 0;
-
static void buttonHandler(void);
static void postEvent(uint8_t handlerId);
/* -------- 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) {
#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();
}
static void buttonHandler(void);
static void tickHandler(void);
static bool connected = false;
+static int32_t buttonCnt = 0;
void main() {
Hal_init();
static void buttonHandler(void) {
uint8_t i;
+ buttonCnt++;
if (connected)
Pulsecounter_event3_indicate();
else
for (i = 0; i < 3; i++) {
Hal_greenLedOn();
Hal_redLedOn();
- Hal_delay(100);
+ Hal_delay(10);
Hal_greenLedOff();
Hal_redLedOff();
}