class of Buttons -isPressed -wasPressed -notPressed -LongPress (Timer)
Revision 8:6c8a00baae91, committed 2020-04-17
- Comitter:
- x1dmoesc
- Date:
- Fri Apr 17 14:05:36 2020 +0000
- Parent:
- 7:09fb38cf8526
- Commit message:
- add new coments and debug the condition of: if(iNumBtn != NULL && *iNumBtn > 0)
Changed in this revision
Button.cpp | Show annotated file Show diff for this revision Revisions of this file |
Button.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 09fb38cf8526 -r 6c8a00baae91 Button.cpp --- a/Button.cpp Tue Jun 04 14:19:35 2019 +0000 +++ b/Button.cpp Fri Apr 17 14:05:36 2020 +0000 @@ -3,7 +3,11 @@ /******************************************************************************/ -// constructor +// constructor of instance button +// - PinName: Name of pin of MBed LPC1768 (e.g. p9, p10,...) +// - PinMode: PullUp, PullDown, PullNone, OpenDrain +// - time: defines the time after the longPress-Flag is set. +// /******************************************************************************/ Button::Button(PinName pBtn, PinMode pBtnMode, float time) { @@ -20,14 +24,22 @@ /******************************************************************************/ // initialisation +// - bNewState: current state of button +// - bOldState: previous state of button +// - bIsPressed: flag is set if button is pressed +// - bLongPresed: flag is set, after timer is zero (bIsPressed = true) +// - bWasPressed: after button is not pressed anymore +// /******************************************************************************/ void Button::init() { + bNewState = false; + bOldState = false; + bIsPressed = false; bLongPress = false; bWasPressed = false; - bNewState = false; - bOldState = false; + bBtnNewAction = false; @@ -47,7 +59,8 @@ // - bBtnNewAction: flag, if an action is occur // - iNumCycle: cycle counter of same state // - NUNCYCLES: max. value of cycle counter -// - *iNumBtn: pointer of variable, which counts pressed buttons +// - *iNumBtn: pointer to variable, which counts the number of pressed buttons +// /******************************************************************************/ void Button::polling(uint8_t *iNumBtn) { @@ -90,8 +103,8 @@ timer->detach(); bLongPress = false; - if((iNumBtn != NULL && *iNumBtn) > 0) - (*iNumBtn)--; + if(iNumBtn != NULL && *iNumBtn > 0) // if there is a pointer to a counter-Variable and the value is greater than 0 + (*iNumBtn)--; // decrease iNumBtn by one } } @@ -104,7 +117,6 @@ } - /******************************************************************************/ // /******************************************************************************/
diff -r 09fb38cf8526 -r 6c8a00baae91 Button.h --- a/Button.h Tue Jun 04 14:19:35 2019 +0000 +++ b/Button.h Fri Apr 17 14:05:36 2020 +0000 @@ -13,7 +13,7 @@ public: // public Button(PinName pBtn, PinMode pBtnMode, float Time = 0); // constructor void init(); // initialisation - void polling(uint8_t *iNumBtn = NULL); // polls and debounce the button + void polling(uint8_t *iNumBtn = NULL); // polls and debounce the button bool isPressed(); // bool value if button is pressed or not bool wasPressed(); // bool isLongPress();