Unloading at effect end

This commit is contained in:
cschwinne 2021-07-23 00:30:25 +02:00
parent 148de04e6f
commit a84e242a37
6 changed files with 23 additions and 16 deletions

View File

@ -42,6 +42,7 @@ uint16_t WS2812FX::mode_static(void) {
* Custom mode. Executes WebAssembly fx() function
*/
uint16_t WS2812FX::mode_custom(void) {
if (SEGENV.call == 0) wasmfx.init();
wasmfx.run();
return FRAMETIME;
}

View File

@ -386,6 +386,10 @@ class WS2812FX {
}
}
bool isResetRequired() {
return _requiresReset;
}
/**
* Flags that before the next effect is calculated,
* the internal segment state should be reset.
@ -630,8 +634,7 @@ class WS2812FX {
setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t w = 0),
show(void),
setColorOrder(uint8_t co),
setPixelSegment(uint8_t n),
initWasm(void);
setPixelSegment(uint8_t n);
bool
isRgbw = false,

View File

@ -144,6 +144,7 @@ void WS2812FX::service() {
// reset the segment runtime data if needed, called before isActive to ensure deleted
// segment's buffers are cleared
if (SEGENV.isResetRequired()) wasmfx.end();
SEGENV.resetIfRequired();
if (!SEGMENT.isActive()) continue;
@ -1085,8 +1086,4 @@ uint32_t WS2812FX::gamma32(uint32_t color)
return ((w << 24) | (r << 16) | (g << 8) | (b));
}
void WS2812FX::initWasm() {
wasmfx.init();
}
WS2812FX* WS2812FX::instance = nullptr;

View File

@ -252,6 +252,7 @@ void userLoop();
//wasm.cpp
void wasmInit();
void wasmRun();
void wasmEnd();
class WASMFX {
public:
@ -263,6 +264,10 @@ class WASMFX {
wasmRun();
}
void end() {
wasmEnd();
}
uint32_t now();
uint32_t speed();
uint32_t intensity();

View File

@ -222,10 +222,6 @@ void wasm_task(void*)
if (result) FATAL("Func", result);
Serial.println(F("WASM init success!"));
// Should not arrive here
//while (true) {}
}
void wasmInit()
@ -268,3 +264,9 @@ void wasmRun() {
}
}
}
void wasmEnd() {
if (module) m3_FreeModule(module); module = nullptr;
if (runtime) m3_FreeRuntime(runtime); runtime = nullptr;
if (env) m3_FreeEnvironment(env); env = nullptr;
}

View File

@ -313,7 +313,6 @@ void WLED::setup()
if (!pinManager.isPinAllocated(STATUSLED)) pinMode(STATUSLED, OUTPUT);
#endif
wasmfx.init();
DEBUG_PRINTLN(F("Initializing strip"));
beginStrip();