Skip to content

Commit

Permalink
Run commands
Browse files Browse the repository at this point in the history
  • Loading branch information
pipe01 committed Jun 22, 2024
1 parent 403e72c commit e2e8433
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
5 changes: 5 additions & 0 deletions frontend/wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@

<div id="performance"></div>

<div>
<input type="text" id="command">
<button onclick="myWorker.postMessage({ type: 'runCommand', command: document.getElementById('command').value })">Run</button>
</div>

<script>
const myWorker = new Worker("infiniemu.worker.js");
const display = document.getElementById("display");
Expand Down
15 changes: 13 additions & 2 deletions frontend/wasm/infiniemu.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ var Module = {

postMessage({ type: "ready" });
},
print(text) {
console.log("print", text);
}
};

importScripts("infiniemu.js");

const iterations = 700000;

var pt, lcd, touch, pins;
var pt, lcd, touch, pins, cmd;

var isLcdSleeping = false;
var displayBufferPointer, rgbaBufferPointer;
Expand Down Expand Up @@ -54,6 +56,12 @@ onmessage = (e) => {
Module._pins_clear(pins, 13);
break;

case "runCommand":
const str = stringToNewUTF8(e.data.command);
Module._commander_run_command(cmd, str);
Module._free(str);
break;

case "loadProgram":
if (pt) {
console.error("Pinetime already loaded");
Expand All @@ -69,6 +77,9 @@ onmessage = (e) => {
lcd = Module._pinetime_get_st7789(pt);
touch = Module._pinetime_get_cst816s(pt);
pins = Module._nrf52832_get_pins(Module._pinetime_get_nrf52832(pt));
cmd = Module._commander_new(pt);

Module._commander_set_output(cmd, Module._commander_output);

displayBufferPointer = Module._malloc(240 * 240 * 2);
rgbaBufferPointer = Module._malloc(240 * 240 * 4);
Expand Down
6 changes: 4 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ set(SRC_FILES
)

set(WASM_EXPORTS
malloc pinetime_new pinetime_step pinetime_loop
malloc free
pinetime_new pinetime_step pinetime_loop
pinetime_get_st7789 st7789_read_screen_rgba st7789_is_sleeping st7789_get_write_count st7789_is_sleeping
pinetime_get_cst816s cst816s_do_touch cst816s_release_touch
pinetime_get_nrf52832 nrf52832_get_pins pins_set pins_clear
program_new program_load_binary program_load_elf
commander_new commander_set_output commander_run_command commander_output
)

set(LIBS m tiny-aes capstone)
Expand All @@ -79,7 +81,7 @@ if(EMSCRIPTEN)
list(JOIN WASM_EXPORTS "," WASM_EXPORTS_STR)

target_link_options(infiniemu-wasm PRIVATE "-sEXPORTED_FUNCTIONS=${WASM_EXPORTS_STR}")
target_link_options(infiniemu-wasm PRIVATE -sTOTAL_STACK=64MB -sALLOW_MEMORY_GROWTH -sEXPORTED_RUNTIME_METHODS=ccall,cwrap)
target_link_options(infiniemu-wasm PRIVATE -sTOTAL_STACK=64MB -sALLOW_MEMORY_GROWTH -sEXPORTED_RUNTIME_METHODS=ccall,cwrap,stringToNewUTF8)
else()
add_executable(infiniemu-cli ${SRC_FILES} main.c)
add_library(infiniemu-lib STATIC ${SRC_FILES})
Expand Down
9 changes: 9 additions & 0 deletions src/wasm.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "pinetime.h"
#include "components/spi/st7789.h"

#include <emscripten.h>

bool pinetime_loop(pinetime_t *pt, size_t n)
{
st7789_t *lcd = pinetime_get_st7789(pt);
Expand Down Expand Up @@ -39,3 +41,10 @@ void st7789_read_screen_rgba(st7789_t *st, uint8_t *screen_buffer, uint8_t *rgba
}
}
}

void commander_output(const char *msg, void *userdata)
{
EM_ASM({
console.log($0);
}, msg);
}

0 comments on commit e2e8433

Please sign in to comment.