support for 8G gestures

This commit is contained in:
Peli de Halleux
2016-12-20 13:05:06 -08:00
parent 4ebe9f595a
commit 3141e12f4c
3 changed files with 17 additions and 4 deletions

View File

@ -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);
}
/**