class of Buttons -isPressed -wasPressed -notPressed -LongPress (Timer)
Diff: button.cpp
- Revision:
- 2:cf58f3863c07
- Parent:
- 1:e9d0d9b29acc
- Child:
- 3:68f58a34e627
diff -r e9d0d9b29acc -r cf58f3863c07 button.cpp --- a/button.cpp Tue Dec 04 10:40:33 2018 +0000 +++ b/button.cpp Thu Dec 13 12:48:21 2018 +0000 @@ -47,14 +47,15 @@ // - 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 /******************************************************************************/ -void button::polling() +void button::polling(int *iNumBtn) { bOldState = bNewState; // bNewState gets the becomes the bOldstate bNewState = (bool)pin->read(); // update bNewState bWasPressed = false; // reset the flag was pressed - + if(!bBtnNewAction and (bOldState != bNewState)) // if there is a action (changing signal) on the button (btn), then rise the flag bBtnNewAction bBtnNewAction = true; @@ -73,6 +74,9 @@ if(bNewState == PRESSED) { // btn is pressed, then bIsPressed = true; // set this flag true + if(iNumBtn != NULL) + (*iNumBtn)++; + if(fTime > 0) // if btn has a timer, timer->attach(this, &button::setLongPressFlag, fTime); @@ -86,6 +90,9 @@ if(fTime > 0) // if btn has a timer, timer->detach(); bLongPress = false; + + if((iNumBtn != NULL && *iNumBtn) > 0) + (*iNumBtn)--; } }