class of Buttons -isPressed -wasPressed -notPressed -LongPress (Timer)
Button.h@8:6c8a00baae91, 2020-04-17 (annotated)
- Committer:
- x1dmoesc
- Date:
- Fri Apr 17 14:05:36 2020 +0000
- Revision:
- 8:6c8a00baae91
- Parent:
- 5:6eefa28ac3fd
add new coments and debug the condition of: if(iNumBtn != NULL && *iNumBtn > 0)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
x1dmoesc | 0:8625b4741933 | 1 | #ifndef MBED_BUTTON_H |
x1dmoesc | 0:8625b4741933 | 2 | #define MBED_BUTTON_H |
x1dmoesc | 0:8625b4741933 | 3 | |
x1dmoesc | 0:8625b4741933 | 4 | #include "mbed.h" |
x1dmoesc | 0:8625b4741933 | 5 | |
x1dmoesc | 0:8625b4741933 | 6 | #define NUMCYCLE 10 |
x1dmoesc | 0:8625b4741933 | 7 | #define PRESSED 0 |
x1dmoesc | 0:8625b4741933 | 8 | #define NOT_PRESSED 1 |
x1dmoesc | 0:8625b4741933 | 9 | |
x1dmoesc | 4:3b94400f2894 | 10 | class Button |
x1dmoesc | 0:8625b4741933 | 11 | { |
x1dmoesc | 0:8625b4741933 | 12 | |
x1dmoesc | 0:8625b4741933 | 13 | public: // public |
x1dmoesc | 4:3b94400f2894 | 14 | Button(PinName pBtn, PinMode pBtnMode, float Time = 0); // constructor |
x1dmoesc | 0:8625b4741933 | 15 | void init(); // initialisation |
x1dmoesc | 8:6c8a00baae91 | 16 | void polling(uint8_t *iNumBtn = NULL); // polls and debounce the button |
x1dmoesc | 1:e9d0d9b29acc | 17 | bool isPressed(); // bool value if button is pressed or not |
x1dmoesc | 0:8625b4741933 | 18 | bool wasPressed(); // |
x1dmoesc | 1:e9d0d9b29acc | 19 | bool isLongPress(); |
x1dmoesc | 0:8625b4741933 | 20 | |
x1dmoesc | 0:8625b4741933 | 21 | |
x1dmoesc | 0:8625b4741933 | 22 | private: // private |
x1dmoesc | 1:e9d0d9b29acc | 23 | bool bIsPressed; // current pressing state |
x1dmoesc | 1:e9d0d9b29acc | 24 | bool bWasPressed; // last pressenig state |
x1dmoesc | 1:e9d0d9b29acc | 25 | bool bLongPress; // if current pressing state is an long press |
x1dmoesc | 0:8625b4741933 | 26 | bool bNewState; // current state/value of button |
x1dmoesc | 0:8625b4741933 | 27 | bool bOldState; // previous state/value of button |
x1dmoesc | 0:8625b4741933 | 28 | bool bBtnNewAction; // flag if an action is occur |
x1dmoesc | 0:8625b4741933 | 29 | int iNumCycle; // cycle counter |
x1dmoesc | 1:e9d0d9b29acc | 30 | float fTime; // if constructor creates an timer, this flag is set high |
x1dmoesc | 0:8625b4741933 | 31 | |
x1dmoesc | 1:e9d0d9b29acc | 32 | |
x1dmoesc | 1:e9d0d9b29acc | 33 | void setLongPressFlag(); |
x1dmoesc | 1:e9d0d9b29acc | 34 | |
x1dmoesc | 1:e9d0d9b29acc | 35 | DigitalIn *pin; // Input pin for Button |
x1dmoesc | 1:e9d0d9b29acc | 36 | Timeout *timer; // Timer, to set a Flag for secound Mode |
x1dmoesc | 0:8625b4741933 | 37 | |
x1dmoesc | 0:8625b4741933 | 38 | }; |
x1dmoesc | 0:8625b4741933 | 39 | |
x1dmoesc | 0:8625b4741933 | 40 | |
x1dmoesc | 0:8625b4741933 | 41 | #endif |