support for is-gesture (#1873)
* support for is-gesture * updated shims * activate shake button * refactor * refactor shake button
This commit is contained in:
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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
10
libs/core/shims.d.ts
vendored
@ -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
|
||||
|
Reference in New Issue
Block a user