Skip to content

Commit

Permalink
fix for TFT_eSPI_Button compatibility mode #139
Browse files Browse the repository at this point in the history
 fix for TFT_eSPI_Button compatibility mode
  • Loading branch information
Tinyu-Zhao authored Jul 3, 2024
2 parents 588e69b + 5237715 commit 171ad23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/utility/M5Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,21 +749,27 @@ void TFT_eSPI_Button::drawButton(bool inverted /* = false */,
if (long_name != "") strncpy(_label, oldLabel, 50);
}

bool TFT_eSPI_Button::contains(int16_t x, int16_t y) {
return Button::contains(x, y);
bool TFT_eSPI_Button::isPressed() {
return currstate;
}

bool TFT_eSPI_Button::contains(int16_t _x, int16_t _y) {
return ((_x >= x) && (_x < (x + w)) && (_y >= y) && (_y < (y + h)));
}

void TFT_eSPI_Button::press(bool p) {
if (p)
fingerDown();
else
fingerUp();
laststate = currstate;
currstate = p;
}

bool TFT_eSPI_Button::justPressed() {
return wasPressed();
return (currstate && !laststate);
}

bool TFT_eSPI_Button::justReleased() {
return wasReleased();
}
return (!currstate && laststate);
}
3 changes: 3 additions & 0 deletions src/utility/M5Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,9 @@ class TFT_eSPI_Button : public Button {
bool isPressed();
bool justPressed();
bool justReleased();

private:
bool currstate, laststate;
};

#endif /* _M5BUTTON_H_ */

0 comments on commit 171ad23

Please sign in to comment.