Skip to content

Commit

Permalink
Minor revisions to Button.h
Browse files Browse the repository at this point in the history
Removed property pin.  Rather, added new int pinValue() method to get pin value.  Made holdThreshold and doubleclickThreshold properties public. New isDoubleClicked method and Callback doubleclickHander.
  • Loading branch information
rmorenojr committed Sep 16, 2018
1 parent 27b6c1e commit 3093ae8
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
|| | This is a Hardware Abstraction Library for Buttons
|| | It providea an easy way of handling buttons
|| |
|| | Added doubl-click method by Ricardo Moreno https://github.com/rmorenojr/Button
|| #
||
|| @revisions
|| | 09_14_2008 v1.1 Added double-click callback method
|| | by Ricardo Moreno https://github.com/rmorenojr/Button
|| #
||
|| @license LICENSE_REPLACE
Expand All @@ -33,42 +37,47 @@ class Button {

Button(uint8_t buttonPin, uint8_t buttonMode=BUTTON_PULLUP_INTERNAL, bool _debounceMode=true, int _debounceDuration=20);

uint8_t pin;

//Public variables
unsigned int holdEventThreshold; //uint16_t
unsigned int doubleclickThreshold;

//Public methods
void pullup(uint8_t buttonMode);
void pulldown();
void process();

bool isPressed(bool proc=true);
bool isDoubleClicked(bool proc=true);
bool wasPressed(bool proc=true);
bool stateChanged(bool proc=true);
bool uniquePress();

void setHoldThreshold(unsigned int holdTime);
void setdoubleclickThreshold(unsigned int doublclickTime); //The time in ms when first click starts and second click ends
bool held(unsigned int time=0);
bool heldFor(unsigned int time);

void pressHandler(buttonEventHandler handler);
void releaseHandler(buttonEventHandler handler);
void clickHandler(buttonEventHandler handler);
void doubleclickHandler(buttonEventHandler handler, unsigned int doublclickTime=600);
void doubleclickHandler(buttonEventHandler handler, unsigned int doublclickTime=900);
void holdHandler(buttonEventHandler handler, unsigned int holdTime=0);

unsigned int holdTime() const;
inline unsigned int presses() const { return numberOfPresses; }
inline unsigned int pinValue() const { return pin; }

bool operator==(Button &rhs);

private:
uint8_t pin;
uint8_t mode;
uint8_t state;
bool debounceMode;
bool doubleclickFound;
unsigned long pressedStartTime;
unsigned long previouspressedStartTime;
unsigned long releasedTime;
unsigned int holdEventThreshold;
unsigned int doubleclickThreshhold;
unsigned long debounceStartTime;
int debounceDuration;
buttonEventHandler cb_onPress;
Expand Down

0 comments on commit 3093ae8

Please sign in to comment.