Skip to content

Commit

Permalink
fixes and more bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal-Dan committed Sep 24, 2023
1 parent 7e81e67 commit 5d19117
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
8 changes: 4 additions & 4 deletions VortexEngine/VortexLib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -93,7 +93,7 @@ TESTS=\

# target files
ifdef WASM
TARGETS=vortex.js \
TARGETS=VortexLib.js \
vortex.a
else
TARGETS=vortex.a
Expand All @@ -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
Expand All @@ -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
Expand Down
44 changes: 42 additions & 2 deletions VortexEngine/VortexLib/VortexLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>("push", dataPtr[i]);
}

return dataArray;
}

emscripten::val getRawDataArray(const ByteStream &byteStream)
{
const uint8_t *rawDataPtr = reinterpret_cast<const uint8_t *>(byteStream.rawData());
uint32_t rawSize = byteStream.rawSize();

emscripten::val rawDataArray = emscripten::val::array();

for (uint32_t i = 0; i < rawSize; ++i) {
rawDataArray.call<void>("push", rawDataPtr[i]);
}

return rawDataArray;
}

EMSCRIPTEN_BINDINGS(Vortex) {
// vector<string>
register_vector<std::string>("VectorString");
Expand Down Expand Up @@ -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<uint8_t>())
.function("rawData", &ByteStream::rawData, allow_raw_pointer<void>())
.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>("LedPos")
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5d19117

Please sign in to comment.