WLED/wled00/um_manager.cpp

62 lines
2.7 KiB
C++
Raw Permalink Normal View History

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(); }
2021-10-17 17:14:55 +02:00
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;
}
2022-06-08 21:14:01 +02:00
bool UsermodManager::getUMData(um_data_t **data, uint8_t mod_id) {
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); }
2021-06-25 01:26:15 +02:00
bool UsermodManager::readFromConfig(JsonObject& obj) {
bool allComplete = true;
for (byte i = 0; i < numMods; i++) {
if (!ums[i]->readFromConfig(obj)) allComplete = false;
}
return allComplete;
}
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;
}
void UsermodManager::onUpdateBegin(bool init) { for (byte i = 0; i < numMods; i++) ums[i]->onUpdateBegin(init); } // notify usermods that update is to begin
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;
Fix Warnings (#1744) * Remove -w (Suppress all warnings, including those which GNU CPP issues by default.) and add back in -Wall (Turn on all optional warnings which are desirable for normal code.) from build_flags * Fixes warning: suggest parentheses around '+' in operand of '&' [-Wparentheses] * Fixes warning: "CONFIG_LITTLEFS_FOR_IDF_3_2" redefined * Fixes warning: format '%x' expects argument of type 'unsigned int', but argument 3 has type 'uint64_t {aka long long unsigned int}' [-Wformat=] * Fixes warning: enumeration value 'onoff' not handled in switch [-Wswitch] * Fixes warning: "ntohl" redefined, warning: "ntohs" redefined, warning: "htonl" redefined, warning: "htons" redefined - Original fix: https://github.com/blynkkk/blynk-library/commit/858f8f4ee93246c2550e3f61857681dc87ac43eb * Fixes warning: unused variable 'mainSeg' [-Wunused-variable] * Fixes warning: unused variable 'start' [-Wunused-variable] * (untested!) Fixes warning: operation on '...' may be undefined [-Wsequence-point] * Fixes warning: unused variable * Fixes warning: unused variable and warning: narrowing conversion * Fixes warning: unused variable * Fixes warning: unused variable * (untested!) Fixes warning: statement has no effect [-Wunused-value] * Fixes warning: control reaches end of non-void function * Fixes warning: unused variable * Fixes warning: left operand of comma operator has no effect * Fixes warning: no return statement in function returning non-void * (untested!) Fixes warning: ISO C++ forbids converting a string constant to 'char*' and fixes warning: unused variable 'nPins' * Fixes warning: deleting array 'dmxData' * Fixes warning: unused variable * Remove all warning suppression buildflags Co-authored-by: Louis Beaudoin <louis@embedded-creations.com> Co-authored-by: Aircoookie <dev.aircoookie@gmail.com>
2021-02-27 00:20:31 +01:00
return true;
2020-05-28 02:20:02 +02:00
}