Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions _locales/machine-learning-jsdoc-strings.json
Original file line number Diff line number Diff line change
@@ -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."
}
{}
2 changes: 0 additions & 2 deletions _locales/machine-learning-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
4 changes: 1 addition & 3 deletions pxt.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
},
"files": [
"README.md",
"shims.d.ts",
"enums.d.ts",
"pxtextension.ts",
"pxtextension.cpp"
Expand All @@ -32,8 +31,7 @@
"preferredEditor": "tsprj",
"yotta": {
"config": {
"ML_INFERENCE_PERIOD_MS": 250,
"ML_EVENT_LISTENER_DEFAULT_FLAGS": 32
"ML_INFERENCE_PERIOD_MS": 250
}
}
}
38 changes: 0 additions & 38 deletions pxtextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
17 changes: 4 additions & 13 deletions pxtextension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down Expand Up @@ -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.
Expand Down
20 changes: 0 additions & 20 deletions shims.d.ts

This file was deleted.

Loading