Skip to content

Commit 8bfb85a

Browse files
Remove custom onEvent function (#28)
control.onEvent is now sufficient
1 parent 62ab8f9 commit 8bfb85a

File tree

7 files changed

+6
-111
lines changed

7 files changed

+6
-111
lines changed

README.md

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,6 @@ By default the model will run every 250 ms, to change this value the
4242
}
4343
```
4444

45-
### Model events
46-
47-
By default this extension configures the Model prediction events to not be
48-
queued for the same event.
49-
So if an event raised when its handler is still running it will be dropped.
50-
51-
```json
52-
{
53-
"yotta": {
54-
"config": {
55-
"ML_EVENT_LISTENER_DEFAULT_FLAGS": 32
56-
}
57-
}
58-
}
59-
```
60-
61-
The values are defined in the
62-
[codal-core/inc/core/CodalListener.h](https://github.com/lancaster-university/codal-core/blob/df05db9e15499bd8906618192a4d482e3836c62f/inc/core/CodalListener.h#L36-L40)
63-
file:
64-
65-
```cpp
66-
#define MESSAGE_BUS_LISTENER_REENTRANT 0x0008
67-
#define MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY 0x0010
68-
#define MESSAGE_BUS_LISTENER_DROP_IF_BUSY 0x0020
69-
#define MESSAGE_BUS_LISTENER_NONBLOCKING 0x0040
70-
#define MESSAGE_BUS_LISTENER_URGENT 0x0080
71-
```
72-
7345
### Debug messages
7446

7547
To enable debug print from this extension, add the following into your
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
{
2-
"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*",
3-
"mlrunner.customOnEvent|param|flags": "The specified event flags are ignored and configured via pxt.json.",
4-
"mlrunner.customOnEvent|param|handler": "The function to call when the event is detected.",
5-
"mlrunner.customOnEvent|param|src": "The ID of the component to listen to.",
6-
"mlrunner.customOnEvent|param|value": "The event value to listen to from that component."
7-
}
1+
{}

_locales/machine-learning-strings.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
"ml.onStart|block": "on ML $event start",
66
"ml.onStopDetailed|block": "on ML $event stop $duration (ms)",
77
"ml.onStop|block": "on ML $event stop",
8-
"mlrunner|block": "mlrunner",
98
"{id:category}Ml": "Ml",
109
"{id:category}MlEvent": "MlEvent",
11-
"{id:category}Mlrunner": "Mlrunner",
1210
"{id:group}micro:bit (V2)": "micro:bit (V2)"
1311
}

pxt.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
},
99
"files": [
1010
"README.md",
11-
"shims.d.ts",
1211
"enums.d.ts",
1312
"pxtextension.ts",
1413
"pxtextension.cpp"
@@ -32,8 +31,7 @@
3231
"preferredEditor": "tsprj",
3332
"yotta": {
3433
"config": {
35-
"ML_INFERENCE_PERIOD_MS": 250,
36-
"ML_EVENT_LISTENER_DEFAULT_FLAGS": 32
34+
"ML_INFERENCE_PERIOD_MS": 250
3735
}
3836
}
3937
}

pxtextension.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ enum MlRunnerError {
4040
#define ML_INFERENCE_PERIOD_MS 250
4141
#endif
4242

43-
// Configure the default flags for the model event listeners, can be set in pxt.json
44-
#ifndef ML_EVENT_LISTENER_DEFAULT_FLAGS
45-
#define ML_EVENT_LISTENER_DEFAULT_FLAGS MESSAGE_BUS_LISTENER_DROP_IF_BUSY
46-
#endif
47-
4843
namespace mlrunner {
4944

5045
static const uint16_t ML_CODAL_TIMER_VALUE = 1;
@@ -144,39 +139,6 @@ namespace mlrunner {
144139
}
145140
}
146141

147-
/**
148-
* Execute a function from TypeScript land.
149-
*
150-
* @param e The event data is ignored
151-
* @param action TypeScript function to run without any arguments.
152-
*/
153-
void runHandler(MicroBitEvent e, void *action) {
154-
runAction0((Action)action);
155-
}
156-
157-
/*************************************************************************/
158-
/* TypeScript exported functions */
159-
/*************************************************************************/
160-
/**
161-
* Register a TypeScript function to run when an event is raised.
162-
*
163-
* This custom version of the MakeCode onEvent function is needed due to:
164-
* https://github.com/microsoft/pxt-microbit/issues/5709
165-
*
166-
*
167-
* @param src The ID of the component to listen to.
168-
* @param value The event value to listen to from that component.
169-
* @param handler The function to call when the event is detected.
170-
* @param flags The specified event flags are ignored and configured via pxt.json.
171-
*/
172-
//%
173-
void customOnEvent(int src, int value, Action handler, int flags = 0) {
174-
uBit.messageBus.ignore(src, value, runHandler);
175-
uBit.messageBus.listen(src, value, runHandler, handler, ML_EVENT_LISTENER_DEFAULT_FLAGS);
176-
pxt::incr(handler);
177-
pxt::registerGCPtr(handler);
178-
}
179-
180142
//%
181143
void init(Buffer model_str) {
182144
#if MICROBIT_CODAL != 1

pxtextension.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ namespace ml {
6868
if (!isRunning()) {
6969
startRunning();
7070
}
71-
mlRunnerCustomOnEvent(
71+
// The sim probably won't respect the DropIfBusy flag.
72+
control.onEvent(
7273
MlRunnerIds.MlRunnerInference,
7374
event.eventValue,
74-
wrappedBody
75+
wrappedBody,
76+
EventFlags.DropIfBusy
7577
);
7678
}
7779

@@ -144,17 +146,6 @@ namespace ml {
144146
export let getModelBlob: () => Buffer;
145147
let simIsRunning = false;
146148

147-
//% shim=mlrunner::customOnEvent
148-
function mlRunnerCustomOnEvent(
149-
id: number,
150-
evid: number,
151-
handler: () => void,
152-
flags?: number
153-
) {
154-
// The sim probably won't respect the DropIfBusy flag
155-
control.onEvent(id, evid, handler, EventFlags.DropIfBusy);
156-
}
157-
158149
/**
159150
* TS shim for C++ function init(), which initialize the ML model with
160151
* an address to a model blob.

shims.d.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)