diff --git a/VortexEngine/VortexLib/Makefile b/VortexEngine/VortexLib/Makefile index aaa169ec2d..9c0f8415d9 100644 --- a/VortexEngine/VortexLib/Makefile +++ b/VortexEngine/VortexLib/Makefile @@ -31,7 +31,7 @@ INCLUDES=\ ifdef WASM DEFINES += -D WASM -CFLAGS += -s DISABLE_EXCEPTION_CATCHING=0 --bind +CFLAGS += --bind -s MODULARIZE=1 -s EXPORT_NAME='VortexLib' endif ifdef TESTFRAMEWORK @@ -93,7 +93,7 @@ TESTS=\ # target files ifdef WASM -TARGETS=vortex.js \ +TARGETS=VortexLib.js \ vortex.a else TARGETS=vortex.a @@ -113,7 +113,7 @@ wasm: FORCE vortex.a: $(DEPS) $(AR) $@ $^ -vortex.js: $(DEPS) +VortexLib.js: $(DEPS) $(CC) $(CFLAGS) $^ -o $@ $(LLIBS) # catch-all make target to generate .o and .d files @@ -132,7 +132,7 @@ FORCE: # generic clean target clean: - @$(RM) $(DFILES) $(OBJS) $(TARGETS) $(TESTS) vortex.js vortex.wasm + @$(RM) $(DFILES) $(OBJS) $(TARGETS) $(TESTS) VortexLib.js vortex.wasm # Now include our target dependency files # the hyphen means ignore non-existent files diff --git a/VortexEngine/VortexLib/VortexLib.cpp b/VortexEngine/VortexLib/VortexLib.cpp index 3a85b32494..3824ef3371 100644 --- a/VortexEngine/VortexLib/VortexLib.cpp +++ b/VortexEngine/VortexLib/VortexLib.cpp @@ -72,6 +72,34 @@ val tick_wasm() { return ledArray; } +emscripten::val getDataArray(const ByteStream &byteStream) +{ + const uint8_t *dataPtr = byteStream.data(); + uint32_t size = byteStream.size(); + + emscripten::val dataArray = emscripten::val::array(); + + for (uint32_t i = 0; i < size; ++i) { + dataArray.call("push", dataPtr[i]); + } + + return dataArray; +} + +emscripten::val getRawDataArray(const ByteStream &byteStream) +{ + const uint8_t *rawDataPtr = reinterpret_cast(byteStream.rawData()); + uint32_t rawSize = byteStream.rawSize(); + + emscripten::val rawDataArray = emscripten::val::array(); + + for (uint32_t i = 0; i < rawSize; ++i) { + rawDataArray.call("push", rawDataPtr[i]); + } + + return rawDataArray; +} + EMSCRIPTEN_BINDINGS(Vortex) { // vector register_vector("VectorString"); @@ -143,7 +171,14 @@ EMSCRIPTEN_BINDINGS(Vortex) { .function("unserialize32", &ByteStream::unserialize32) .function("peek8", &ByteStream::peek8) .function("peek16", &ByteStream::peek16) - .function("peek32", &ByteStream::peek32); + .function("peek32", &ByteStream::peek32) + .function("data", &ByteStream::data, allow_raw_pointer()) + .function("rawData", &ByteStream::rawData, allow_raw_pointer()) + .function("rawSize", &ByteStream::rawSize) + .function("size", &ByteStream::size) + .function("capacity", &ByteStream::capacity) + .function("is_compressed", &ByteStream::is_compressed) + .function("CRC", &ByteStream::CRC); // Binding static enum values enum_("LedPos") @@ -495,6 +530,11 @@ EMSCRIPTEN_BINDINGS(Vortex) { .class_function("getStorageFilename", &Vortex::getStorageFilename) .class_function("setLockEnabled", &Vortex::setLockEnabled) .class_function("lockEnabled", &Vortex::lockEnabled); + + function("getDataArray", &getDataArray); + function("getRawDataArray", &getRawDataArray); + + } #endif @@ -1037,7 +1077,7 @@ bool Vortex::setLedCount(uint8_t count) #if FIXED_LED_COUNT == 0 Mode *cur = Modes::curMode(); if (cur && !cur->setLedCount(count)) { - return true; + return false; } Leds::setLedCount(count); #endif