Skip to content

Commit

Permalink
Revert "Reuse state attribute for pressed state"
Browse files Browse the repository at this point in the history
This reverts commit 9babb4f.
  • Loading branch information
jamesmyatt committed Aug 26, 2020
1 parent 9babb4f commit 83bc18e
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/Bounce2.h
Expand Up @@ -67,7 +67,7 @@ class Debouncer
static const uint8_t UNSTABLE_STATE = 0b00000010;
static const uint8_t CHANGED_STATE = 0b00000100;

protected:
private:
inline void changeState();
inline void setStateFlag(const uint8_t flag) {state |= flag;}
inline void unsetStateFlag(const uint8_t flag) {state &= ~flag;}
Expand Down Expand Up @@ -241,9 +241,8 @@ class Bounce : public Debouncer
@brief The Debouncer:Bounce:Button class. The Button class matches an electrical state to a physical action.
*/
class Button : public Bounce{
private:
// Note : this is private as it might change in the future
static const uint8_t PRESSED_STATE = 0b00001000;
protected:
bool stateForPressed = 1; //
public:
/*!
@brief Create an instance of the Button class. By default, the pressed state is matched to a HIGH electrical level.
Expand All @@ -255,10 +254,7 @@ class Button : public Bounce{
@endcode
*/
Button(){
// Default to pressed state is HIGH
setStateFlag(PRESSED_STATE);
}
Button(){ }

/*!
@brief Set the electrical state (HIGH/LOW) that corresponds to a physical press. By default, the pressed state is matched to a HIGH electrical level.
Expand All @@ -268,17 +264,14 @@ class Button : public Bounce{
*/
void setPressedState(bool state){
if (state)
setStateFlag(PRESSED_STATE);
else
unsetStateFlag(PRESSED_STATE);
stateForPressed = state;
}

/*!
@brief Get the electrical state (HIGH/LOW) that corresponds to a physical press.
*/
inline bool getPressedState() {
return getStateFlag(PRESSED_STATE);
return stateForPressed;
};

/*!
Expand Down

0 comments on commit 83bc18e

Please sign in to comment.