Convert bluetooth to new style
This commit is contained in:
parent
3ee0c6ea42
commit
53634f4d6a
|
@ -1,6 +1,8 @@
|
||||||
#include "BitVM.h"
|
#include "kindscript.h"
|
||||||
#include "MESEvents.h"
|
#include "MESEvents.h"
|
||||||
|
|
||||||
|
using namespace kindscript;
|
||||||
|
|
||||||
enum class MesCameraEvent {
|
enum class MesCameraEvent {
|
||||||
//% block="take photo"
|
//% block="take photo"
|
||||||
TakePhoto = MES_CAMERA_EVT_TAKE_PHOTO,
|
TakePhoto = MES_CAMERA_EVT_TAKE_PHOTO,
|
||||||
|
@ -119,3 +121,96 @@ enum class MesDpadButtonInfo {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//% color=156 weight=80
|
||||||
|
namespace devices {
|
||||||
|
static void genEvent(int id, int event) {
|
||||||
|
MicroBitEvent e(id, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a ``camera`` command to the parent device.
|
||||||
|
* @param event TODO
|
||||||
|
*/
|
||||||
|
//% 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 TODO
|
||||||
|
*/
|
||||||
|
//% 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 TODO
|
||||||
|
*/
|
||||||
|
//% 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 TODO
|
||||||
|
* @param body TODO
|
||||||
|
*/
|
||||||
|
//% help=devices/on-notified weight=26
|
||||||
|
//% blockId=devices_device_info_event block="on notified" 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 TODO
|
||||||
|
* @param body TODO
|
||||||
|
*/
|
||||||
|
//% help=devices/on-gamepad-button weight=40 shim=micro_bit::onGamepadButton
|
||||||
|
//% 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) {
|
||||||
|
// keep in sync with MESEvents.h
|
||||||
|
_signalStrength = ev.value - 1;
|
||||||
|
}
|
||||||
|
static void initSignalStrength() {
|
||||||
|
if (_signalStrength < 0) {
|
||||||
|
_signalStrength = 0;
|
||||||
|
uBit.MessageBus.listen(MES_SIGNAL_STRENGTH_ID, MICROBIT_EVT_ANY, signalStrengthHandler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the last signal strength reported by the paired device.
|
||||||
|
*/
|
||||||
|
//% help=devices/signal-strength weight=24
|
||||||
|
//% blockId=devices_signal_strength block="signal strength" blockGap=14 icon="\uf012" blockGap=14
|
||||||
|
int signalStrength() {
|
||||||
|
initSignalStrength();
|
||||||
|
return _signalStrength;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers code to run when the device notifies about a change of signal strength.
|
||||||
|
* @param body TODO
|
||||||
|
*/
|
||||||
|
//% shim=micro_bit::onSignalStrengthChanged weight=23 help=devices/on-signal-strength-changed
|
||||||
|
//% blockId=devices_signal_strength_changed_event block="on signal strength changed" icon="\uf012"
|
||||||
|
void onSignalStrengthChanged(Action body) {
|
||||||
|
initSignalStrength();
|
||||||
|
registerWithDal(MES_SIGNAL_STRENGTH_ID, MICROBIT_EVT_ANY, body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
2
libs/microbit-devices/enums.d.ts
vendored
2
libs/microbit-devices/enums.d.ts
vendored
|
@ -121,5 +121,7 @@
|
||||||
//% block="4 up"
|
//% block="4 up"
|
||||||
_4Up = 16, // MES_DPAD_BUTTON_4_UP
|
_4Up = 16, // MES_DPAD_BUTTON_4_UP
|
||||||
}
|
}
|
||||||
|
declare namespace devices {
|
||||||
|
}
|
||||||
|
|
||||||
// Auto-generated. Do not edit. Really.
|
// Auto-generated. Do not edit. Really.
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
"files": [
|
"files": [
|
||||||
"README.md",
|
"README.md",
|
||||||
"enums.d.ts",
|
"enums.d.ts",
|
||||||
"devices.cpp",
|
"shims.d.ts",
|
||||||
"devices.ts"
|
"devices.cpp"
|
||||||
],
|
],
|
||||||
"public": true,
|
"public": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,38 +1,42 @@
|
||||||
|
// Auto-generated. Do not edit.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//% color=156 weight=80
|
//% color=156 weight=80
|
||||||
namespace devices {
|
declare namespace devices {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a ``camera`` command to the parent device.
|
* Sends a ``camera`` command to the parent device.
|
||||||
* @param event TODO
|
* @param event TODO
|
||||||
*/
|
*/
|
||||||
//% weight=30 help=devices/tell-camera-to shim=micro_bit::devices::camera
|
//% weight=30 help=devices/tell-camera-to
|
||||||
//% blockId=devices_camera icon="\uf030" block="tell camera to|%property" blockGap=8
|
//% blockId=devices_camera icon="\uf030" block="tell camera to|%property" blockGap=8 shim=devices::tellCameraTo
|
||||||
export function tellCameraTo(event: MesCameraEvent): void { }
|
function tellCameraTo(event: MesCameraEvent): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a ``remote control`` command to the parent device.
|
* Sends a ``remote control`` command to the parent device.
|
||||||
* @param event TODO
|
* @param event TODO
|
||||||
*/
|
*/
|
||||||
//% weight=29 help=devices/tell-remote-control-to shim=micro_bit::devices::remote_control
|
//% weight=29 help=devices/tell-remote-control-to
|
||||||
//% blockId=devices_remote_control block="tell remote control to|%property" blockGap=14 icon="\uf144"
|
//% blockId=devices_remote_control block="tell remote control to|%property" blockGap=14 icon="\uf144" shim=devices::tellRemoteControlTo
|
||||||
export function tellRemoteControlTo(event: MesRemoteControlEvent): void { }
|
function tellRemoteControlTo(event: MesRemoteControlEvent): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an ``alert`` command to the parent device.
|
* Sends an ``alert`` command to the parent device.
|
||||||
* @param event TODO
|
* @param event TODO
|
||||||
*/
|
*/
|
||||||
//% weight=27 help=devices/raise-alert-to shim=micro_bit::devices::alert
|
//% weight=27 help=devices/raise-alert-to
|
||||||
//% blockId=devices_alert block="raise alert to|%property" icon="\uf0f3"
|
//% blockId=devices_alert block="raise alert to|%property" icon="\uf0f3" shim=devices::raiseAlertTo
|
||||||
export function raiseAlertTo(event: MesAlertEvent): void { }
|
function raiseAlertTo(event: MesAlertEvent): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers code to run when the device notifies about a particular event.
|
* Registers code to run when the device notifies about a particular event.
|
||||||
* @param event TODO
|
* @param event TODO
|
||||||
* @param body TODO
|
* @param body TODO
|
||||||
*/
|
*/
|
||||||
//% shim=micro_bit::onDeviceInfo help=devices/on-notified
|
//% help=devices/on-notified weight=26
|
||||||
//% weight=26
|
//% blockId=devices_device_info_event block="on notified" icon="\uf10a" shim=devices::onNotified
|
||||||
//% blockId=devices_device_info_event block="on notified" icon="\uf10a"
|
function onNotified(event: MesDeviceInfo, body: () => void): void;
|
||||||
export function onNotified(event: MesDeviceInfo, body: Action): void { }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register code to run when the micro:bit receives a command from the paired gamepad.
|
* Register code to run when the micro:bit receives a command from the paired gamepad.
|
||||||
|
@ -41,24 +45,23 @@ namespace devices {
|
||||||
*/
|
*/
|
||||||
//% help=devices/on-gamepad-button weight=40 shim=micro_bit::onGamepadButton
|
//% help=devices/on-gamepad-button weight=40 shim=micro_bit::onGamepadButton
|
||||||
//% weight=25
|
//% weight=25
|
||||||
//% blockId=devices_gamepad_event block="on gamepad button|%NAME" icon="\uf11b"
|
//% blockId=devices_gamepad_event block="on gamepad button|%NAME" icon="\uf11b" shim=devices::onGamepadButton
|
||||||
export function onGamepadButton(name: MesDpadButtonInfo, body: Action): void { }
|
function onGamepadButton(name: MesDpadButtonInfo, body: () => void): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the last signal strength reported by the paired device.
|
* Returns the last signal strength reported by the paired device.
|
||||||
*/
|
*/
|
||||||
//% help=devices/signal-strength weight=24 shim=micro_bit::signalStrength
|
//% help=devices/signal-strength weight=24
|
||||||
//% blockId=devices_signal_strength block="signal strength" blockGap=14 icon="\uf012" blockGap=14
|
//% blockId=devices_signal_strength block="signal strength" blockGap=14 icon="\uf012" blockGap=14 shim=devices::signalStrength
|
||||||
export function signalStrength(): number {
|
function signalStrength(): number;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers code to run when the device notifies about a change of signal strength.
|
* Registers code to run when the device notifies about a change of signal strength.
|
||||||
* @param body TODO
|
* @param body TODO
|
||||||
*/
|
*/
|
||||||
//% shim=micro_bit::onSignalStrengthChanged weight=23 help=devices/on-signal-strength-changed
|
//% shim=micro_bit::onSignalStrengthChanged weight=23 help=devices/on-signal-strength-changed
|
||||||
//% blockId=devices_signal_strength_changed_event block="on signal strength changed" icon="\uf012"
|
//% blockId=devices_signal_strength_changed_event block="on signal strength changed" icon="\uf012" shim=devices::onSignalStrengthChanged
|
||||||
export function onSignalStrengthChanged(body: Action): void { }
|
function onSignalStrengthChanged(body: () => void): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Auto-generated. Do not edit. Really.
|
Loading…
Reference in New Issue
Block a user