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 committed Jul 3, 2024
1 parent 588e69b commit 8493f21
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/M5Core2.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class M5Core2 {

void begin(bool LCDEnable = true, bool SDEnable = true,
bool SerialEnable = true, bool I2CEnable = false,
mbus_mode_t mode = kMBusModeOutput, bool SpeakerEnable = true);
mbus_mode_t mode = kMBusModeOutput, bool SpeakerEnable = false);
void update();

void shutdown();
Expand Down
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 8493f21

Please sign in to comment.