WLED/wled00/um_manager.cpp

63 wiersze
2.9 KiB
C++
Czysty Zwykły widok Historia

2020-05-28 00:20:02 +00:00
#include "wled.h"
/*
* Registration and management utility for v2 usermods
*/
//Usermod Manager internals
2022-06-11 16:55:23 +00: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 03:23:32 +00: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 16:55:23 +00:00
void UsermodManager::appendConfigData() { for (byte i = 0; i < numMods; i++) ums[i]->appendConfigData(); }
2023-01-06 08:24:29 +00:00
bool UsermodManager::handleButton(uint8_t b) {
2021-10-17 15:14:55 +00:00
bool overrideIO = false;
for (byte i = 0; i < numMods; i++) {
if (ums[i]->handleButton(b)) overrideIO = true;
}
return overrideIO;
}
2023-01-06 08:24:29 +00:00
bool UsermodManager::getUMData(um_data_t **data, uint8_t mod_id) {
2022-06-08 19:14:01 +00: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 00:20:02 +00: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 14:50:15 +00:00
void UsermodManager::addToConfig(JsonObject& obj) { for (byte i = 0; i < numMods; i++) ums[i]->addToConfig(obj); }
2023-01-06 08:24:29 +00:00
bool UsermodManager::readFromConfig(JsonObject& obj) {
2021-06-24 23:26:15 +00:00
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
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 00:20:02 +00:00
2021-02-09 16:15:43 +00: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 00:20:02 +00:00
bool UsermodManager::add(Usermod* um)
{
if (numMods >= WLED_MAX_USERMODS || um == nullptr) return false;
2022-06-08 19:14:01 +00: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-26 23:20:31 +00:00
return true;
2020-05-28 00:20:02 +00:00
}