added input.onPinRelease. Fix for #294
This commit is contained in:
@ -135,12 +135,12 @@ namespace input {
|
||||
}
|
||||
|
||||
/**
|
||||
* Do something when a pin(``P0``, ``P1`` or both ``P2``) is pressed.
|
||||
* @param name TODO
|
||||
* @param body TODO
|
||||
* Do something when a pin is pressed.
|
||||
* @param name the pin that needs to be pressed
|
||||
* @param body the code to run when the pin is pressed
|
||||
*/
|
||||
//% help=input/on-pin-pressed weight=83
|
||||
//% blockId=device_pin_event block="on pin|%NAME|pressed" icon="\uf094"
|
||||
//% blockId=device_pin_event block="on pin %NAME|pressed" icon="\uf094"
|
||||
void onPinPressed(TouchPin name, Action body) {
|
||||
auto pin = getPin((int)name);
|
||||
if (!pin) return;
|
||||
@ -150,6 +150,22 @@ namespace input {
|
||||
registerWithDal((int)name, MICROBIT_BUTTON_EVT_CLICK, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do something when a pin is released.
|
||||
* @param name the pin that needs to be released
|
||||
* @param body the code to run when the pin is released
|
||||
*/
|
||||
//% help=input/on-pin-released weight=6 blockGap=8
|
||||
//% blockId=device_pin_released block="on pin %NAME|released" icon="\uf094"
|
||||
void onPinReleased(TouchPin name, Action body) {
|
||||
auto pin = getPin((int)name);
|
||||
if (!pin) return;
|
||||
|
||||
// Forces the PIN to switch to makey-makey style detection.
|
||||
pin->isTouched();
|
||||
registerWithDal((int)name, MICROBIT_BUTTON_EVT_UP, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the button state (pressed or not) for ``A`` and ``B``.
|
||||
*/
|
||||
|
17
libs/microbit/shims.d.ts
vendored
17
libs/microbit/shims.d.ts
vendored
@ -213,14 +213,23 @@ declare namespace input {
|
||||
function onGesture(gesture: Gesture, body: () => void): void;
|
||||
|
||||
/**
|
||||
* Do something when a pin(``P0``, ``P1`` or both ``P2``) is pressed.
|
||||
* @param name TODO
|
||||
* @param body TODO
|
||||
* Do something when a pin is pressed.
|
||||
* @param name the pin that needs to be pressed
|
||||
* @param body the code to run when the pin is pressed
|
||||
*/
|
||||
//% help=input/on-pin-pressed weight=83
|
||||
//% blockId=device_pin_event block="on pin|%NAME|pressed" icon="\uf094" shim=input::onPinPressed
|
||||
//% blockId=device_pin_event block="on pin %NAME|pressed" icon="\uf094" 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
|
||||
* @param body the code to run when the pin is released
|
||||
*/
|
||||
//% help=input/on-pin-released weight=6 blockGap=8
|
||||
//% blockId=device_pin_released block="on pin %NAME|released" icon="\uf094" shim=input::onPinReleased
|
||||
function onPinReleased(name: TouchPin, body: () => void): void;
|
||||
|
||||
/**
|
||||
* Get the button state (pressed or not) for ``A`` and ``B``.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user