Skip to content

Commit 8493f21

Browse files
committed
fix for TFT_eSPI_Button compatibility mode #139
fix for TFT_eSPI_Button compatibility mode
1 parent 588e69b commit 8493f21

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/M5Core2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class M5Core2 {
2626

2727
void begin(bool LCDEnable = true, bool SDEnable = true,
2828
bool SerialEnable = true, bool I2CEnable = false,
29-
mbus_mode_t mode = kMBusModeOutput, bool SpeakerEnable = true);
29+
mbus_mode_t mode = kMBusModeOutput, bool SpeakerEnable = false);
3030
void update();
3131

3232
void shutdown();

src/utility/M5Button.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -749,21 +749,27 @@ void TFT_eSPI_Button::drawButton(bool inverted /* = false */,
749749
if (long_name != "") strncpy(_label, oldLabel, 50);
750750
}
751751

752-
bool TFT_eSPI_Button::contains(int16_t x, int16_t y) {
753-
return Button::contains(x, y);
752+
bool TFT_eSPI_Button::isPressed() {
753+
return currstate;
754+
}
755+
756+
bool TFT_eSPI_Button::contains(int16_t _x, int16_t _y) {
757+
return ((_x >= x) && (_x < (x + w)) && (_y >= y) && (_y < (y + h)));
754758
}
755759

756760
void TFT_eSPI_Button::press(bool p) {
757761
if (p)
758762
fingerDown();
759763
else
760764
fingerUp();
765+
laststate = currstate;
766+
currstate = p;
761767
}
762768

763769
bool TFT_eSPI_Button::justPressed() {
764-
return wasPressed();
770+
return (currstate && !laststate);
765771
}
766772

767773
bool TFT_eSPI_Button::justReleased() {
768-
return wasReleased();
769-
}
774+
return (!currstate && laststate);
775+
}

src/utility/M5Button.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,9 @@ class TFT_eSPI_Button : public Button {
981981
bool isPressed();
982982
bool justPressed();
983983
bool justReleased();
984+
985+
private:
986+
bool currstate, laststate;
984987
};
985988

986989
#endif /* _M5BUTTON_H_ */

0 commit comments

Comments
 (0)