bring back deprecated blocks, but hide them

This commit is contained in:
Amerlander
2020-02-20 17:49:58 +01:00
parent 07fe2645cf
commit b91ae2c4b5
11 changed files with 91 additions and 23 deletions

View File

@ -380,6 +380,9 @@
"input.onButtonEvent|param|body": "code to run when event is raised",
"input.onButtonEvent|param|button": "the button",
"input.onButtonEvent|param|eventType": "event Type",
"input.onButtonPressed": "Do something when a button (A, B or both A+B) is pushed down and released again.",
"input.onButtonPressed|param|body": "code to run when event is raised",
"input.onButtonPressed|param|button": "the button that needs to be pressed",
"input.onGesture": "Do something when when a gesture is done (like shaking the micro:bit).",
"input.onGesture|param|body": "code to run when gesture is raised",
"input.onGesture|param|gesture": "the type of gesture to track, eg: Gesture.Shake",
@ -387,9 +390,15 @@
"input.onLogoDown|param|body": "TODO",
"input.onLogoUp": "Attaches code to run when the logo is oriented upwards and the board is vertical.",
"input.onLogoUp|param|body": "TODO",
"input.onPinEvent": "Do something when a pin is touched and released again (while also touching the GND pin).",
"input.onPinEvent|param|body": "the code to run when event is fired on pin",
"input.onPinEvent|param|name": "the pin, eg: TouchPin.P0",
"input.onPinTouched": "Do something when a pin is touched and released again (while also touching the GND pin).",
"input.onPinTouched|param|body": "the code to run when event is fired on pin",
"input.onPinTouched|param|name": "the pin, eg: TouchPin.P0",
"input.onPinPressed": "Do something when a pin is touched and released again (while also touching the GND pin).",
"input.onPinPressed|param|body": "the code to run when the pin is pressed",
"input.onPinPressed|param|name": "the pin that needs to be pressed, eg: TouchPin.P0",
"input.onPinReleased": "Do something when a pin is released.",
"input.onPinReleased|param|body": "the code to run when the pin is released",
"input.onPinReleased|param|name": "the pin that needs to be released, eg: TouchPin.P0",
"input.onScreenDown": "Attaches code to run when the screen is facing down.",
"input.onScreenDown|param|body": "TODO",
"input.onScreenUp": "Attaches code to run when the screen is facing up.",

View File

@ -311,8 +311,11 @@
"input.lightLevel|block": "light level",
"input.magneticForce|block": "magnetic force (µT)|%NAME",
"input.onButtonEvent|block": "on button %NAME| is %eventType=control_button_event_value_id",
"input.onButtonPressed|block": "on button|%NAME|pressed",
"input.onGesture|block": "on |%NAME",
"input.onPinEvent|block": "on pin %name|is %eventType=control_button_event_value_id",
"input.onPinTouched|block": "on pin %name|is %eventType=control_button_event_value_id",
"input.onPinPressed|block": "on pin %name|pressed",
"input.onPinReleased|block": "on pin %NAME|released",
"input.pinIsPressed|block": "pin %NAME|is pressed",
"input.rotation|block": "rotation (°)|%NAME",
"input.runningTimeMicros|block": "running time (micros)",

View File

@ -123,7 +123,7 @@
<block type="device_gesture_event" x="472" y="-8">
<field name="NAME">Gesture.SixG</field>
</block>
<block type="device_pin_event" x="555" y="96">
<block type="device_pin_touch" x="555" y="96">
<field name="name">TouchPin.P2</field>
</block>
</xml>

View File

@ -117,7 +117,7 @@
</block>
</statement>
</block>
<block type="device_pin_event" x="2407" y="0">
<block type="device_pin_touch" x="2407" y="0">
<field name="name">TouchPin.P2</field>
<statement name="HANDLER">
<block type="device_led_toggle">

View File

