Modified version to work with EventQueue (outside of ISR)

MultiClick.h

Committer:
ohtsuka
Date:
2016-06-15
Revision:
4:8d6883cdc3c8
Parent:
3:c7f97bebf2f7
Child:
5:cb4d45f41e17

File content as of revision 4:8d6883cdc3c8:

#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));
    void attach_longpressed(void (*function)(void));
    
private:
    void isr_pressed(void);
    void isr_released(void);
    void click_timeout( void );
    void debounce_timeout( void );
    void longpress_timeout( void );

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