moving devices implementations to js to get simulator support (#403)
This commit is contained in:
parent
cc58a74471
commit
06217d18c8
@ -125,62 +125,6 @@ enum class MesDpadButtonInfo {
|
||||
*/
|
||||
//% color=#008272 weight=80 icon="\uf10b"
|
||||
namespace devices {
|
||||
static void genEvent(int id, int event) {
|
||||
MicroBitEvent e(id, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a ``camera`` command to the parent device.
|
||||
* @param event event description
|
||||
*/
|
||||
//% weight=30 help=devices/tell-camera-to
|
||||
//% blockId=devices_camera icon="\uf030" block="tell camera to|%property" blockGap=8
|
||||
void tellCameraTo(MesCameraEvent event) {
|
||||
genEvent(MES_CAMERA_ID, (int)event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a ``remote control`` command to the parent device.
|
||||
* @param event event description
|
||||
*/
|
||||
//% weight=29 help=devices/tell-remote-control-to
|
||||
//% blockId=devices_remote_control block="tell remote control to|%property" blockGap=14 icon="\uf144"
|
||||
void tellRemoteControlTo(MesRemoteControlEvent event) {
|
||||
genEvent(MES_REMOTE_CONTROL_ID, (int)event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an ``alert`` command to the parent device.
|
||||
* @param event event description
|
||||
*/
|
||||
//% weight=27 help=devices/raise-alert-to
|
||||
//% blockId=devices_alert block="raise alert to|%property" icon="\uf0f3"
|
||||
void raiseAlertTo(MesAlertEvent event) {
|
||||
genEvent(MES_ALERTS_ID, (int)event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers code to run when the device notifies about a particular event.
|
||||
* @param event event description
|
||||
* @param body code handler when event is triggered
|
||||
*/
|
||||
//% help=devices/on-notified weight=26
|
||||
//% blockId=devices_device_info_event block="on notified|%event" icon="\uf10a"
|
||||
void onNotified(MesDeviceInfo event, Action body) {
|
||||
registerWithDal(MES_DEVICE_INFO_ID, (int)event, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register code to run when the micro:bit receives a command from the paired gamepad.
|
||||
* @param name button name
|
||||
* @param body code to run when button is pressed
|
||||
*/
|
||||
//% help=devices/on-gamepad-button weight=40
|
||||
//% weight=25
|
||||
//% blockId=devices_gamepad_event block="on gamepad button|%NAME" icon="\uf11b"
|
||||
void onGamepadButton(MesDpadButtonInfo name, Action body) {
|
||||
registerWithDal(MES_DPAD_CONTROLLER_ID, (int)name, body);
|
||||
}
|
||||
|
||||
static int _signalStrength = -1;
|
||||
static void signalStrengthHandler(MicroBitEvent ev) {
|
||||
|
55
libs/devices/devices.ts
Normal file
55
libs/devices/devices.ts
Normal file
@ -0,0 +1,55 @@
|
||||
|
||||
namespace devices {
|
||||
/**
|
||||
* Sends a ``camera`` command to the parent device.
|
||||
* @param event event description
|
||||
*/
|
||||
//% weight=30 help=devices/tell-camera-to
|
||||
//% blockId=devices_camera icon="\uf030" block="tell camera to|%property" blockGap=8
|
||||
export function tellCameraTo(event: MesCameraEvent) {
|
||||
control.raiseEvent(DAL.MES_CAMERA_ID, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a ``remote control`` command to the parent device.
|
||||
* @param event event description
|
||||
*/
|
||||
//% weight=29 help=devices/tell-remote-control-to
|
||||
//% blockId=devices_remote_control block="tell remote control to|%property" blockGap=14 icon="\uf144"
|
||||
export function tellRemoteControlTo(event: MesRemoteControlEvent) {
|
||||
control.raiseEvent(DAL.MES_REMOTE_CONTROL_ID, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an ``alert`` command to the parent device.
|
||||
* @param event event description
|
||||
*/
|
||||
//% weight=27 help=devices/raise-alert-to
|
||||
//% blockId=devices_alert block="raise alert to|%property" icon="\uf0f3"
|
||||
export function raiseAlertTo(event: MesAlertEvent) {
|
||||
control.raiseEvent(DAL.MES_ALERTS_ID, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers code to run when the device notifies about a particular event.
|
||||
* @param event event description
|
||||
* @param body code handler when event is triggered
|
||||
*/
|
||||
//% help=devices/on-notified weight=26
|
||||
//% blockId=devices_device_info_event block="on notified|%event" icon="\uf10a"
|
||||
export function onNotified(event: MesDeviceInfo, body: Action) {
|
||||
control.onEvent(DAL.MES_DEVICE_INFO_ID, event, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register code to run when the micro:bit receives a command from the paired gamepad.
|
||||
* @param name button name
|
||||
* @param body code to run when button is pressed
|
||||
*/
|
||||
//% help=devices/on-gamepad-button weight=40
|
||||
//% weight=25
|
||||
//% blockId=devices_gamepad_event block="on gamepad button|%NAME" icon="\uf11b"
|
||||
export function onGamepadButton(name: MesDpadButtonInfo, body: Action) {
|
||||
control.onEvent(DAL.MES_DPAD_CONTROLLER_ID, name, body);
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
"enums.d.ts",
|
||||
"shims.d.ts",
|
||||
"devices.cpp",
|
||||
"devices.ts",
|
||||
"_locales/fr/devices-jsdoc-strings.json",
|
||||
"_locales/no/devices-strings.json",
|
||||
"_locales/ja/devices-strings.json",
|
||||
|
43
libs/devices/shims.d.ts
vendored
43
libs/devices/shims.d.ts
vendored
@ -7,49 +7,6 @@
|
||||
//% color=#008272 weight=80 icon="\uf10b"
|
||||
declare namespace devices {
|
||||
|
||||
/**
|
||||
* Sends a ``camera`` command to the parent device.
|
||||
* @param event event description
|
||||
*/
|
||||
//% weight=30 help=devices/tell-camera-to
|
||||
//% blockId=devices_camera icon="\uf030" block="tell camera to|%property" blockGap=8 shim=devices::tellCameraTo
|
||||
function tellCameraTo(event: MesCameraEvent): void;
|
||||
|
||||
/**
|
||||
* Sends a ``remote control`` command to the parent device.
|
||||
* @param event event description
|
||||
*/
|
||||
//% weight=29 help=devices/tell-remote-control-to
|
||||
//% blockId=devices_remote_control block="tell remote control to|%property" blockGap=14 icon="\uf144" shim=devices::tellRemoteControlTo
|
||||
function tellRemoteControlTo(event: MesRemoteControlEvent): void;
|
||||
|
||||
/**
|
||||
* Sends an ``alert`` command to the parent device.
|
||||
* @param event event description
|
||||
*/
|
||||
//% weight=27 help=devices/raise-alert-to
|
||||
//% blockId=devices_alert block="raise alert to|%property" icon="\uf0f3" shim=devices::raiseAlertTo
|
||||
function raiseAlertTo(event: MesAlertEvent): void;
|
||||
|
||||
/**
|
||||
* Registers code to run when the device notifies about a particular event.
|
||||
* @param event event description
|
||||
* @param body code handler when event is triggered
|
||||
*/
|
||||
//% help=devices/on-notified weight=26
|
||||
//% blockId=devices_device_info_event block="on notified|%event" icon="\uf10a" shim=devices::onNotified
|
||||
function onNotified(event: MesDeviceInfo, body: () => void): void;
|
||||
|
||||
/**
|
||||
* Register code to run when the micro:bit receives a command from the paired gamepad.
|
||||
* @param name button name
|
||||
* @param body code to run when button is pressed
|
||||
*/
|
||||
//% help=devices/on-gamepad-button weight=40
|
||||
//% weight=25
|
||||
//% blockId=devices_gamepad_event block="on gamepad button|%NAME" icon="\uf11b" shim=devices::onGamepadButton
|
||||
function onGamepadButton(name: MesDpadButtonInfo, body: () => void): void;
|
||||
|
||||
/**
|
||||
* Returns the last signal strength reported by the paired device.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user