2020-05-28 02:20:02 +02:00
|
|
|
#include "wled.h"
|
|
|
|
/*
|
|
|
|
* Registration and management utility for v2 usermods
|
|
|
|
*/
|
|
|
|
|
|
|
|
//Usermod Manager internals
|
2022-06-11 18:55:23 +02:00
|
|
|
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(); }
|
2021-09-30 05:23:32 +02:00
|
|
|
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(); }
|
2022-06-11 18:55:23 +02:00
|
|
|
void UsermodManager::appendConfigData() { for (byte i = 0; i < numMods; i++) ums[i]->appendConfigData(); }
|
2023-01-06 09:24:29 +01:00
|
|
|
bool UsermodManager::handleButton(uint8_t b) {
|
2021-10-17 17:14:55 +02:00
|
|
|
bool overrideIO = false;
|
|
|
|
for (byte i = 0; i < numMods; i++) {
|
|
|
|
if (ums[i]->handleButton(b)) overrideIO = true;
|
|
|
|
}
|
|
|
|
return overrideIO;
|
|
|
|
}
|
2023-01-06 09:24:29 +01:00
|
|
|
bool UsermodManager::getUMData(um_data_t **data, uint8_t mod_id) {
|
2022-06-08 21:14:01 +02:00
|
|
|
for (byte i = 0; i < numMods; i++) {
|
|
|
|
if (mod_id > 0 && ums[i]->getId() != mod_id) continue; // only get data form requested usermod if provided
|
|
|
|
if (ums[i]->getUMData(data)) return true; // if usermod does provide data return immediately (only one usermod can povide data at one time)
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-28 02:20:02 +02:00
|
|
|
void UsermodManager::addToJsonState(JsonObject& obj) { for (byte i = 0; i < numMods; i++) ums[i]->addToJsonState(obj); }
|
|
|
|
void UsermodManager::addToJsonInfo(JsonObject& obj) { for (byte i = 0; i < numMods; i++) ums[i]->addToJsonInfo(obj); }
|
|
|
|
void UsermodManager::readFromJsonState(JsonObject& obj) { for (byte i = 0; i < numMods; i++) ums[i]->readFromJsonState(obj); }
|
2020-11-11 15:50:15 +01:00
|
|
|
void UsermodManager::addToConfig(JsonObject& obj) { for (byte i = 0; i < numMods; i++) ums[i]->addToConfig(obj); }
|
2023-01-06 09:24:29 +01:00
|
|
|
bool UsermodManager::readFromConfig(JsonObject& obj) {
|
2021-06-25 01:26:15 +02:00
|
|
|
bool allComplete = true;
|
|
|
|
for (byte i = 0; i < numMods; i++) {
|
|
|
|
if (!ums[i]->readFromConfig(obj)) allComplete = false;
|
|
|
|
}
|
|
|
|
return allComplete;
|
|
|
|
}
|
2021-05-07 12:41:39 +02:00
|
|
|
void UsermodManager::onMqttConnect(bool sessionPresent) { for (byte i = 0; i < numMods; i++) ums[i]->onMqttConnect(sessionPresent); }
|
|
|
|
bool UsermodManager::onMqttMessage(char* topic, char* payload) {
|
|
|
|
for (byte i = 0; i < numMods; i++) if (ums[i]->onMqttMessage(topic, payload)) return true;
|
|
|
|
return false;
|
|
|
|
}
|
2022-06-11 00:50:29 +02:00
|
|
|
void UsermodManager::onUpdateBegin(bool init) { for (byte i = 0; i < numMods; i++) ums[i]->onUpdateBegin(init); } // notify usermods that update is to begin
|
2023-02-05 12:23:05 +01:00
|
|
|
void UsermodManager::onStateChange(uint8_t mode) { for (byte i = 0; i < numMods; i++) ums[i]->onStateChange(mode); } // notify usermods that WLED state changed
|
2020-05-28 02:20:02 +02:00
|
|
|
|
2021-02-09 17:15:43 +01:00
|
|
|
/*
|
|
|
|
* Enables usermods to lookup another Usermod.
|
|
|
|
*/
|
|
|
|
Usermod* UsermodManager::lookup(uint16_t mod_id) {
|
|
|
|
for (byte i = 0; i < numMods; i++) {
|
|
|
|
if (ums[i]->getId() == mod_id) {
|
|
|
|
return ums[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-05-28 02:20:02 +02:00
|
|
|
bool UsermodManager::add(Usermod* um)
|
|
|
|
{
|
|
|
|
if (numMods >= WLED_MAX_USERMODS || um == nullptr) return false;
|
2022-06-08 21:14:01 +02:00
|
|
|
ums[numMods++] = um;
|
2021-02-27 00:20:31 +01:00
|
|
|
return true;
|
2020-05-28 02:20:02 +02:00
|
|
|
}
|