Button handling hook for usermods.

This commit is contained in:
Blaz Kristan 2021-10-17 17:14:55 +02:00
parent 61eff6e7e8
commit 4e2bbc04fa
3 changed files with 11 additions and 1 deletions

View File

@ -214,6 +214,8 @@ void handleButton()
if (btnPin[b]<0 || buttonType[b] == BTN_TYPE_NONE) continue;
#endif
if (usermods.handleButton(b)) continue; // did usermod handle buttons
if ((buttonType[b] == BTN_TYPE_ANALOG || buttonType[b] == BTN_TYPE_ANALOG_INVERTED) && millis() - lastRead > 250) { // button is not a button but a potentiometer
if (b+1 == WLED_MAX_BUTTONS) lastRead = millis();
handleAnalog(b); continue;

View File

@ -218,6 +218,7 @@ class Usermod {
public:
virtual void loop() {}
virtual void handleOverlayDraw() {}
virtual bool handleButton(uint8_t b) { return false; }
virtual void setup() {}
virtual void connected() {}
virtual void addToJsonState(JsonObject& obj) {}
@ -238,7 +239,7 @@ class UsermodManager {
public:
void loop();
void handleOverlayDraw();
bool handleButton(uint8_t b);
void setup();
void connected();
void addToJsonState(JsonObject& obj);

View File

@ -6,6 +6,13 @@
//Usermod Manager internals
void UsermodManager::loop() { for (byte i = 0; i < numMods; i++) ums[i]->loop(); }
void UsermodManager::handleOverlayDraw() { for (byte i = 0; i < numMods; i++) ums[i]->handleOverlayDraw(); }
bool UsermodManager::handleButton(uint8_t b) {
bool overrideIO = false;
for (byte i = 0; i < numMods; i++) {
if (ums[i]->handleButton(b)) overrideIO = true;
}
return overrideIO;
}
void UsermodManager::setup() { for (byte i = 0; i < numMods; i++) ums[i]->setup(); }
void UsermodManager::connected() { for (byte i = 0; i < numMods; i++) ums[i]->connected(); }