2016-11-30 06:55:37 +01:00
|
|
|
#include "pxt.h"
|
2016-03-30 02:11:17 +02:00
|
|
|
|
2021-11-25 17:27:39 +01:00
|
|
|
extern uint32_t __StackTop;
|
|
|
|
|
2016-04-02 02:45:18 +02:00
|
|
|
/**
|
|
|
|
* How to create the event.
|
|
|
|
*/
|
|
|
|
enum class EventCreationMode {
|
|
|
|
/**
|
|
|
|
* MicroBitEvent is initialised, and no further processing takes place.
|
|
|
|
*/
|
|
|
|
CreateOnly = CREATE_ONLY,
|
|
|
|
/**
|
|
|
|
* MicroBitEvent is initialised, and its event handlers are immediately fired (not suitable for use in interrupts!).
|
|
|
|
*/
|
|
|
|
CreateAndFire = CREATE_AND_FIRE,
|
|
|
|
};
|
|
|
|
|
|
|
|
// note the trailing '_' in names - otherwise we get conflict with the pre-processor
|
|
|
|
// this trailing underscore is removed by enums.d.ts generation process
|
|
|
|
|
|
|
|
// TODO shouldn't these be renamed to something more sensible anyways?
|
|
|
|
|
|
|
|
enum EventBusSource {
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_BUTTON_A_ = MICROBIT_ID_BUTTON_A,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_BUTTON_B_ = MICROBIT_ID_BUTTON_B,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_BUTTON_AB_ = MICROBIT_ID_BUTTON_AB,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_RADIO_ = MICROBIT_ID_RADIO,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_GESTURE_ = MICROBIT_ID_GESTURE,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_ACCELEROMETER_ = MICROBIT_ID_ACCELEROMETER,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_IO_P0_ = MICROBIT_ID_IO_P0,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_IO_P1_ = MICROBIT_ID_IO_P1,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_IO_P2_ = MICROBIT_ID_IO_P2,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_IO_P3_ = MICROBIT_ID_IO_P3,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_IO_P4_ = MICROBIT_ID_IO_P4,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_IO_P5_ = MICROBIT_ID_IO_P5,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_IO_P6_ = MICROBIT_ID_IO_P6,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_IO_P7_ = MICROBIT_ID_IO_P7,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2017-01-31 22:36:32 +01:00
|
|
|
MICROBIT_ID_IO_P8_ = MICROBIT_ID_IO_P8,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_IO_P9_ = MICROBIT_ID_IO_P9,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_IO_P10_ = MICROBIT_ID_IO_P10,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_IO_P11_ = MICROBIT_ID_IO_P11,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2017-01-31 22:36:32 +01:00
|
|
|
MICROBIT_ID_IO_P12_ = MICROBIT_ID_IO_P12,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2017-01-31 22:36:32 +01:00
|
|
|
MICROBIT_ID_IO_P13_ = MICROBIT_ID_IO_P13,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2017-01-31 22:36:32 +01:00
|
|
|
MICROBIT_ID_IO_P14_ = MICROBIT_ID_IO_P14,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2017-01-31 22:36:32 +01:00
|
|
|
MICROBIT_ID_IO_P15_ = MICROBIT_ID_IO_P15,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2017-01-31 22:36:32 +01:00
|
|
|
MICROBIT_ID_IO_P16_ = MICROBIT_ID_IO_P16,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_IO_P19_ = MICROBIT_ID_IO_P19,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ID_IO_P20_ = MICROBIT_ID_IO_P20,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DEVICE_INFO_ID_ = MES_DEVICE_INFO_ID,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_SIGNAL_STRENGTH_ID_ = MES_SIGNAL_STRENGTH_ID,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_CONTROLLER_ID_ = MES_DPAD_CONTROLLER_ID,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventSourceId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_BROADCAST_GENERAL_ID_ = MES_BROADCAST_GENERAL_ID,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum EventBusValue {
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_EVT_ANY_ = MICROBIT_EVT_ANY,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
|
|
|
MICROBIT_BUTTON_EVT_DOWN_ = MICROBIT_BUTTON_EVT_DOWN,
|
|
|
|
//% blockIdentity="control.eventValueId"
|
|
|
|
MICROBIT_BUTTON_EVT_UP_ = MICROBIT_BUTTON_EVT_UP,
|
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_BUTTON_EVT_CLICK_ = MICROBIT_BUTTON_EVT_CLICK,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_RADIO_EVT_DATAGRAM_ = MICROBIT_RADIO_EVT_DATAGRAM,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE_ = MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2017-01-30 20:19:54 +01:00
|
|
|
MICROBIT_PIN_EVT_RISE_ = MICROBIT_PIN_EVT_RISE,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2017-01-30 20:19:54 +01:00
|
|
|
MICROBIT_PIN_EVT_FALL_ = MICROBIT_PIN_EVT_FALL,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2017-01-30 20:19:54 +01:00
|
|
|
MICROBIT_PIN_EVT_PULSE_HI_ = MICROBIT_PIN_EVT_PULSE_HI,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2017-01-30 20:19:54 +01:00
|
|
|
MICROBIT_PIN_EVT_PULSE_LO_ = MICROBIT_PIN_EVT_PULSE_LO,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_ALERT_EVT_ALARM1_ = MES_ALERT_EVT_ALARM1,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_ALERT_EVT_ALARM2_ = MES_ALERT_EVT_ALARM2,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_ALERT_EVT_ALARM3_ = MES_ALERT_EVT_ALARM3,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_ALERT_EVT_ALARM4_ = MES_ALERT_EVT_ALARM4,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_ALERT_EVT_ALARM5_ = MES_ALERT_EVT_ALARM5,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_ALERT_EVT_ALARM6_ = MES_ALERT_EVT_ALARM6,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_ALERT_EVT_DISPLAY_TOAST_ = MES_ALERT_EVT_DISPLAY_TOAST,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_ALERT_EVT_FIND_MY_PHONE_ = MES_ALERT_EVT_FIND_MY_PHONE,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_ALERT_EVT_PLAY_RINGTONE_ = MES_ALERT_EVT_PLAY_RINGTONE,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_ALERT_EVT_PLAY_SOUND_ = MES_ALERT_EVT_PLAY_SOUND,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_ALERT_EVT_VIBRATE_ = MES_ALERT_EVT_VIBRATE,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_CAMERA_EVT_LAUNCH_PHOTO_MODE_ = MES_CAMERA_EVT_LAUNCH_PHOTO_MODE,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_CAMERA_EVT_LAUNCH_VIDEO_MODE_ = MES_CAMERA_EVT_LAUNCH_VIDEO_MODE,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_CAMERA_EVT_START_VIDEO_CAPTURE_ = MES_CAMERA_EVT_START_VIDEO_CAPTURE,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_CAMERA_EVT_STOP_PHOTO_MODE_ = MES_CAMERA_EVT_STOP_PHOTO_MODE,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_CAMERA_EVT_STOP_VIDEO_CAPTURE_ = MES_CAMERA_EVT_STOP_VIDEO_CAPTURE,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_CAMERA_EVT_STOP_VIDEO_MODE_ = MES_CAMERA_EVT_STOP_VIDEO_MODE,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_CAMERA_EVT_TAKE_PHOTO_ = MES_CAMERA_EVT_TAKE_PHOTO,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_CAMERA_EVT_TOGGLE_FRONT_REAR_ = MES_CAMERA_EVT_TOGGLE_FRONT_REAR,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DEVICE_DISPLAY_OFF_ = MES_DEVICE_DISPLAY_OFF,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DEVICE_DISPLAY_ON_ = MES_DEVICE_DISPLAY_ON,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DEVICE_GESTURE_DEVICE_SHAKEN_ = MES_DEVICE_GESTURE_DEVICE_SHAKEN,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DEVICE_INCOMING_CALL_ = MES_DEVICE_INCOMING_CALL,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DEVICE_INCOMING_MESSAGE_ = MES_DEVICE_INCOMING_MESSAGE,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DEVICE_ORIENTATION_LANDSCAPE_ = MES_DEVICE_ORIENTATION_LANDSCAPE,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DEVICE_ORIENTATION_PORTRAIT_ = MES_DEVICE_ORIENTATION_PORTRAIT,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_1_DOWN_ = MES_DPAD_BUTTON_1_DOWN,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_1_UP_ = MES_DPAD_BUTTON_1_UP,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_2_DOWN_ = MES_DPAD_BUTTON_2_DOWN,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_2_UP_ = MES_DPAD_BUTTON_2_UP,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_3_DOWN_ = MES_DPAD_BUTTON_3_DOWN,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_3_UP_ = MES_DPAD_BUTTON_3_UP,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_4_DOWN_ = MES_DPAD_BUTTON_4_DOWN,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_4_UP_ = MES_DPAD_BUTTON_4_UP,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_A_DOWN_ = MES_DPAD_BUTTON_A_DOWN,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_A_UP_ = MES_DPAD_BUTTON_A_UP,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_B_DOWN_ = MES_DPAD_BUTTON_B_DOWN,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_B_UP_ = MES_DPAD_BUTTON_B_UP,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_C_DOWN_ = MES_DPAD_BUTTON_C_DOWN,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_C_UP_ = MES_DPAD_BUTTON_C_UP,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_D_DOWN_ = MES_DPAD_BUTTON_D_DOWN,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_DPAD_BUTTON_D_UP_ = MES_DPAD_BUTTON_D_UP,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_REMOTE_CONTROL_EVT_FORWARD_ = MES_REMOTE_CONTROL_EVT_FORWARD,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_REMOTE_CONTROL_EVT_NEXTTRACK_ = MES_REMOTE_CONTROL_EVT_NEXTTRACK,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_REMOTE_CONTROL_EVT_PAUSE_ = MES_REMOTE_CONTROL_EVT_PAUSE,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_REMOTE_CONTROL_EVT_PLAY_ = MES_REMOTE_CONTROL_EVT_PLAY,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_REMOTE_CONTROL_EVT_PREVTRACK_ = MES_REMOTE_CONTROL_EVT_PREVTRACK,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_REMOTE_CONTROL_EVT_REWIND_ = MES_REMOTE_CONTROL_EVT_REWIND,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_REMOTE_CONTROL_EVT_STOP_ = MES_REMOTE_CONTROL_EVT_STOP,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_REMOTE_CONTROL_EVT_VOLUMEDOWN_ = MES_REMOTE_CONTROL_EVT_VOLUMEDOWN,
|
2017-12-14 20:00:47 +01:00
|
|
|
//% blockIdentity="control.eventValueId"
|
2016-04-02 02:45:18 +02:00
|
|
|
MES_REMOTE_CONTROL_EVT_VOLUMEUP_ = MES_REMOTE_CONTROL_EVT_VOLUMEUP,
|
|
|
|
};
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
enum EventFlags {
|
|
|
|
//%
|
|
|
|
QueueIfBusy = MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY,
|
|
|
|
//%
|
|
|
|
DropIfBusy = MESSAGE_BUS_LISTENER_DROP_IF_BUSY,
|
|
|
|
//%
|
|
|
|
Reentrant = MESSAGE_BUS_LISTENER_REENTRANT
|
|
|
|
};
|
|
|
|
|
2016-04-02 02:45:18 +02:00
|
|
|
//% weight=1 color="#333333"
|
2016-10-11 22:48:25 +02:00
|
|
|
//% advanced=true
|
2016-03-30 02:11:17 +02:00
|
|
|
namespace control {
|
|
|
|
void fiberDone(void *a)
|
|
|
|
{
|
|
|
|
decr((Action)a);
|
|
|
|
release_fiber();
|
|
|
|
}
|
|
|
|
|
2020-05-08 18:35:38 +02:00
|
|
|
/**
|
|
|
|
* Gets the number of milliseconds elapsed since power on.
|
|
|
|
*/
|
|
|
|
//% help=control/millis weight=50
|
|
|
|
//% blockId=control_running_time block="millis (ms)"
|
|
|
|
int millis() {
|
|
|
|
return system_timer_current_time();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets current time in microseconds. Overflows every ~18 minutes.
|
|
|
|
*/
|
|
|
|
//%
|
|
|
|
int micros() {
|
|
|
|
return system_timer_current_time_us() & 0x3fffffff;
|
|
|
|
}
|
|
|
|
|
2016-03-30 02:11:17 +02:00
|
|
|
/**
|
|
|
|
* Schedules code that run in the background.
|
|
|
|
*/
|
2017-12-14 20:00:47 +01:00
|
|
|
//% help=control/in-background blockAllowMultiple=1 afterOnStart=true
|
2016-03-30 02:11:17 +02:00
|
|
|
//% blockId="control_in_background" block="run in background" blockGap=8
|
|
|
|
void inBackground(Action a) {
|
2019-12-02 05:58:26 +01:00
|
|
|
runInParallel(a);
|
2016-03-30 02:11:17 +02:00
|
|
|
}
|
|
|
|
|
2020-05-08 18:35:38 +02:00
|
|
|
/**
|
|
|
|
* Blocks the calling thread until the specified event is raised.
|
|
|
|
*/
|
|
|
|
//% help=control/wait-for-event async
|
|
|
|
//% blockId=control_wait_for_event block="wait for event|from %src|with value %value"
|
|
|
|
void waitForEvent(int src, int value) {
|
|
|
|
pxt::waitForEvent(src, value);
|
|
|
|
}
|
|
|
|
|
2016-03-30 02:11:17 +02:00
|
|
|
/**
|
|
|
|
* Resets the BBC micro:bit.
|
|
|
|
*/
|
2016-08-17 02:04:21 +02:00
|
|
|
//% weight=30 async help=control/reset blockGap=8
|
2016-03-30 02:11:17 +02:00
|
|
|
//% blockId="control_reset" block="reset"
|
2016-10-11 22:48:25 +02:00
|
|
|
void reset() {
|
2016-04-19 20:52:44 +02:00
|
|
|
microbit_reset();
|
2016-03-30 02:11:17 +02:00
|
|
|
}
|
2016-04-02 02:45:18 +02:00
|
|
|
|
2016-08-17 02:04:21 +02:00
|
|
|
/**
|
|
|
|
* Blocks the current fiber for the given microseconds
|
|
|
|
* @param micros number of micro-seconds to wait. eg: 4
|
|
|
|
*/
|
2021-11-25 17:27:39 +01:00
|
|
|
//% help=control/wait-micros weight=29 async
|
2016-08-17 02:04:21 +02:00
|
|
|
//% blockId="control_wait_us" block="wait (µs)%micros"
|
2021-11-25 17:27:39 +01:00
|
|
|
//% micros.min=0 micros.max=6000
|
2016-08-17 02:04:21 +02:00
|
|
|
void waitMicros(int micros) {
|
2020-08-19 22:03:58 +02:00
|
|
|
sleep_us(micros);
|
2016-08-17 02:04:21 +02:00
|
|
|
}
|
|
|
|
|
2016-04-02 02:45:18 +02:00
|
|
|
/**
|
|
|
|
* Raises an event in the event bus.
|
|
|
|
* @param src ID of the MicroBit Component that generated the event e.g. MICROBIT_ID_BUTTON_A.
|
|
|
|
* @param value Component specific code indicating the cause of the event.
|
2016-04-14 23:29:28 +02:00
|
|
|
* @param mode optional definition of how the event should be processed after construction (default is CREATE_AND_FIRE).
|
2016-04-02 02:45:18 +02:00
|
|
|
*/
|
2016-05-17 01:24:44 +02:00
|
|
|
//% weight=21 blockGap=12 blockId="control_raise_event" block="raise event|from source %src=control_event_source_id|with value %value=control_event_value_id" blockExternalInputs=1
|
2017-12-14 20:00:47 +01:00
|
|
|
//% help=control/raise-event
|
2016-04-14 23:29:28 +02:00
|
|
|
//% mode.defl=CREATE_AND_FIRE
|
2016-10-11 22:48:25 +02:00
|
|
|
void raiseEvent(int src, int value, EventCreationMode mode) {
|
|
|
|
MicroBitEvent evt(src, value, (MicroBitEventLaunchMode)mode);
|
2016-04-02 04:55:51 +02:00
|
|
|
}
|
2016-04-02 02:45:18 +02:00
|
|
|
|
|
|
|
/**
|
2019-12-02 05:58:26 +01:00
|
|
|
* Registers an event handler.
|
2016-04-02 02:45:18 +02:00
|
|
|
*/
|
2016-10-11 22:48:25 +02:00
|
|
|
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src=control_event_source_id|with value %value=control_event_value_id"
|
2017-12-14 20:00:47 +01:00
|
|
|
//% help=control/on-event
|
2016-04-18 22:31:05 +02:00
|
|
|
//% blockExternalInputs=1
|
2019-12-02 05:58:26 +01:00
|
|
|
void onEvent(int src, int value, Action handler, int flags = 0) {
|
2020-08-19 22:03:58 +02:00
|
|
|
if (!flags) flags = ::EventFlags::QueueIfBusy;
|
2019-12-02 05:58:26 +01:00
|
|
|
registerWithDal(src, value, handler, (int)flags);
|
2016-04-02 04:59:14 +02:00
|
|
|
}
|
2016-05-17 01:24:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the value of the last event executed on the bus
|
|
|
|
*/
|
|
|
|
//% blockId=control_event_value" block="event value"
|
2017-12-14 20:00:47 +01:00
|
|
|
//% help=control/event-value
|
2016-05-17 01:24:44 +02:00
|
|
|
//% weight=18
|
|
|
|
int eventValue() {
|
|
|
|
return pxt::lastEvent.value;
|
|
|
|
}
|
2016-10-11 22:48:25 +02:00
|
|
|
|
2016-05-17 01:24:44 +02:00
|
|
|
/**
|
|
|
|
* Gets the timestamp of the last event executed on the bus
|
|
|
|
*/
|
|
|
|
//% blockId=control_event_timestamp" block="event timestamp"
|
2017-12-14 20:00:47 +01:00
|
|
|
//% help=control/event-timestamp
|
2016-05-17 18:36:01 +02:00
|
|
|
//% weight=19 blockGap=8
|
2016-05-17 01:24:44 +02:00
|
|
|
int eventTimestamp() {
|
|
|
|
return pxt::lastEvent.timestamp;
|
|
|
|
}
|
2016-10-11 22:48:25 +02:00
|
|
|
|
2016-04-26 22:43:02 +02:00
|
|
|
/**
|
2019-12-02 05:58:26 +01:00
|
|
|
* Make a friendly name for the device based on its serial number
|
2016-04-26 22:43:02 +02:00
|
|
|
*/
|
2016-04-28 19:46:03 +02:00
|
|
|
//% blockId="control_device_name" block="device name" weight=10 blockGap=8
|
2020-08-19 22:03:58 +02:00
|
|
|
//% help=control/device-name
|
2017-12-14 20:00:47 +01:00
|
|
|
//% advanced=true
|
2019-12-02 05:58:26 +01:00
|
|
|
String deviceName() {
|
|
|
|
return mkString(microbit_friendly_name(), -1);
|
2016-04-26 22:43:02 +02:00
|
|
|
}
|
2016-10-11 22:48:25 +02:00
|
|
|
|
2016-04-27 02:09:15 +02:00
|
|
|
/**
|
|
|
|
* Derive a unique, consistent serial number of this device from internal data.
|
|
|
|
*/
|
2016-04-28 19:46:03 +02:00
|
|
|
//% blockId="control_device_serial_number" block="device serial number" weight=9
|
2020-08-19 22:03:58 +02:00
|
|
|
//% help=control/device-serial-number
|
2017-12-14 20:00:47 +01:00
|
|
|
//% advanced=true
|
2016-04-27 02:09:15 +02:00
|
|
|
int deviceSerialNumber() {
|
|
|
|
return microbit_serial_number();
|
|
|
|
}
|
2019-12-02 05:58:26 +01:00
|
|
|
|
2021-11-25 17:27:39 +01:00
|
|
|
/**
|
|
|
|
* Derive a unique, consistent 64-bit serial number of this device from internal data.
|
|
|
|
*/
|
|
|
|
//% help=control/device-long-serial-number
|
|
|
|
//% advanced=true
|
|
|
|
Buffer deviceLongSerialNumber() {
|
|
|
|
return mkBuffer((uint8_t*)&NRF_FICR->DEVICEID[0], sizeof(uint64_t));
|
|
|
|
}
|
|
|
|
|
2019-12-02 05:58:26 +01:00
|
|
|
/**
|
|
|
|
* Informs simulator/runtime of a MIDI message
|
|
|
|
* Internal function to support the simulator.
|
|
|
|
*/
|
|
|
|
//% part=midioutput blockHidden=1
|
|
|
|
void __midiSend(Buffer buffer) {
|
|
|
|
// this is a stub to support the simulator
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
//%
|
2021-11-25 17:27:39 +01:00
|
|
|
void __log(int priority, String text) {
|
2019-12-02 05:58:26 +01:00
|
|
|
if (NULL == text) return;
|
|
|
|
pxt::sendSerial(text->getUTF8Data(), text->getUTF8Size());
|
|
|
|
}
|
2021-11-25 17:27:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates the next user notification event
|
|
|
|
*/
|
|
|
|
//% help=control/allocate-notify-event
|
|
|
|
int allocateNotifyEvent() {
|
|
|
|
#if MICROBIT_CODAL
|
|
|
|
return ::allocateNotifyEvent();
|
|
|
|
#else
|
|
|
|
static int notifyEv = 1024;
|
|
|
|
return ++notifyEv;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Write a message to DMESG debugging buffer. */
|
|
|
|
//%
|
|
|
|
void dmesg(String s) {
|
|
|
|
// this is no-op on v1
|
|
|
|
DMESG("# %s", s->getUTF8Data());
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Write a message and value (pointer) to DMESG debugging buffer. */
|
|
|
|
//%
|
|
|
|
void dmesgPtr(String str, Object_ ptr) {
|
|
|
|
// this is no-op on v1
|
|
|
|
DMESG("# %s: %p", str->getUTF8Data(), ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
//%
|
|
|
|
uint32_t _ramSize()
|
|
|
|
{
|
|
|
|
return (uint32_t)&__StackTop & 0x1fffffff;
|
|
|
|
}
|
|
|
|
|
2016-03-30 02:11:17 +02:00
|
|
|
}
|