diff --git a/Makefile b/Makefile index 50c87ddc6..4a216c3a2 100644 --- a/Makefile +++ b/Makefile @@ -125,3 +125,5 @@ endif clean: @echo "CLEAN" @rm -f $(products) + +-include build/targets.$(PLATFORM).mak diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 13bc02e13..a8ae4db8e 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -136,11 +136,6 @@ void AppsContainer::run() { switchTo(nullptr); } -void AppsContainer::runWhile(bool (*callback)(void * ctx), void * ctx) { - while (callback(ctx) && RunLoop::step()) { - } -} - bool AppsContainer::updateBatteryState() { if (m_window.updateBatteryLevel() || m_window.updateIsChargingState() || diff --git a/apps/apps_container.h b/apps/apps_container.h index d7a7b7a56..89126897f 100644 --- a/apps/apps_container.h +++ b/apps/apps_container.h @@ -39,7 +39,6 @@ public: virtual bool dispatchEvent(Ion::Events::Event event) override; void switchTo(App::Snapshot * snapshot) override; void run() override; - void runWhile(bool (*callback)(void * ctx), void * ctx); bool updateBatteryState(); void refreshPreferences(); void displayExamModePopUp(bool activate); diff --git a/build/platform.emscripten.mak b/build/platform.emscripten.mak index ac856c8ba..3ecd61880 100644 --- a/build/platform.emscripten.mak +++ b/build/platform.emscripten.mak @@ -3,14 +3,3 @@ USE_LIBA = 0 EXE = js OS_WITH_ONBOARDING_APP ?= 0 OS_WITH_SOFTWARE_UPDATE_PROMPT ?= 0 - -numworks_simulator.zip: LDFLAGS += --memory-init-file 0 -numworks_simulator.zip: app.js - @rm -rf $(basename $@) - @mkdir $(basename $@) - @cp app.js $(basename $@)/firmware.js - @cp ion/src/emscripten/background.jpg $(basename $@)/ - @cp ion/src/emscripten/simulator.html $(basename $@)/ - @echo "ZIP $@" - @zip -r -9 $@ $(basename $@) > /dev/null - @rm -rf $(basename $@) diff --git a/build/targets.emscripten.mak b/build/targets.emscripten.mak new file mode 100644 index 000000000..1515c2bbe --- /dev/null +++ b/build/targets.emscripten.mak @@ -0,0 +1,17 @@ +app.js: LDFLAGS += -s 'EMTERPRETIFY_FILE="app.etb"' +app.js: $(app_objs) $(app_image_objs) + +app.packed.js: LDFLAGS += --memory-init-file 0 +app.packed.js: $(app_objs) $(app_image_objs) + +numworks_simulator.zip: app.packed.js + @rm -rf $(basename $@) + @mkdir $(basename $@) + @cp app.packed.js $(basename $@)/epsilon.js + @cp ion/src/emscripten/background.jpg $(basename $@)/ + @cp ion/src/emscripten/simulator.html $(basename $@)/ + @echo "ZIP $@" + @zip -r -9 $@ $(basename $@) > /dev/null + @rm -rf $(basename $@) + +products += $(addprefix app.,js mem etb) app.packed.js numworks_simulator.zip diff --git a/build/toolchain.emscripten.mak b/build/toolchain.emscripten.mak index aeb11453c..fad4d210e 100644 --- a/build/toolchain.emscripten.mak +++ b/build/toolchain.emscripten.mak @@ -1,5 +1,6 @@ CC = emcc CXX = emcc LD = emcc -LDFLAGS = -s EXPORTED_FUNCTIONS="['_main', '_IonEventsEmscriptenPushEvent']" -Os +SFLAGS = -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 +LDFLAGS = -Oz -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 -s EXPORTED_FUNCTIONS="['_main', '_IonEventsEmscriptenPushEvent']" SIZE = size diff --git a/escher/include/escher/run_loop.h b/escher/include/escher/run_loop.h index 2788fb2f8..2ef4b9207 100644 --- a/escher/include/escher/run_loop.h +++ b/escher/include/escher/run_loop.h @@ -8,12 +8,13 @@ class RunLoop { public: RunLoop(); void run(); + void runWhile(bool (*callback)(void * ctx), void * ctx); protected: virtual bool dispatchEvent(Ion::Events::Event e) = 0; virtual int numberOfTimers(); virtual Timer * timerAtIndex(int i); - bool step(); private: + bool step(); int m_time; }; diff --git a/escher/src/run_loop.cpp b/escher/src/run_loop.cpp index 55eb0d870..c35fcbd6a 100644 --- a/escher/src/run_loop.cpp +++ b/escher/src/run_loop.cpp @@ -18,12 +18,12 @@ Timer * RunLoop::timerAtIndex(int i) { } void RunLoop::run() { -#ifdef __EMSCRIPTEN__ - emscripten_set_main_loop_arg([](void * ctx){ ((RunLoop *)ctx)->step(); }, this, 0, 1); -#else - while(step()) { + runWhile(nullptr, nullptr); +} + +void RunLoop::runWhile(bool (*callback)(void * ctx), void * ctx) { + while ((callback == nullptr || callback(ctx)) && step()) { } -#endif } bool RunLoop::step() { diff --git a/ion/src/emscripten/events_keyboard.cpp b/ion/src/emscripten/events_keyboard.cpp index 46972ffe8..72fea581c 100644 --- a/ion/src/emscripten/events_keyboard.cpp +++ b/ion/src/emscripten/events_keyboard.cpp @@ -4,6 +4,7 @@ extern "C" { #include } +#include static Ion::Events::Event sEvent = Ion::Events::None; @@ -47,6 +48,7 @@ static constexpr Event sEventForASCIICharAbove32[95] = { Event getEvent(int * timeout) { Ion::Display::Emscripten::refresh(); + emscripten_sleep(1); if (sEvent != None) { Event event = sEvent; updateModifiersFromEvent(event); diff --git a/ion/src/emscripten/simulator.html b/ion/src/emscripten/simulator.html index 2bcb76a8c..c0d91aaa4 100644 --- a/ion/src/emscripten/simulator.html +++ b/ion/src/emscripten/simulator.html @@ -197,7 +197,7 @@ var Module = { canvas: document.getElementById("screen") }; - +