Modified version to work with EventQueue (outside of ISR)

Committer:
ohtsuka
Date:
Mon Jun 13 08:30:29 2016 +0000
Revision:
1:67d677ad73e7
Parent:
0:9c5c674dcaea
Child:
2:6af39916a4a2
??????(debounce)??

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ohtsuka 0:9c5c674dcaea 1 #include "mbed.h"
ohtsuka 0:9c5c674dcaea 2
ohtsuka 1:67d677ad73e7 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 };