Skip to content

Commit 6bc4d84

Browse files
committed
#222 one button support working
1 parent c379ab0 commit 6bc4d84

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/extras/TcOneButtonHandler.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
* Support for a menu with a single button, it will add a button on the required pin, and listen for changes
1010
* With the following:
1111
* Short press: increment by 1
12-
* Double press (when not editing): select item
13-
* Hold down: go back navigation
12+
* Double press (when not editing): back navigation
13+
* Hold down: select
1414
*/
1515
class TcOneButtonHandler : public SwitchListener {
1616
private:
@@ -31,14 +31,20 @@ class TcOneButtonHandler : public SwitchListener {
3131

3232
void onReleased(pinid_t pin, bool held) override {
3333
if(held && pin == buttonPin) {
34-
menuMgr.performDirectionMove(true);
34+
menuMgr.onMenuSelect(false);
3535
lastPress = 0;
3636
} else {
3737
if((millis() - lastPress) < doubleClickThreshold) {
38-
menuMgr.onMenuSelect(held);
38+
menuMgr.performDirectionMove(true);
3939
lastPress = 0;
4040
} else {
41-
switches.getEncoder()->increment(1);
41+
auto enc = switches.getEncoder();
42+
if(enc->getCurrentReading() == enc->getMaximumValue()) {
43+
enc->setCurrentReading(0);
44+
enc->runCallback(enc->getCurrentReading());
45+
} else {
46+
enc->increment(1);
47+
}
4248
lastPress = millis();
4349
}
4450
}

0 commit comments

Comments
 (0)