Skip to content

Commit

Permalink
Merge branch 'small-fft' of github.com:netmindz/WLED into small-fft
Browse files Browse the repository at this point in the history
  • Loading branch information
netmindz committed Sep 22, 2024
2 parents dd4cf26 + 7dcd9ca commit f98c13b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 22 deletions.
5 changes: 5 additions & 0 deletions usermods/audioreactive/audio_reactive.h
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,11 @@ class AudioReactive : public Usermod {
#endif
}

#if defined(_MoonModules_WLED_) && defined(WLEDMM_FASTPATH)
void loop2(void) {
loop();
}
#endif

bool getUMData(um_data_t **data)
{
Expand Down
4 changes: 2 additions & 2 deletions wled00/bus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void BusDigital::show() {
PolyBus::show(_busPtr, _iType);
}

bool BusDigital::canShow() const {
bool BusDigital::canShow() {
return PolyBus::canShow(_busPtr, _iType);
}

Expand Down Expand Up @@ -885,7 +885,7 @@ uint32_t BusHub75Matrix::getPixelColor(uint16_t pix) const {

void BusHub75Matrix::setBrightness(uint8_t b, bool immediate) {
_bri = b;
if (_bri > 238) _bri=238;
// if (_bri > 238) _bri=238; // not strictly needed. Enable this line if you see glitches at highest brightness.
display->setBrightness(_bri);
}

Expand Down
4 changes: 3 additions & 1 deletion wled00/fcn_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ class Usermod {
virtual ~Usermod() { if (um_data) delete um_data; }
virtual void setup() = 0; // pure virtual, has to be overriden
virtual void loop() = 0; // pure virtual, has to be overriden
virtual void loop2() {} // WLEDMM called just before effects will be processed
virtual void handleOverlayDraw() {} // called after all effects have been processed, just before strip.show()
virtual bool handleButton(uint8_t b) { return false; } // button overrides are possible here
virtual bool getUMData(um_data_t **data) { if (data) *data = nullptr; return false; }; // usermod data exchange [see examples for audio effects]
Expand All @@ -325,10 +326,11 @@ class Usermod {
class UsermodManager {
private:
Usermod* ums[WLED_MAX_USERMODS];
byte numMods = 0;
unsigned numMods = 0;

public:
void loop();
void loop2(); // WLEDMM loop just before drawing effects (presets and everything already handled)
void handleOverlayDraw();
bool handleButton(uint8_t b);
bool getUMData(um_data_t **um_data, uint8_t mod_id = USERMOD_ID_RESERVED); // USERMOD_ID_RESERVED will poll all usermods
Expand Down
37 changes: 19 additions & 18 deletions wled00/um_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,50 @@
*/

//Usermod Manager internals
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(); }
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(); }
// void UsermodManager::appendConfigData() { for (byte i = 0; i < numMods; i++) ums[i]->appendConfigData(); } //WLEDMM not used
void UsermodManager::setup() { for (unsigned i = 0; i < numMods; i++) ums[i]->setup(); }
void UsermodManager::connected() { for (unsigned i = 0; i < numMods; i++) ums[i]->connected(); }
void UsermodManager::loop() { for (unsigned i = 0; i < numMods; i++) ums[i]->loop(); }
void UsermodManager::loop2() { for (unsigned i = 0; i < numMods; i++) ums[i]->loop2(); }
void UsermodManager::handleOverlayDraw() { for (unsigned i = 0; i < numMods; i++) ums[i]->handleOverlayDraw(); }
// void UsermodManager::appendConfigData() { for (unsigned i = 0; i < numMods; i++) ums[i]->appendConfigData(); } //WLEDMM not used
bool UsermodManager::handleButton(uint8_t b) {
bool overrideIO = false;
for (byte i = 0; i < numMods; i++) {
for (unsigned i = 0; i < numMods; i++) {
if (ums[i]->handleButton(b)) overrideIO = true;
}
return overrideIO;
}
bool UsermodManager::getUMData(um_data_t **data, uint8_t mod_id) {
for (byte i = 0; i < numMods; i++) {
for (unsigned 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 provide data at one time)
}
return false;
}
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); }
void UsermodManager::addToConfig(JsonObject& obj) { for (byte i = 0; i < numMods; i++) ums[i]->addToConfig(obj); }
void UsermodManager::addToJsonState(JsonObject& obj) { for (unsigned i = 0; i < numMods; i++) ums[i]->addToJsonState(obj); }
void UsermodManager::addToJsonInfo(JsonObject& obj) { for (unsigned i = 0; i < numMods; i++) ums[i]->addToJsonInfo(obj); }
void UsermodManager::readFromJsonState(JsonObject& obj) { for (unsigned i = 0; i < numMods; i++) ums[i]->readFromJsonState(obj); }
void UsermodManager::addToConfig(JsonObject& obj) { for (unsigned i = 0; i < numMods; i++) ums[i]->addToConfig(obj); }
bool UsermodManager::readFromConfig(JsonObject& obj) {
bool allComplete = true;
for (byte i = 0; i < numMods; i++) {
for (unsigned 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); }
void UsermodManager::onMqttConnect(bool sessionPresent) { for (unsigned 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;
for (unsigned 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
void UsermodManager::onUpdateBegin(bool init) { for (unsigned i = 0; i < numMods; i++) ums[i]->onUpdateBegin(init); } // notify usermods that update is to begin
void UsermodManager::onStateChange(uint8_t mode) { for (unsigned i = 0; i < numMods; i++) ums[i]->onStateChange(mode); } // notify usermods that WLED state changed

/*
* Enables usermods to lookup another Usermod.
*/
Usermod* UsermodManager::lookup(uint16_t mod_id) {
for (byte i = 0; i < numMods; i++) {
for (unsigned i = 0; i < numMods; i++) {
if (ums[i]->getId() == mod_id) {
return ums[i];
}
Expand All @@ -57,7 +58,7 @@ Usermod* UsermodManager::lookup(uint16_t mod_id) {
//WLEDMM: used by Usermods in xml.cpp
Usermod* UsermodManager::lookupName(const char *mod_name) {
//WLEDMM: hack to get the usermod object with the mod_name (better would be to store the usermod name in the class but that requires change to all usermods)
for (byte i = 0; i < numMods; i++) {
for (unsigned i = 0; i < numMods; i++) {
// StaticJsonDocument <1024> docx;
JsonObject um = doc.createNestedObject("um"); //WLEDMM reuse the global doc variable here

Expand Down
13 changes: 13 additions & 0 deletions wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,19 @@ void WLED::loop()
handlePresets();
yield();

#if defined(_MoonModules_WLED_) && defined(WLEDMM_FASTPATH)
#ifdef WLED_DEBUG
unsigned long usermod2Millis = millis();
#endif
usermods.loop2();
#ifdef WLED_DEBUG
usermod2Millis = millis() - usermod2Millis;
avgUsermodMillis += usermod2Millis;
if (usermod2Millis > maxUsermodMillis) maxUsermodMillis = usermod2Millis;
#endif
yield();
#endif

#ifdef WLED_DEBUG
unsigned long stripMillis = millis();
#endif
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

// version code in format yymmddb (b = daily build)
#define VERSION 2409060
#define VERSION 2409210

// WLEDMM - you can check for this define in usermods, to only enabled WLEDMM specific code in the "right" fork. Its not defined in AC WLED.
#define _MoonModules_WLED_
Expand Down

0 comments on commit f98c13b

Please sign in to comment.