I've been working on a project, where I want to run Micropython in JS. I stumbled upon the following port:
https://github.com/micropython/micropyt ... javascript
Which seems to work out great. I did implement some further functionality through emscripten, so that I can call JS from a MicroPython script:
(MicroPython)
Code: Select all
import js
js.exec("Some string")
Code: Select all
m.callback.call = (data) => {
console.log(data)
return data
}
Code: Select all
...
EM_JS(char *, callback, (const char* str), {
if(!Module.callback) Module.callback = {};
var returnVal = Module.callback['call'](UTF8ToString(str));
if(!returnVal) return 0;
const byteCount = (Module.lengthBytesUTF8(returnVal) + 1);
const returnValPtr = Module._malloc(byteCount);
Module.stringToUTF8(returnVal, returnValPtr, byteCount);
return returnValPtr;
});
STATIC mp_obj_t js_exec(mp_obj_t code) {
char * result = callback(mp_obj_str_get_str(code));
return mp_obj_new_str(result, strlen(result));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(js_exec_obj, js_exec);
...
Code: Select all
sensorData = 10
while sensorData < 50:
pass
Now, how do I update sensorData if the user has written some blocking code?
My initially idea, was to write a method in main.c, that performs an interrupt. I've been looking in various other ports, to see how that would work out, but without any luck.