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

@ -12,7 +12,7 @@ Tell everyone who you are. Show you name on the LEDs.
Let's build a **LOVE METER** machine. Place an ``||input:on pin pressed||`` block to run code when pin **0** is pressed. Use ``P0`` from the list of pin inputs. Let's build a **LOVE METER** machine. Place an ``||input:on pin pressed||`` block to run code when pin **0** is pressed. Use ``P0`` from the list of pin inputs.
```blocks ```blocks
input.onPinEvent(TouchPin.P0, Button.Click, () => { input.onPinTouched(TouchPin.P0, Button.Click, () => {
}); });
``` ```
@ -21,7 +21,7 @@ input.onPinEvent(TouchPin.P0, Button.Click, () => {
Using ``||basic:show number||`` and ``||Math:pick random||`` blocks, show a random number from `0` to `100` when pin **0** is pressed. Using ``||basic:show number||`` and ``||Math:pick random||`` blocks, show a random number from `0` to `100` when pin **0** is pressed.
```blocks ```blocks
input.onPinEvent(TouchPin.P0, Button.Click, () => { input.onPinTouched(TouchPin.P0, Button.Click, () => {
basic.showNumber(Math.randomRange(0, 100)); basic.showNumber(Math.randomRange(0, 100));
}); });
``` ```
@ -35,7 +35,7 @@ Show ``"LOVE METER"`` on the screen when the @boardname@ starts.
```blocks ```blocks
basic.showString("LOVE METER"); basic.showString("LOVE METER");
input.onPinEvent(TouchPin.P0, Button.Click, () => { input.onPinTouched(TouchPin.P0, Button.Click, () => {
basic.showNumber(Math.randomRange(0, 100)); basic.showNumber(Math.randomRange(0, 100));
}); });
``` ```

View File

@ -9,7 +9,7 @@ input.input.onButtonEvent(Button.A, ButtonEvent.Click, () => {
input.onGesture(Gesture.Shake, () => { input.onGesture(Gesture.Shake, () => {
}); });
input.onPinEvent(TouchPin.P0, Button.Click, () => { input.onPinTouched(TouchPin.P0, Button.Click, () => {
}); });
input.buttonIsPressed(Button.A); input.buttonIsPressed(Button.A);

View File

@ -14,7 +14,7 @@ through your body and back into the @boardname@. This is called
**completing a circuit**. It's like you're a big wire! **completing a circuit**. It's like you're a big wire!
```sig ```sig
input.onPinEvent(TouchPin.P0, Button.Click, () => { input.onPinTouched(TouchPin.P0, Button.Click, () => {
}) })
``` ```
@ -43,7 +43,7 @@ Every time you press the pin, the program shows the number of times on the scree
```blocks ```blocks
let count = 0 let count = 0
basic.showNumber(count) basic.showNumber(count)
input.onPinEvent(TouchPin.P0, Button.Click, () => { input.onPinTouched(TouchPin.P0, Button.Click, () => {
count = count + 1 count = count + 1
basic.showNumber(count) basic.showNumber(count)
}) })

View File

@ -13,7 +13,7 @@ through your body and back into the @boardname@. This is called
**completing a circuit**. It's like you're a big wire! **completing a circuit**. It's like you're a big wire!
```sig ```sig
input.onPinEvent(TouchPin.P0, ButtonEvent.Click, () => { input.onPinTouched(TouchPin.P0, ButtonEvent.Click, () => {
}) })
``` ```
@ -36,7 +36,7 @@ Every time you release the pin, the program shows the number of times on the scr
```blocks ```blocks
let count = 0 let count = 0
basic.showNumber(count, 100) basic.showNumber(count, 100)
input.onPinEvent(TouchPin.P0, ButtonEvent.Click, () => { input.onPinTouched(TouchPin.P0, ButtonEvent.Click, () => {
count = count + 1 count = count + 1
basic.showNumber(count, 100) basic.showNumber(count, 100)
}) })

View File

@ -380,6 +380,9 @@
"input.onButtonEvent|param|body": "code to run when event is raised", "input.onButtonEvent|param|body": "code to run when event is raised",
"input.onButtonEvent|param|button": "the button", "input.onButtonEvent|param|button": "the button",
"input.onButtonEvent|param|eventType": "event Type", "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": "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|body": "code to run when gesture is raised",
"input.onGesture|param|gesture": "the type of gesture to track, eg: Gesture.Shake", "input.onGesture|param|gesture": "the type of gesture to track, eg: Gesture.Shake",
@ -387,9 +390,15 @@
"input.onLogoDown|param|body": "TODO", "input.onLogoDown|param|body": "TODO",
"input.onLogoUp": "Attaches code to run when the logo is oriented upwards and the board is vertical.", "input.onLogoUp": "Attaches code to run when the logo is oriented upwards and the board is vertical.",
"input.onLogoUp|param|body": "TODO", "input.onLogoUp|param|body": "TODO",
"input.onPinEvent": "Do something when a pin is touched and released again (while also touching the GND pin).", "input.onPinTouched": "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.onPinTouched|param|body": "the code to run when event is fired on pin",
"input.onPinEvent|param|name": "the pin, eg: TouchPin.P0", "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": "Attaches code to run when the screen is facing down.",
"input.onScreenDown|param|body": "TODO", "input.onScreenDown|param|body": "TODO",
"input.onScreenUp": "Attaches code to run when the screen is facing up.", "input.onScreenUp": "Attaches code to run when the screen is facing up.",

View File

@ -311,8 +311,11 @@
"input.lightLevel|block": "light level", "input.lightLevel|block": "light level",
"input.magneticForce|block": "magnetic force (µT)|%NAME", "input.magneticForce|block": "magnetic force (µT)|%NAME",
"input.onButtonEvent|block": "on button %NAME| is %eventType=control_button_event_value_id", "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.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.pinIsPressed|block": "pin %NAME|is pressed",
"input.rotation|block": "rotation (°)|%NAME", "input.rotation|block": "rotation (°)|%NAME",
"input.runningTimeMicros|block": "running time (micros)", "input.runningTimeMicros|block": "running time (micros)",

View File

@ -123,7 +123,7 @@
<block type="device_gesture_event" x="472" y="-8"> <block type="device_gesture_event" x="472" y="-8">
<field name="NAME">Gesture.SixG</field> <field name="NAME">Gesture.SixG</field>
</block> </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> <field name="name">TouchPin.P2</field>
</block> </block>
</xml> </xml>

View File

@ -117,7 +117,7 @@
</block> </block>
</statement> </statement>
</block> </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> <field name="name">TouchPin.P2</field>
<statement name="HANDLER"> <statement name="HANDLER">
<block type="device_led_toggle"> <block type="device_led_toggle">

View File

@ -190,8 +190,17 @@ namespace input {
} }
// Deprecated // 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 name the pin, eg: TouchPin.P0
* @param body the code to run when event is fired on pin * @param body the code to run when event is fired on pin
*/ */
//% help=input/on-pin-event weight=83 blockGap=32 //% help=input/on-pin-touch weight=83 blockGap=32
//% blockId=device_pin_event block="on pin %name|is %eventType=control_button_event_value_id" //% blockId=device_pin_touch block="on pin %name|is %eventType=control_button_event_value_id"
void onPinEvent(TouchPin name, int eventType, Action body) { void onPinTouched(TouchPin name, int eventType, Action body) {
auto pin = getPin((int)name); auto pin = getPin((int)name);
if (!pin) return; if (!pin) return;
@ -244,6 +253,14 @@ namespace input {
} }
// Deprecated // 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) { void onPinPressed(TouchPin name, Action body) {
auto pin = getPin((int)name); auto pin = getPin((int)name);
if (!pin) return; if (!pin) return;
@ -254,6 +271,14 @@ namespace input {
} }
// Deprecated // 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) { void onPinReleased(TouchPin name, Action body) {
auto pin = getPin((int)name); auto pin = getPin((int)name);
if (!pin) return; if (!pin) return;

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

@ -233,6 +233,17 @@ declare namespace input {
//% parts="buttonpair" shim=input::onButtonEvent //% parts="buttonpair" shim=input::onButtonEvent
function onButtonEvent(button: Button, eventType: int32, body: () => void): void; 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). * Do something when when a gesture is done (like shaking the micro:bit).
* @param gesture the type of gesture to track, eg: Gesture.Shake * @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 name the pin, eg: TouchPin.P0
* @param body the code to run when event is fired on pin * @param body the code to run when event is fired on pin
*/ */
//% help=input/on-pin-event weight=83 blockGap=32 //% help=input/on-pin-input weight=83 blockGap=32
//% blockId=device_pin_event block="on pin %name|is %eventType=control_button_event_value_id" shim=input::onPinEvent //% blockId=device_pin_touch block="on pin %name|is %eventType=control_button_event_value_id" shim=input::onPinTouched
function onPinEvent(name: TouchPin, eventType: int32, body: () => void): void; 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``. * Get the button state (pressed or not) for ``A`` and ``B``.

View File

@ -1,5 +1,5 @@
namespace pxsim.input { namespace pxsim.input {
export function onPinEvent(pinId: number, pinEvent: number, handler: RefAction) { export function onPinTouched(pinId: number, pinEvent: number, handler: RefAction) {
let pin = getPin(pinId); let pin = getPin(pinId);
if (!pin) return; if (!pin) return;
pin.isTouched(); pin.isTouched();