support flag argument (#2126)

* support flag argument

* enable drop semantics

* add reentrant

* updated shims
This commit is contained in:
Peli de Halleux 2019-06-07 09:54:36 -07:00 committed by Abhijith Chatra
parent a0181ef2a7
commit 83ababd521
3 changed files with 24 additions and 4 deletions

View File

@ -205,6 +205,15 @@ enum EventBusValue {
MES_REMOTE_CONTROL_EVT_VOLUMEUP_ = MES_REMOTE_CONTROL_EVT_VOLUMEUP,
};
enum EventFlags {
//%
QueueIfBusy = MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY,
//%
DropIfBusy = MESSAGE_BUS_LISTENER_DROP_IF_BUSY,
//%
Reentrant = MESSAGE_BUS_LISTENER_REENTRANT
};
//% weight=1 color="#333333"
//% advanced=true
namespace control {
@ -261,8 +270,9 @@ namespace control {
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id"
//% help=control/on-event
//% blockExternalInputs=1
void onEvent(int src, int value, Action handler) {
registerWithDal(src, value, handler);
void onEvent(int src, int value, Action handler, int flags = 0) {
if (!flags) flags = EventFlags::QueueIfBusy;
registerWithDal(src, value, handler, (int)flags);
}
/**

10
libs/core/enums.d.ts vendored
View File

@ -400,6 +400,16 @@ declare namespace input {
//% blockIdentity="control.eventValueId"
MES_REMOTE_CONTROL_EVT_VOLUMEUP = 8, // MES_REMOTE_CONTROL_EVT_VOLUMEUP
}
declare const enum EventFlags {
//%
QueueIfBusy = 16, // MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY
//%
DropIfBusy = 32, // MESSAGE_BUS_LISTENER_DROP_IF_BUSY
//%
Reentrant = 8, // MESSAGE_BUS_LISTENER_REENTRANT
}
declare namespace control {
}

View File

@ -411,8 +411,8 @@ declare namespace control {
*/
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id"
//% help=control/on-event
//% blockExternalInputs=1 shim=control::onEvent
function onEvent(src: int32, value: int32, handler: () => void): void;
//% blockExternalInputs=1 flags.defl=0 shim=control::onEvent
function onEvent(src: int32, value: int32, handler: () => void, flags?: int32): void;
/**
* Gets the value of the last event executed on the bus