Skip to content
Draft
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
2 changes: 2 additions & 0 deletions libs/core/_locales/core-jsdoc-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@
"control.raiseEvent|param|src": "ID of the MicroBit Component that generated the event e.g. MICROBIT_ID_BUTTON_A.",
"control.raiseEvent|param|value": "Component specific code indicating the cause of the event.",
"control.ramSize": "Returns estimated size of memory in bytes.",
"control.rawOnEvent": "Registers an event handler.",
"control.rawUnregisterEvent": "Unregisters an event handler.",
"control.reset": "Resets the BBC micro:bit.",
"control.runInParallel": "Run other code in the parallel.",
"control.runtimeWarning": "Display warning in the simulator.",
Expand Down
10 changes: 10 additions & 0 deletions libs/core/codal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ void registerWithDal(int id, int event, Action a, int flags) {
registerGCPtr(a);
}

// relies on making sure Action a is kept alive in STS
void rawRegisterWithDal(int id, int event, Action a, int flags) {
uBit.messageBus.listen(id, event, dispatchForeground, a, (uint16_t) flags);
}

void rawUnregisterWithDal(int id, int event) {
uBit.messageBus.ignore(id, event, dispatchForeground);
}


void fiberDone(void *a) {
decr((Action)a);
unregisterGCPtr((Action)a);
Expand Down
17 changes: 17 additions & 0 deletions libs/core/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,23 @@ namespace control {
registerWithDal(src, value, handler, (int)flags);
}

/**
* Registers an event handler.
*/
//%
void rawOnEvent(int src, int value, Action handler, int flags = 0) {
if (!flags) flags = ::EventFlags::QueueIfBusy;
rawRegisterWithDal(src, value, handler, (int)flags);
}

/**
* Unregisters an event handler.
*/
//%
void rawUnregisterEvent(int src, int value) {
rawUnregisterWithDal(src, value);
}

/**
* Gets the value of the last event executed on the bus
*/
Expand Down
12 changes: 12 additions & 0 deletions libs/core/shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,18 @@ declare namespace control {
//% blockExternalInputs=1 flags.defl=0 shim=control::onEvent
function onEvent(src: int32, value: int32, handler: () => void, flags?: int32): void;

/**
* Registers an event handler.
*/
//% flags.defl=0 shim=control::rawOnEvent
function rawOnEvent(src: int32, value: int32, handler: () => void, flags?: int32): void;

/**
* Unregisters an event handler.
*/
//% shim=control::rawUnregisterEvent
function rawUnregisterEvent(src: int32, value: int32): void;

/**
* Gets the value of the last event executed on the bus
*/
Expand Down
15 changes: 15 additions & 0 deletions sim/state/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ namespace pxsim.control {
pxtcore.registerWithDal(id, evid, handler, flags)
}

export function rawOnEvent(id: number, evid: number, handler: RefAction, flags: number) {
if (id == DAL.MICROBIT_ID_BUTTON_AB) {
const b = board().buttonPairState;
if (!b.usesButtonAB) {
b.usesButtonAB = true;
runtime.queueDisplayUpdate();
}
}
pxtcore.registerWithDal(id, evid, handler, flags)
}

export function rawUnregisterEvent(id: number, evid: number) {
// TODO
}

export function eventTimestamp() {
return board().bus.getLastEventTime()
}
Expand Down
2 changes: 1 addition & 1 deletion targetconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"tags": [ "Lights and Display" ],
"simx": {
"sha": "0825d56f78528c57af100a96abdfe2162f59945a",
"devUrl": "http://localhost:3000"
"devUrl": "https://microbit-apps.github.io/display-shield/"
}
},
"microsoft/pxt-microturtle": {
Expand Down
Loading