support for is-gesture (#1873)

* support for is-gesture

* updated shims

* activate shake button

* refactor

* refactor shake button
This commit is contained in:
Peli de Halleux
2019-03-21 07:40:23 -07:00
committed by GitHub
parent 8890614325
commit d640dc5eed
9 changed files with 96 additions and 11 deletions

View File

@ -340,6 +340,8 @@
"input.calibrate": "Obsolete, use input.calibrateCompass instead.",
"input.calibrateCompass": "Obsolete, compass calibration is automatic.",
"input.compassHeading": "Get the current compass heading in degrees.",
"input.isGesture": "Tests if a gesture is currently detected.",
"input.isGesture|param|gesture": "the type of gesture to detect, eg: Gesture.Shake",
"input.lightLevel": "Reads the light level applied to the LED screen in a range from ``0`` (dark) to ``255`` bright.",
"input.magneticForce": "Get the magnetic force value in ``micro-Teslas`` (``µT``). This function is not supported in the simulator.",
"input.magneticForce|param|dimension": "TODO",

View File

@ -291,6 +291,7 @@
"input.buttonIsPressed|block": "button|%NAME|is pressed",
"input.calibrateCompass|block": "calibrate compass",
"input.compassHeading|block": "compass heading (°)",
"input.isGesture|block": "is %gesture gesture",
"input.lightLevel|block": "light level",
"input.magneticForce|block": "magnetic force (µT)|%NAME",
"input.onButtonPressed|block": "on button|%NAME|pressed",

View File

@ -190,6 +190,19 @@ namespace input {
registerWithDal(MICROBIT_ID_GESTURE, gi, body);
}
/**
* Tests if a gesture is currently detected.
* @param gesture the type of gesture to detect, eg: Gesture.Shake
*/
//% help=input/is-gesture weight=10 blockGap=8
//% blockId=deviceisgesture block="is %gesture gesture"
//% parts="accelerometer"
//% gesture.fieldEditor="gestures" gesture.fieldOptions.columns=4
bool isGesture(Gesture gesture) {
int gi = (int)gesture;
return uBit.accelerometer.getGesture() == gi;
}
/**
* 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

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

@ -228,6 +228,16 @@ declare namespace input {
//% NAME.fieldEditor="gestures" NAME.fieldOptions.columns=4 shim=input::onGesture
function onGesture(gesture: Gesture, body: () => void): void;
/**
* Tests if a gesture is currently detected.
* @param gesture the type of gesture to detect, eg: Gesture.Shake
*/
//% help=input/is-gesture weight=10 blockGap=8
//% blockId=deviceisgesture block="is %gesture gesture"
//% parts="accelerometer"
//% gesture.fieldEditor="gestures" gesture.fieldOptions.columns=4 shim=input::isGesture
function isGesture(gesture: Gesture): boolean;
/**
* 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