diff --git a/libs/core/input.ts b/libs/core/input.ts index 05f39e89..20b1dd67 100644 --- a/libs/core/input.ts +++ b/libs/core/input.ts @@ -13,6 +13,7 @@ namespace sensors.internal { control.runInBackground(() => { let prev = query() + changeHandler(prev, prev) while (true) { loops.pause(periodMs) let curr = query() @@ -183,7 +184,7 @@ namespace sensors.internal { Low = 3, } - export class ThresholdDetector { + export class ThresholdDetector { public id: number; private min: number; private max: number; diff --git a/libs/core/linux.cpp b/libs/core/linux.cpp index e3f16705..5821d191 100644 --- a/libs/core/linux.cpp +++ b/libs/core/linux.cpp @@ -393,6 +393,10 @@ static void runPoller(Thread *thr) { // note that this is run without the user mutex held - it should not modify any state! TValue prev = pxt::runAction0(query); + startUser(); + pxt::runAction2(thr->act, prev, prev); + stopUser(); + while (true) { sleep_core_us(us); if (paniced) diff --git a/libs/ev3/pxt.json b/libs/ev3/pxt.json index 61752d25..5a3c7634 100644 --- a/libs/ev3/pxt.json +++ b/libs/ev3/pxt.json @@ -3,7 +3,8 @@ "description": "The EV3 library", "files": [ "README.md", - "ns.ts" + "ns.ts", + "startup.ts" ], "dependencies": { "base": "file:../base", diff --git a/libs/ev3/startup.ts b/libs/ev3/startup.ts new file mode 100644 index 00000000..3dcce976 --- /dev/null +++ b/libs/ev3/startup.ts @@ -0,0 +1,4 @@ +// This is the last thing executed before user code + +// We pause for 100ms to give time to read sensor values, so they work in on_start block +loops.pause(100)