Skip to content

Commit b46bb28

Browse files
committed
mappingTable realloc improvements
Back-end ======== Virtual layer: mappingTable realloc: always if size changes, if failed, keep old, init using memset
1 parent 1460cc9 commit b46bb28

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

docs/moonbase/inputoutput.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ For each board the following presets are defined:
4747

4848
- MicroController (MCU): The ESP32 chip
4949
- MCU-Board (MCB): MCU on a PCB
50-
- Carrier Board (CRB): board that the MCU-board plugs into (Or shield or controller board or interfae board)
50+
- Carrier Board (CRB): board that the MCU-board plugs into (Or shield or controller board or interface board)
5151
- Device (DVC): All of the above in a box with connectors
5252

5353
## Board details
@@ -62,4 +62,4 @@ For each board the following presets are defined:
6262

6363
### SE16 v1
6464

65-
* Set jumper1 the same as you set it on the board: Jumper1: on: Infrared, off: Ethernet
65+
* Set jumper1 the same as you set it on the board: on: Infrared, off: Ethernet

src/MoonLight/Layers/VirtualLayer.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,18 @@ void VirtualLayer::onLayoutPre() {
327327
mappingTableIndex.clear();
328328
}
329329

330-
if (mappingTableSize < size.x * size.y * size.z) {
331-
mappingTable = reallocMB<PhysMap>(mappingTable, size.x * size.y * size.z);
332-
if (mappingTable) {
330+
if (mappingTableSize != size.x * size.y * size.z) {
331+
332+
PhysMap* newTable = reallocMB<PhysMap>(mappingTable, size.x * size.y * size.z);
333+
if (newTable) {
334+
mappingTable = newTable;
333335
EXT_LOGD(ML_TAG, "realloc mappingTable %d -> %dx%dx%d", mappingTableSize, size.x, size.y, size.z);
334336
mappingTableSize = size.x * size.y * size.z;
335337
} else {
336-
EXT_LOGW(ML_TAG, "realloc mappingTable failed %dx%dx%d", size.x, size.y, size.z);
337-
mappingTableSize = 0;
338+
EXT_LOGW(ML_TAG, "realloc mappingTable failed keeping oldSize %d", mappingTableSize);
338339
}
339340
}
340-
for (int i = 0; i < mappingTableSize; i++) mappingTable[i] = PhysMap();
341+
memset(mappingTable, 0, mappingTableSize * sizeof(PhysMap)); // set mappingTable to default PhysMap
341342
}
342343

343344
void VirtualLayer::addLight(Coord3D position) {

src/MoonLight/Modules/ModuleLightsControl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ModuleLightsControl : public Module {
4040

4141
EXT_LOGI(ML_TAG, "Lights:%d(Header:%d) L-H:%d Node:%d PL:%d(PL-L:%d) VL:%d PM:%d C3D:%d", sizeof(Lights), sizeof(LightsHeader), sizeof(Lights) - sizeof(LightsHeader), sizeof(Node), sizeof(PhysicalLayer), sizeof(PhysicalLayer) - sizeof(Lights), sizeof(VirtualLayer), sizeof(PhysMap), sizeof(Coord3D));
4242

43-
EXT_LOGI(ML_TAG, "isInPSRAM: mt:%d mti:%d ch:%d", isInPSRAM(&layerP.layers[0]->mappingTable), isInPSRAM(&layerP.layers[0]->mappingTableIndexes), isInPSRAM(layerP.lights.channels));
43+
EXT_LOGI(ML_TAG, "isInPSRAM: mt:%d mti:%d ch:%d", isInPSRAM(layerP.layers[0]->mappingTable), isInPSRAM(&layerP.layers[0]->mappingTableIndexes), isInPSRAM(layerP.lights.channels));
4444

4545
setPresetsFromFolder(); // set the right values during boot
4646

0 commit comments

Comments
 (0)