added input.onPinRelease. Fix for #294

This commit is contained in:
Peli de Halleux
2016-08-08 15:23:18 -07:00
parent 825c6d57e7
commit 20d0dd91ad
4 changed files with 89 additions and 9 deletions

View File

@ -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``.
*/

View File

@ -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``.
*/