Modified version to work with EventQueue (outside of ISR)

Committer:
ohtsuka
Date:
Mon Jun 13 10:15:15 2016 +0000
Revision:
3:c7f97bebf2f7
Parent:
2:6af39916a4a2
Child:
4:8d6883cdc3c8
longpress supported.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ohtsuka 0:9c5c674dcaea 1 #include "mbed.h"
ohtsuka 0:9c5c674dcaea 2
ohtsuka 3:c7f97bebf2f7 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 3:c7f97bebf2f7 19 void attach_longpressed(void (*function)(void));
ohtsuka 0:9c5c674dcaea 20
ohtsuka 0:9c5c674dcaea 21 private:
ohtsuka 1:67d677ad73e7 22 void isr_pressed(void);
ohtsuka 1:67d677ad73e7 23 void isr_released(void);
ohtsuka 0:9c5c674dcaea 24 void click_timeout( void );
ohtsuka 1:67d677ad73e7 25 void debounce_timeout( void );
ohtsuka 3:c7f97bebf2f7 26 void longpress_timeout( void );
ohtsuka 1:67d677ad73e7 27
ohtsuka 1:67d677ad73e7 28 Timer *_t;
ohtsuka 0:9c5c674dcaea 29 Timeout *_timeout;
ohtsuka 1:67d677ad73e7 30 Timeout *_debounce_timeout;
ohtsuka 3:c7f97bebf2f7 31 Timeout *_longpress_timeout;
ohtsuka 0:9c5c674dcaea 32 InterruptIn *_iin;
ohtsuka 0:9c5c674dcaea 33 PinMode _mode;
ohtsuka 0:9c5c674dcaea 34
ohtsuka 1:67d677ad73e7 35 int _debounce_ignore_us;
ohtsuka 1:67d677ad73e7 36 int _pressed_time;
ohtsuka 1:67d677ad73e7 37 int _click_interval_us;
ohtsuka 1:67d677ad73e7 38 int _longpress_us;
ohtsuka 0:9c5c674dcaea 39 int _click_times;
ohtsuka 0:9c5c674dcaea 40
ohtsuka 1:67d677ad73e7 41 bool _debounce_ignore;
ohtsuka 3:c7f97bebf2f7 42 bool _longpressed;
ohtsuka 0:9c5c674dcaea 43 void (*_c_callback_clicked)(void);
ohtsuka 0:9c5c674dcaea 44 void (*_c_callback_doubleclicked)(void);
ohtsuka 0:9c5c674dcaea 45 void (*_c_callback_n_clicked)(int);
ohtsuka 3:c7f97bebf2f7 46 void (*_c_callback_longpressed)(void);
ohtsuka 0:9c5c674dcaea 47 };