diff --git a/README.md b/README.md index d943256..38c144c 100644 --- a/README.md +++ b/README.md @@ -42,34 +42,6 @@ By default the model will run every 250 ms, to change this value the } ``` -### Model events - -By default this extension configures the Model prediction events to not be -queued for the same event. -So if an event raised when its handler is still running it will be dropped. - -```json -{ - "yotta": { - "config": { - "ML_EVENT_LISTENER_DEFAULT_FLAGS": 32 - } - } -} -``` - -The values are defined in the -[codal-core/inc/core/CodalListener.h](https://github.com/lancaster-university/codal-core/blob/df05db9e15499bd8906618192a4d482e3836c62f/inc/core/CodalListener.h#L36-L40) -file: - -```cpp -#define MESSAGE_BUS_LISTENER_REENTRANT 0x0008 -#define MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY 0x0010 -#define MESSAGE_BUS_LISTENER_DROP_IF_BUSY 0x0020 -#define MESSAGE_BUS_LISTENER_NONBLOCKING 0x0040 -#define MESSAGE_BUS_LISTENER_URGENT 0x0080 -``` - ### Debug messages To enable debug print from this extension, add the following into your diff --git a/_locales/machine-learning-jsdoc-strings.json b/_locales/machine-learning-jsdoc-strings.json index f23893d..9e26dfe 100644 --- a/_locales/machine-learning-jsdoc-strings.json +++ b/_locales/machine-learning-jsdoc-strings.json @@ -1,7 +1 @@ -{ - "mlrunner.customOnEvent": "Register a TypeScript function to run when an event is raised.\n* This custom version of the MakeCode onEvent function is needed due to:\nhttps://github.com/microsoft/pxt-microbit/issues/5709\n*", - "mlrunner.customOnEvent|param|flags": "The specified event flags are ignored and configured via pxt.json.", - "mlrunner.customOnEvent|param|handler": "The function to call when the event is detected.", - "mlrunner.customOnEvent|param|src": "The ID of the component to listen to.", - "mlrunner.customOnEvent|param|value": "The event value to listen to from that component." -} \ No newline at end of file +{} \ No newline at end of file diff --git a/_locales/machine-learning-strings.json b/_locales/machine-learning-strings.json index fd4bd33..9d5044a 100644 --- a/_locales/machine-learning-strings.json +++ b/_locales/machine-learning-strings.json @@ -5,9 +5,7 @@ "ml.onStart|block": "on ML $event start", "ml.onStopDetailed|block": "on ML $event stop $duration (ms)", "ml.onStop|block": "on ML $event stop", - "mlrunner|block": "mlrunner", "{id:category}Ml": "Ml", "{id:category}MlEvent": "MlEvent", - "{id:category}Mlrunner": "Mlrunner", "{id:group}micro:bit (V2)": "micro:bit (V2)" } \ No newline at end of file diff --git a/pxt.json b/pxt.json index a7d51a1..ba7d749 100644 --- a/pxt.json +++ b/pxt.json @@ -8,7 +8,6 @@ }, "files": [ "README.md", - "shims.d.ts", "enums.d.ts", "pxtextension.ts", "pxtextension.cpp" @@ -32,8 +31,7 @@ "preferredEditor": "tsprj", "yotta": { "config": { - "ML_INFERENCE_PERIOD_MS": 250, - "ML_EVENT_LISTENER_DEFAULT_FLAGS": 32 + "ML_INFERENCE_PERIOD_MS": 250 } } } diff --git a/pxtextension.cpp b/pxtextension.cpp index c5d4b6b..724ddda 100644 --- a/pxtextension.cpp +++ b/pxtextension.cpp @@ -40,11 +40,6 @@ enum MlRunnerError { #define ML_INFERENCE_PERIOD_MS 250 #endif -// Configure the default flags for the model event listeners, can be set in pxt.json -#ifndef ML_EVENT_LISTENER_DEFAULT_FLAGS -#define ML_EVENT_LISTENER_DEFAULT_FLAGS MESSAGE_BUS_LISTENER_DROP_IF_BUSY -#endif - namespace mlrunner { static const uint16_t ML_CODAL_TIMER_VALUE = 1; @@ -144,39 +139,6 @@ namespace mlrunner { } } - /** - * Execute a function from TypeScript land. - * - * @param e The event data is ignored - * @param action TypeScript function to run without any arguments. - */ - void runHandler(MicroBitEvent e, void *action) { - runAction0((Action)action); - } - - /*************************************************************************/ - /* TypeScript exported functions */ - /*************************************************************************/ - /** - * Register a TypeScript function to run when an event is raised. - * - * This custom version of the MakeCode onEvent function is needed due to: - * https://github.com/microsoft/pxt-microbit/issues/5709 - * - * - * @param src The ID of the component to listen to. - * @param value The event value to listen to from that component. - * @param handler The function to call when the event is detected. - * @param flags The specified event flags are ignored and configured via pxt.json. - */ - //% - void customOnEvent(int src, int value, Action handler, int flags = 0) { - uBit.messageBus.ignore(src, value, runHandler); - uBit.messageBus.listen(src, value, runHandler, handler, ML_EVENT_LISTENER_DEFAULT_FLAGS); - pxt::incr(handler); - pxt::registerGCPtr(handler); - } - //% void init(Buffer model_str) { #if MICROBIT_CODAL != 1 diff --git a/pxtextension.ts b/pxtextension.ts index 1fa1ee0..d7c9504 100644 --- a/pxtextension.ts +++ b/pxtextension.ts @@ -68,10 +68,12 @@ namespace ml { if (!isRunning()) { startRunning(); } - mlRunnerCustomOnEvent( + // The sim probably won't respect the DropIfBusy flag. + control.onEvent( MlRunnerIds.MlRunnerInference, event.eventValue, - wrappedBody + wrappedBody, + EventFlags.DropIfBusy ); } @@ -144,17 +146,6 @@ namespace ml { export let getModelBlob: () => Buffer; let simIsRunning = false; - //% shim=mlrunner::customOnEvent - function mlRunnerCustomOnEvent( - id: number, - evid: number, - handler: () => void, - flags?: number - ) { - // The sim probably won't respect the DropIfBusy flag - control.onEvent(id, evid, handler, EventFlags.DropIfBusy); - } - /** * TS shim for C++ function init(), which initialize the ML model with * an address to a model blob. diff --git a/shims.d.ts b/shims.d.ts deleted file mode 100644 index 9cdf50c..0000000 --- a/shims.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -// Auto-generated. Do not edit. -declare namespace mlrunner { - - /** - * Register a TypeScript function to run when an event is raised. - * - * This custom version of the MakeCode onEvent function is needed due to: - * https://github.com/microsoft/pxt-microbit/issues/5709 - * - * - * @param src The ID of the component to listen to. - * @param value The event value to listen to from that component. - * @param handler The function to call when the event is detected. - * @param flags The specified event flags are ignored and configured via pxt.json. - */ - //% flags.defl=0 shim=mlrunner::customOnEvent - function customOnEvent(src: int32, value: int32, handler: () => void, flags?: int32): void; -} - -// Auto-generated. Do not edit. Really.