diff --git a/src/utility/M5Button.cpp b/src/utility/M5Button.cpp index 176985d..afe4e95 100644 --- a/src/utility/M5Button.cpp +++ b/src/utility/M5Button.cpp @@ -749,8 +749,12 @@ 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) { @@ -758,12 +762,14 @@ void TFT_eSPI_Button::press(bool 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); +} \ No newline at end of file diff --git a/src/utility/M5Button.h b/src/utility/M5Button.h index a67196f..48f258f 100644 --- a/src/utility/M5Button.h +++ b/src/utility/M5Button.h @@ -981,6 +981,9 @@ class TFT_eSPI_Button : public Button { bool isPressed(); bool justPressed(); bool justReleased(); + + private: + bool currstate, laststate; }; #endif /* _M5BUTTON_H_ */