tcMenu
TcOneButtonHandler.h
1 #ifndef TCLIBRARYDEV_TCONEBUTTONHANDLER_H
2 #define TCLIBRARYDEV_TCONEBUTTONHANDLER_H
3 
4 #include <PlatformDetermination.h>
5 #include <SwitchInput.h>
6 #include <tcMenu.h>
7 
15 class TcOneButtonHandler : public SwitchListener {
16 private:
17  uint32_t lastPress;
18  int doubleClickThreshold;
19  pinid_t buttonPin;
20 public:
21  TcOneButtonHandler(pinid_t buttonPin, int doubleClickThreshold)
22  : lastPress(0), buttonPin(buttonPin), doubleClickThreshold(doubleClickThreshold) {
23  }
24 
25  void start() {
26  switches.addSwitchListener(buttonPin, this, NO_REPEAT, false);
27  }
28 
29  void onPressed(pinid_t pin, bool held) override {
30  }
31 
32  void onReleased(pinid_t pin, bool held) override {
33  if(held && pin == buttonPin) {
34  menuMgr.onMenuSelect(false);
35  lastPress = 0;
36  } else {
37  if((millis() - lastPress) < doubleClickThreshold) {
39  lastPress = 0;
40  } else {
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  }
48  lastPress = millis();
49  }
50  }
51  }
52 };
53 
54 #endif //TCLIBRARYDEV_TCONEBUTTONHANDLER_H
void performDirectionMove(bool dirIsBack)
Definition: tcMenu.cpp:106
void onMenuSelect(bool held)
Definition: tcMenu.cpp:201
Definition: TcOneButtonHandler.h:15
The menu manager is responsible for managing a set of menu items, and is configured with a renderer a...
MenuManager menuMgr
Definition: tcMenu.cpp:16