abc
Dependents: Microwave_MBED MicrowaveSimulation_LPC1768 RTOS_Alarm_Clock USB_Project_Host ... more
DebounceInterrupts.h@7:2d73e219dadf, 2014-02-18 (annotated)
- Committer:
- kandangath
- Date:
- Tue Feb 18 07:00:07 2014 +0000
- Revision:
- 7:2d73e219dadf
- Parent:
- 5:3c0f741fb448
- Child:
- 8:4b3ff16d5f91
Add counter for debounced interrupts
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kandangath | 0:ca5a0fee9f52 | 1 | |
kandangath | 0:ca5a0fee9f52 | 2 | /** |
kandangath | 1:ffacad1b455a | 3 | * Debounces an InterruptIn |
kandangath | 0:ca5a0fee9f52 | 4 | */ |
kandangath | 5:3c0f741fb448 | 5 | |
kandangath | 5:3c0f741fb448 | 6 | /* |
kandangath | 5:3c0f741fb448 | 7 | Example: |
kandangath | 5:3c0f741fb448 | 8 | InterruptIn up_button(p15); |
kandangath | 5:3c0f741fb448 | 9 | |
kandangath | 5:3c0f741fb448 | 10 | void onUp() |
kandangath | 5:3c0f741fb448 | 11 | { |
kandangath | 5:3c0f741fb448 | 12 | // Do Something |
kandangath | 5:3c0f741fb448 | 13 | } |
kandangath | 5:3c0f741fb448 | 14 | |
kandangath | 5:3c0f741fb448 | 15 | int main() |
kandangath | 5:3c0f741fb448 | 16 | { |
kandangath | 5:3c0f741fb448 | 17 | DebounceInterrupts upD(&onUp, &up_button, INT_FALL, 100); |
kandangath | 5:3c0f741fb448 | 18 | while(1) { |
kandangath | 5:3c0f741fb448 | 19 | ... |
kandangath | 5:3c0f741fb448 | 20 | } |
kandangath | 5:3c0f741fb448 | 21 | } |
kandangath | 5:3c0f741fb448 | 22 | */ |
kandangath | 0:ca5a0fee9f52 | 23 | |
kandangath | 0:ca5a0fee9f52 | 24 | #ifndef DEBOUNCE_INTERRUPTS_H |
kandangath | 0:ca5a0fee9f52 | 25 | #define DEBOUNCE_INTERRUPTS_H |
kandangath | 0:ca5a0fee9f52 | 26 | |
kandangath | 0:ca5a0fee9f52 | 27 | #include <stdint.h> |
kandangath | 0:ca5a0fee9f52 | 28 | #include "mbed.h" |
kandangath | 0:ca5a0fee9f52 | 29 | |
kandangath | 4:19689187352e | 30 | enum interruptTrigger{ |
kandangath | 4:19689187352e | 31 | INT_FALL = 0, |
kandangath | 4:19689187352e | 32 | INT_RISE = 1 |
kandangath | 4:19689187352e | 33 | }; |
kandangath | 4:19689187352e | 34 | |
kandangath | 0:ca5a0fee9f52 | 35 | class DebounceInterrupts { |
kandangath | 0:ca5a0fee9f52 | 36 | private: |
kandangath | 7:2d73e219dadf | 37 | unsigned int _debounce_us; |
kandangath | 7:2d73e219dadf | 38 | unsigned int _debounce_count; |
kandangath | 7:2d73e219dadf | 39 | |
kandangath | 0:ca5a0fee9f52 | 40 | void (*fCallback)(void); |
kandangath | 3:e4b7033508d1 | 41 | void _onInterrupt(void); |
kandangath | 7:2d73e219dadf | 42 | void _callback(void); |
kandangath | 0:ca5a0fee9f52 | 43 | public: |
kandangath | 4:19689187352e | 44 | DebounceInterrupts(void (*fptr)(void), /* function to be called after debounced InterruptIn */ |
kandangath | 4:19689187352e | 45 | InterruptIn *interrupt, /* InterruptIn to monitor */ |
kandangath | 4:19689187352e | 46 | const interruptTrigger& trigger, /* true: rise, false: fall */ |
kandangath | 4:19689187352e | 47 | const uint32_t& debounce_ms=10); /* stability duration required */ |
kandangath | 0:ca5a0fee9f52 | 48 | ~DebounceInterrupts(); |
kandangath | 7:2d73e219dadf | 49 | /* |
kandangath | 7:2d73e219dadf | 50 | * Get number of de-bounced interrupts |
kandangath | 7:2d73e219dadf | 51 | * @return: debounced count |
kandangath | 7:2d73e219dadf | 52 | */ |
kandangath | 7:2d73e219dadf | 53 | unsigned int get_debounce(); |
kandangath | 0:ca5a0fee9f52 | 54 | }; |
kandangath | 0:ca5a0fee9f52 | 55 | #endif |