@ -190,8 +190,17 @@ namespace input {
}
// Deprecated
void onButtonPressed(Button button, int eventType, Action body) {
registerWithDal((int)button, eventType, body);
/**
* Do something when a button (A, B or both A+B) is pushed down and released again.
* @param button the button that needs to be pressed
* @param body code to run when event is raised
*/
//% help=input/on-button-pressed weight=85 blockGap=16
//% blockId=device_button_pressed block="on button|%NAME|pressed"
//% parts="buttonpair"
//% blockHidden=true
void onButtonPressed(Button button, Action body) {
registerWithDal((int)button, MICROBIT_BUTTON_EVT_CLICK, body);
}
/**
@ -232,9 +241,9 @@ namespace input {
* @param name the pin, eg: TouchPin.P0
* @param body the code to run when event is fired on pin
*/
//% help=input/on-pin-event weight=83 blockGap=32
//% blockId=device_pin_event block="on pin %name|is %eventType=control_button_event_value_id"
void onPinEvent(TouchPin name, int eventType, Action body) {
//% help=input/on-pin-touch weight=83 blockGap=32
//% blockId=device_pin_touch block="on pin %name|is %eventType=control_button_event_value_id"
void onPinTouched(TouchPin name, int eventType, Action body) {
auto pin = getPin((int)name);
if (!pin) return;
@ -244,6 +253,14 @@ namespace input {
}
// Deprecated
/**
* Do something when a pin is touched and released again (while also touching the GND pin).
* @param name the pin that needs to be pressed, eg: TouchPin.P0
* @param body the code to run when the pin is pressed
*/
//% help=input/on-pin-pressed weight=83 blockGap=32
//% blockId=device_pin_input block="on pin %name|pressed"
//% blockHidden=true
void onPinPressed(TouchPin name, Action body) {
auto pin = getPin((int)name);
if (!pin) return;
@ -254,6 +271,14 @@ namespace input {
}
// Deprecated
/**
* Do something when a pin is released.
* @param name the pin that needs to be released, eg: TouchPin.P0
* @param body the code to run when the pin is released
*/
//% help=input/on-pin-released weight=6 blockGap=16
//% blockId=device_pin_released block="on pin %NAME|released"
//% blockHidden=true
void onPinReleased(TouchPin name, Action body) {
auto pin = getPin((int)name);
if (!pin) return;

37
libs/core/shims.d.ts vendored
View File

@ -233,6 +233,17 @@ declare namespace input {
//% parts="buttonpair" shim=input::onButtonEvent
function onButtonEvent(button: Button, eventType: int32, body: () => void): void;
/**
* Do something when a button (A, B or both A+B) is pushed down and released again.
* @param button the button that needs to be pressed
* @param body code to run when event is raised
*/
//% help=input/on-button-pressed weight=85 blockGap=16
//% blockId=device_button_pressed block="on button|%NAME|pressed"
//% parts="buttonpair"
//% blockHidden=true shim=input::onButtonPressed
function onButtonPressed(button: Button, body: () => void): void;
/**
* Do something when when a gesture is done (like shaking the micro:bit).
* @param gesture the type of gesture to track, eg: Gesture.Shake
@ -259,9 +270,29 @@ declare namespace input {
* @param name the pin, eg: TouchPin.P0
* @param body the code to run when event is fired on pin
*/
//% help=input/on-pin-event weight=83 blockGap=32
//% blockId=device_pin_event block="on pin %name|is %eventType=control_button_event_value_id" shim=input::onPinEvent
function onPinEvent(name: TouchPin, eventType: int32, body: () => void): void;
//% help=input/on-pin-input weight=83 blockGap=32
//% blockId=device_pin_touch block="on pin %name|is %eventType=control_button_event_value_id" shim=input::onPinTouched
function onPinTouched(name: TouchPin, eventType: int32, body: () => void): void;
/**
* Do something when a pin is touched and released again (while also touching the GND pin).
* @param name the pin that needs to be pressed, eg: TouchPin.P0
* @param body the code to run when the pin is pressed
*/
//% help=input/on-pin-pressed weight=83 blockGap=32
//% blockId=device_pin_input block="on pin %name|pressed"
//% blockHidden=true shim=input::onPinPressed
function onPinPressed(name: TouchPin, body: () => void): void;
/**
* Do something when a pin is released.
* @param name the pin that needs to be released, eg: TouchPin.P0
* @param body the code to run when the pin is released
*/
//% help=input/on-pin-released weight=6 blockGap=16
//% blockId=device_pin_released block="on pin %NAME|released"
//% blockHidden=true shim=input::onPinReleased
function onPinReleased(name: TouchPin, body: () => void): void;
/**
* Get the button state (pressed or not) for ``A`` and ``B``.