Modified version to work with EventQueue (outside of ISR)
MultiClick.h@2:6af39916a4a2, 2016-06-13 (annotated)
- Committer:
- ohtsuka
- Date:
- Mon Jun 13 09:11:53 2016 +0000
- Revision:
- 2:6af39916a4a2
- Parent:
- 1:67d677ad73e7
- Child:
- 3:c7f97bebf2f7
clink detection timing changed pressed to released.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ohtsuka | 0:9c5c674dcaea | 1 | #include "mbed.h" |
ohtsuka | 0:9c5c674dcaea | 2 | |
ohtsuka | 2:6af39916a4a2 | 3 | //#define DEBUG |
ohtsuka | 1:67d677ad73e7 | 4 | |
ohtsuka | 1:67d677ad73e7 | 5 | #ifdef DEBUG |
ohtsuka | 1:67d677ad73e7 | 6 | #define DBG_PRINT(...) printf(__VA_ARGS__) |
ohtsuka | 1:67d677ad73e7 | 7 | #else |
ohtsuka | 1:67d677ad73e7 | 8 | #define DBG_PRINT(...) |
ohtsuka | 1:67d677ad73e7 | 9 | #endif |
ohtsuka | 1:67d677ad73e7 | 10 | |
ohtsuka | 0:9c5c674dcaea | 11 | class MultiClick |
ohtsuka | 0:9c5c674dcaea | 12 | { |
ohtsuka | 0:9c5c674dcaea | 13 | public: |
ohtsuka | 0:9c5c674dcaea | 14 | MultiClick(PinName pin); |
ohtsuka | 0:9c5c674dcaea | 15 | MultiClick(PinName pin, PinMode m); |
ohtsuka | 0:9c5c674dcaea | 16 | void attach_clicked(void (*function)(void)); |
ohtsuka | 0:9c5c674dcaea | 17 | void attach_doubleclicked(void (*function)(void)); |
ohtsuka | 0:9c5c674dcaea | 18 | void attach_n_clicked(void (*function)(int)); |
ohtsuka | 0:9c5c674dcaea | 19 | |
ohtsuka | 0:9c5c674dcaea | 20 | private: |
ohtsuka | 1:67d677ad73e7 | 21 | void isr_pressed(void); |
ohtsuka | 1:67d677ad73e7 | 22 | void isr_released(void); |
ohtsuka | 0:9c5c674dcaea | 23 | void click_timeout( void ); |
ohtsuka | 1:67d677ad73e7 | 24 | void debounce_timeout( void ); |
ohtsuka | 1:67d677ad73e7 | 25 | |
ohtsuka | 1:67d677ad73e7 | 26 | Timer *_t; |
ohtsuka | 0:9c5c674dcaea | 27 | Timeout *_timeout; |
ohtsuka | 1:67d677ad73e7 | 28 | Timeout *_debounce_timeout; |
ohtsuka | 0:9c5c674dcaea | 29 | InterruptIn *_iin; |
ohtsuka | 0:9c5c674dcaea | 30 | PinMode _mode; |
ohtsuka | 0:9c5c674dcaea | 31 | |
ohtsuka | 1:67d677ad73e7 | 32 | int _debounce_ignore_us; |
ohtsuka | 1:67d677ad73e7 | 33 | int _pressed_time; |
ohtsuka | 1:67d677ad73e7 | 34 | int _click_interval_us; |
ohtsuka | 1:67d677ad73e7 | 35 | int _longpress_us; |
ohtsuka | 0:9c5c674dcaea | 36 | int _click_times; |
ohtsuka | 0:9c5c674dcaea | 37 | |
ohtsuka | 1:67d677ad73e7 | 38 | bool _debounce_ignore; |
ohtsuka | 1:67d677ad73e7 | 39 | |
ohtsuka | 0:9c5c674dcaea | 40 | void (*_c_callback_clicked)(void); |
ohtsuka | 0:9c5c674dcaea | 41 | void (*_c_callback_doubleclicked)(void); |
ohtsuka | 0:9c5c674dcaea | 42 | void (*_c_callback_n_clicked)(int); |
ohtsuka | 0:9c5c674dcaea | 43 | }; |