Skip to content

Commit 17e9af8

Browse files
committed
Bugfixes: remove controls, endsWith, nrOfAssignedPins, meset
Back end ======== - NodeManager: onUpdate: remove controls when new node (revert comment) - Shared endpoints: findModule: path.endsWith - Physical layer: add nrOfAssignedPins, sizeof(ledsPerPin) - Nodes: memcpy and memset sizeof() - Drivers: nrOfPins = min(pins)
1 parent 124d1b9 commit 17e9af8

File tree

16 files changed

+67
-56
lines changed

16 files changed

+67
-56
lines changed

src/MoonBase/Modules/ModuleDevices.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class ModuleDevices : public Module {
128128
deviceUDP.write((uint8_t*)&message, sizeof(message));
129129
deviceUDP.endPacket();
130130

131-
IPAddress activeIP = WiFi.localIP() ? WiFi.localIP() : ETH.localIP();
131+
IPAddress activeIP = WiFi.isConnected() ? WiFi.localIP() : ETH.localIP();
132132
// EXT_LOGD(MB_TAG, "UDP packet written (%s -> %d)", message.name.c_str(), activeIP[3]);
133133
updateDevices(message.name.c_str(), activeIP);
134134
}

src/MoonBase/NodeManager.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class NodeManager : public Module {
3737
void begin() {
3838
Module::begin();
3939
// if (false)
40-
//if file changes, read the file and bring into state
40+
// if file changes, read the file and bring into state
4141
// create a handler which recompiles the live script when the file of a current running live script changes in the File Manager
4242
_fileManager->addUpdateHandler([&](const String& originId) {
4343
EXT_LOGV(ML_TAG, "FileManager::updateHandler %s", originId.c_str());
@@ -148,11 +148,11 @@ class NodeManager : public Module {
148148
if (!updatedItem.value.isNull()) { // if name changed // == updatedItem.value
149149

150150
// // if old node exists then remove it's controls
151-
// if (updatedItem.oldValue != "") {
152-
// // EXT_LOGD(ML_TAG, "remove controls %s[%d]%s[%d].%s = %s -> %s", updatedItem.parent[0].c_str(), updatedItem.index[0], updatedItem.parent[1].c_str(), updatedItem.index[1],
153-
// // updatedItem.name.c_str(), updatedItem.oldValue.c_str(), updatedItem.value.as<String>().c_str());
154-
// nodeState.remove("controls"); // remove the controls from the nodeState
155-
// }
151+
if (updatedItem.oldValue != "") {
152+
// EXT_LOGD(ML_TAG, "remove controls %s[%d]%s[%d].%s = %s -> %s", updatedItem.parent[0].c_str(), updatedItem.index[0], updatedItem.parent[1].c_str(), updatedItem.index[1],
153+
// updatedItem.name.c_str(), updatedItem.oldValue.c_str(), updatedItem.value.as<String>().c_str());
154+
nodeState.remove("controls"); // remove the controls from the nodeState
155+
}
156156

157157
// String xx;
158158
// serializeJson(nodeState["controls"], xx);
@@ -260,7 +260,7 @@ class NodeManager : public Module {
260260
else if (updatedItem.parent[1] == "controls" && updatedItem.name == "value" && updatedItem.index[1] < nodeState["controls"].size()) { // nodes[i].controls[j].value
261261
// serializeJson(nodeState["controls"][updatedItem.index[1]], Serial);
262262
// EXT_LOGD(ML_TAG, "handle control value %s[%d]%s[%d].%s = %s -> %s", updatedItem.parent[0].c_str(), updatedItem.index[0], updatedItem.parent[1].c_str(), updatedItem.index[1], updatedItem.name.c_str(), updatedItem.oldValue.c_str(), updatedItem.value.as<String>().c_str());
263-
263+
264264
if (updatedItem.index[0] < nodes->size()) {
265265
Node* nodeClass = (*nodes)[updatedItem.index[0]];
266266
if (nodeClass != nullptr) {
@@ -301,13 +301,12 @@ class NodeManager : public Module {
301301
requestUIUpdate = false; // reset the flag
302302
// EXT_LOGD(ML_TAG, "requestUIUpdate");
303303

304-
//disable for the time being (locks _accessMutex), need to check if this is needed at all
305304
// update state to UI
306-
// update(
307-
// [&](ModuleState& state) {
308-
// return StateUpdateResult::CHANGED; // notify StatefulService by returning CHANGED
309-
// },
310-
// _moduleName);
305+
update(
306+
[&](ModuleState& state) {
307+
return StateUpdateResult::CHANGED; // notify StatefulService by returning CHANGED
308+
},
309+
_moduleName);
311310
}
312311
}
313312

src/MoonBase/SharedHttpEndpoint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class SharedHttpEndpoint {
8989

9090
Module* findModule(const String& path) {
9191
for (Module* module : modules) {
92-
if (contains(path.c_str(), module->_moduleName.c_str())) return module;
92+
if (path.endsWith(module->_moduleName.c_str())) return module;
9393
}
9494
return nullptr;
9595
}

src/MoonBase/SharedWebSocketServer.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ class SharedWebSocketServer {
7676
});
7777

7878
// ADDED: Better logging in onClose
79-
_handler.onClose([this](PsychicWebSocketClient* client) { ESP_LOGI(SVK_TAG, "ws[%s][%u] disconnect", client->remoteIP().toString().c_str(), client->socket()); });
79+
_handler.onClose([this](PsychicWebSocketClient* client) {
80+
ESP_LOGI(SVK_TAG, "ws[%s][%u] disconnect", client->remoteIP().toString().c_str(), client->socket());
81+
_initializedSockets.erase(client->socket());
82+
});
8083

8184
_server->on("/ws/*", &_handler);
8285
}
@@ -114,7 +117,7 @@ class SharedWebSocketServer {
114117

115118
Module* findModule(const String& path) {
116119
for (Module* module : modules) {
117-
if (contains(path.c_str(), module->_moduleName.c_str())) return module;
120+
if (path.endsWith(module->_moduleName.c_str())) return module;
118121
}
119122
return nullptr;
120123
}

src/MoonBase/Utilities.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,8 @@ void freeMBObject(T* obj) {
384384
#if USE_M5UNIFIED
385385
extern unsigned char moonmanpng[];
386386
extern unsigned int moonmanpng_len;
387-
#endif
387+
#endif
388+
389+
static inline uint32_t fastDiv255(uint32_t x) { //3–4 cycles
390+
return (x * 0x8081u) >> 23;
391+
}

src/MoonLight/Layers/PhysicalLayer.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void PhysicalLayer::loop20ms() {
7575
}
7676

7777
void PhysicalLayer::loopDrivers() {
78-
//run mapping in the driver task
78+
// run mapping in the driver task
7979

8080
if (requestMapPhysical) {
8181
EXT_LOGD(ML_TAG, "mapLayout physical requested");
@@ -133,7 +133,7 @@ void PhysicalLayer::onLayoutPre() {
133133
memset(lights.channels, 0, lights.maxChannels); // set all the channels to 0
134134
// dealloc pins
135135
if (!monitorPass) {
136-
memset(ledsPerPin, UINT16_MAX, sizeof(ledsPerPin));
136+
memset(ledsPerPin, 0xFF, sizeof(ledsPerPin)); // UINT16_MAX
137137
}
138138
} else if (pass == 2) {
139139
indexP = 0;
@@ -176,14 +176,15 @@ void PhysicalLayer::nextPin() {
176176
if (pass == 1 && !monitorPass) {
177177
uint16_t prevNrOfLights = 0;
178178
uint8_t i = 0;
179-
while (ledsPerPin[i] != UINT16_MAX && i < sizeof(ledsPerPin)) {
179+
while (i < MAXLEDPINS && ledsPerPin[i] != UINT16_MAX) {
180180
prevNrOfLights += ledsPerPin[i];
181181
i++;
182182
}
183183
// ledsPerPin[i] is the first empty slot
184-
if (i < sizeof(ledsPerPin)) {
184+
if (i < MAXLEDPINS) {
185185
ledsPerPin[i] = lights.header.nrOfLights - prevNrOfLights;
186-
EXT_LOGD(ML_TAG, "nextPin #%d ledsPerPin:%d", i, ledsPerPin[i]);
186+
nrOfAssignedPins = i + 1;
187+
EXT_LOGD(ML_TAG, "nextPin #%d ledsPerPin:%d of %d", i, ledsPerPin[i], MAXLEDPINS);
187188
}
188189
}
189190
}

src/MoonLight/Layers/PhysicalLayer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class PhysicalLayer {
133133
uint8_t ledPins[MAXLEDPINS];
134134
uint16_t ledsPerPin[MAXLEDPINS];
135135
uint8_t nrOfLedPins = 0;
136+
uint8_t nrOfAssignedPins = 0;
136137
uint16_t maxPower = 0;
137138

138139
// an effect is using a virtual layer: tell the effect in which layer to run...

src/MoonLight/Modules/ModuleDrivers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ class ModuleDrivers : public NodeManager {
155155
#endif
156156

157157
if (node) {
158+
EXT_LOGD(ML_TAG, "%s (p:%p pr:%d)", name, node, isInPSRAM(node));
159+
158160
node->constructor(layerP.layers[0], controls); // pass the layer to the node (C++ constructors are not inherited, so declare it as normal functions)
159161
node->moduleControl = _moduleLightsControl; // to access global lights control functions if needed
160162
node->moduleIO = _moduleIO; // to access global lights control functions if needed

src/MoonLight/Nodes/Drivers/D_ArtnetOut.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ArtNetOutDriver : public DriverNode {
8484
LightsHeader* header = &layer->layerP->lights.header;
8585

8686
// continue with Art-Net code
87-
IPAddress activeIP = WiFi.localIP() ? WiFi.localIP() : ETH.localIP();
87+
IPAddress activeIP = WiFi.isConnected() ? WiFi.localIP() : ETH.localIP();
8888
controllerIP = activeIP;
8989
controllerIP[3] = controllerIP3;
9090
if (!controllerIP) return;

src/MoonLight/Nodes/Drivers/D_AudioSync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AudioSyncDriver : public Node {
3737
}
3838

3939
if (sync.read()) {
40-
memcpy(sharedData.bands, sync.fftResult, NUM_GEQ_CHANNELS);
40+
memcpy(sharedData.bands, sync.fftResult, sizeof(sharedData.bands));
4141
sharedData.volume = sync.volumeSmth;
4242
sharedData.volumeRaw = sync.volumeRaw;
4343
sharedData.majorPeak = sync.FFT_MajorPeak;

0 commit comments

Comments
 (0)