Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for TFT_eSPI_Button compatibility mode #139

Merged
merged 4 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_ */
Loading