Modified version to work with EventQueue (outside of ISR)

MultiClick.h

Committer:
ohtsuka
Date:
2016-06-13
Revision:
1:67d677ad73e7
Parent:
0:9c5c674dcaea
Child:
2:6af39916a4a2

File content as of revision 1:67d677ad73e7:

#include "mbed.h"

#define DEBUG

#ifdef DEBUG
#define DBG_PRINT(...) printf(__VA_ARGS__)
#else
#define DBG_PRINT(...)
#endif

class MultiClick
{
public:
    MultiClick(PinName pin);
    MultiClick(PinName pin, PinMode m);
    void attach_clicked(void (*function)(void));
    void attach_doubleclicked(void (*function)(void));
    void attach_n_clicked(void (*function)(int));
    
private:
    void isr_pressed(void);
    void isr_released(void);
    void click_timeout( void );
    void debounce_timeout( void );

    Timer *_t;
    Timeout *_timeout;
    Timeout *_debounce_timeout;
    InterruptIn *_iin;
    PinMode _mode;
    
    int _debounce_ignore_us;
    int _pressed_time;
    int _click_interval_us;
    int _longpress_us;
    int _click_times;
    
    bool _debounce_ignore;
    
    void (*_c_callback_clicked)(void);
    void (*_c_callback_doubleclicked)(void);
    void (*_c_callback_n_clicked)(int);
};