pxt-calliope/libs/core/input.ts
Amerlander 38cf0ec0c6 Input blocks revision
- add Button and Pin event types
- merge onPinPressed & onPinReleased in new onPinEvent function
- create new onButtonEvent function
2020-02-20 03:24:13 +01:00

68 lines
1.7 KiB
TypeScript

/**
* Events and data from sensors
*/
//% color=#C90072 weight=99
namespace input {
/**
* Returns the value of a C++ runtime constant
*/
//% weight=1 weight=19 blockId="control_button_event_value_id" block="%id"
//% shim=TD_ID advanced=true
export function buttonEventValueId(id: ButtonEvent): number {
return id;
}
/**
* Attaches code to run when the screen is facing up.
* @param body TODO
*/
//% help=input/on-screen-up
export function onScreenUp(body: () => void): void {
onGesture(Gesture.ScreenUp, body);
}
/**
* Attaches code to run when the screen is facing down.
* @param body TODO
*/
//% help=input/on-screen-down
export function onScreenDown(body: () => void): void {
onGesture(Gesture.ScreenDown, body);
}
/**
* Attaches code to run when the device is shaken.
* @param body TODO
*/
//% help=input/on-shake
export function onShake(body: () => void): void {
onGesture(Gesture.Shake, body);
}
/**
* Attaches code to run when the logo is oriented upwards and the board is vertical.
* @param body TODO
*/
//% help=input/on-logo-up
export function onLogoUp(body: () => void): void {
onGesture(Gesture.LogoUp, body);
}
/**
* Attaches code to run when the logo is oriented downwards and the board is vertical.
* @param body TODO
*/
//% help=input/on-logo-down
export function onLogoDown(body: () => void): void {
onGesture(Gesture.LogoDown, body);
}
/**
* Obsolete, use input.calibrateCompass instead.
*/
//% weight=0 help=input/calibrate-compass
export function calibrate() {
input.calibrateCompass();
}
}