class of Buttons -isPressed -wasPressed -notPressed -LongPress (Timer)

Committer:
x1dmoesc
Date:
Tue Dec 04 10:40:33 2018 +0000
Revision:
1:e9d0d9b29acc
Parent:
0:8625b4741933
Child:
2:cf58f3863c07
add timer and bWasPressed;

Who changed what in which revision?

UserRevisionLine numberNew 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 0:8625b4741933 10 class button
x1dmoesc 0:8625b4741933 11 {
x1dmoesc 0:8625b4741933 12
x1dmoesc 0:8625b4741933 13 public: // public
x1dmoesc 1:e9d0d9b29acc 14 button(PinName pBtn, PinMode pBtnMode, float Time = 0); // constructor
x1dmoesc 0:8625b4741933 15 void init(); // initialisation
x1dmoesc 0:8625b4741933 16 void polling(); // 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