support for 8G gestures
This commit is contained in:
parent
4ebe9f595a
commit
3141e12f4c
@ -33,6 +33,8 @@
|
||||
"DisplayMode.Greyscale|block": "greyscale",
|
||||
"EventCreationMode.CreateAndFire": "MicroBitEvent is initialised, and its event handlers are immediately fired (not suitable for use in interrupts!).",
|
||||
"EventCreationMode.CreateOnly": "MicroBitEvent is initialised, and no further processing takes place.",
|
||||
"Gesture.EightG": "Raised when a 8G shock is detected",
|
||||
"Gesture.EightG|block": "8g",
|
||||
"Gesture.FreeFall": "Raised when the board is falling!",
|
||||
"Gesture.FreeFall|block": "free fall",
|
||||
"Gesture.LogoDown": "Raised when the logo is downward and the screen is vertical",
|
||||
|
5
libs/core/enums.d.ts
vendored
5
libs/core/enums.d.ts
vendored
@ -115,6 +115,11 @@ declare namespace basic {
|
||||
*/
|
||||
//% block="6g"
|
||||
SixG = 9, // MICROBIT_ACCELEROMETER_EVT_6G
|
||||
/**
|
||||
* Raised when a 8G shock is detected
|
||||
*/
|
||||
//% block="8g"
|
||||
EightG = 10, // MICROBIT_ACCELEROMETER_EVT_8G
|
||||
}
|
||||
declare namespace input {
|
||||
}
|
||||
|
@ -104,7 +104,12 @@ enum class Gesture {
|
||||
* Raised when a 6G shock is detected
|
||||
*/
|
||||
//% block="6g"
|
||||
SixG = MICROBIT_ACCELEROMETER_EVT_6G
|
||||
SixG = MICROBIT_ACCELEROMETER_EVT_6G,
|
||||
/**
|
||||
* Raised when a 8G shock is detected
|
||||
*/
|
||||
//% block="8g"
|
||||
EightG = MICROBIT_ACCELEROMETER_EVT_8G
|
||||
};
|
||||
|
||||
//% color=300 weight=99
|
||||
@ -130,11 +135,12 @@ namespace input {
|
||||
//% blockId=device_gesture_event block="on |%NAME" icon="\uf135"
|
||||
//% parts="accelerometer"
|
||||
void onGesture(Gesture gesture, Action body) {
|
||||
if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3)
|
||||
int gi = (int)gesture;
|
||||
if (gi == MICROBIT_ACCELEROMETER_EVT_3G && uBit.accelerometer.getRange() < 3)
|
||||
uBit.accelerometer.setRange(4);
|
||||
else if ((int)gesture == MICROBIT_ACCELEROMETER_EVT_6G && uBit.accelerometer.getRange() < 6)
|
||||
else if ((gi == MICROBIT_ACCELEROMETER_EVT_6G || gi == MICROBIT_ACCELEROMETER_EVT_8G) && uBit.accelerometer.getRange() < 6)
|
||||
uBit.accelerometer.setRange(8);
|
||||
registerWithDal(MICROBIT_ID_GESTURE, (int)gesture, body);
|
||||
registerWithDal(MICROBIT_ID_GESTURE, gi, body);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user