Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal by
Revision 39:112df23f039f, committed 2016-07-13
- Comitter:
- LancasterUniversity
- Date:
- Wed Jul 13 12:18:18 2016 +0100
- Parent:
- 38:1a9e8e5e23f2
- Child:
- 40:948486a56c9d
- Commit message:
- Synchronized with git rev 682063dc
Author: Joe Finney
microbit: Replaced BasicGestures enum with #define equivalent [issue #106]
Changed in this revision
--- a/inc/drivers/MicroBitAccelerometer.h Wed Jul 13 12:18:17 2016 +0100
+++ b/inc/drivers/MicroBitAccelerometer.h Wed Jul 13 12:18:18 2016 +0100
@@ -78,6 +78,7 @@
/**
* Gesture events
*/
+#define MICROBIT_ACCELEROMETER_EVT_NONE 0
#define MICROBIT_ACCELEROMETER_EVT_TILT_UP 1
#define MICROBIT_ACCELEROMETER_EVT_TILT_DOWN 2
#define MICROBIT_ACCELEROMETER_EVT_TILT_LEFT 3
@@ -133,22 +134,6 @@
extern const MMA8653SampleRangeConfig MMA8653SampleRange[];
extern const MMA8653SampleRateConfig MMA8653SampleRate[];
-enum BasicGesture
-{
- GESTURE_NONE,
- GESTURE_UP,
- GESTURE_DOWN,
- GESTURE_LEFT,
- GESTURE_RIGHT,
- GESTURE_FACE_UP,
- GESTURE_FACE_DOWN,
- GESTURE_FREEFALL,
- GESTURE_3G,
- GESTURE_6G,
- GESTURE_8G,
- GESTURE_SHAKE
-};
-
struct ShakeHistory
{
uint16_t shaken:1,
@@ -181,8 +166,8 @@
float roll; // Roll of the device, in radians.
uint8_t sigma; // the number of ticks that the instantaneous gesture has been stable.
uint8_t impulseSigma; // the number of ticks since an impulse event has been generated.
- BasicGesture lastGesture; // the last, stable gesture recorded.
- BasicGesture currentGesture; // the instantaneous, unfiltered gesture detected.
+ uint16_t lastGesture; // the last, stable gesture recorded.
+ uint16_t currentGesture; // the instantaneous, unfiltered gesture detected.
ShakeHistory shake; // State information needed to detect shake events.
public:
@@ -382,7 +367,7 @@
* display.scroll("SHAKE!");
* @endcode
*/
- BasicGesture getGesture();
+ uint16_t getGesture();
/**
* A periodic callback invoked by the fiber scheduler idle thread.
@@ -466,7 +451,7 @@
*
* @return A 'best guess' of the current posture of the device, based on instanataneous data.
*/
- BasicGesture instantaneousPosture();
+ uint16_t instantaneousPosture();
};
#endif
\ No newline at end of file
--- a/source/drivers/MicroBitAccelerometer.cpp Wed Jul 13 12:18:17 2016 +0100
+++ b/source/drivers/MicroBitAccelerometer.cpp Wed Jul 13 12:18:18 2016 +0100
@@ -190,14 +190,13 @@
// Initialise gesture history
this->sigma = 0;
this->impulseSigma = 0;
- this->lastGesture = GESTURE_NONE;
- this->currentGesture = GESTURE_NONE;
+ this->lastGesture = MICROBIT_ACCELEROMETER_EVT_NONE;
+ this->currentGesture = MICROBIT_ACCELEROMETER_EVT_NONE;
this->shake.x = 0;
this->shake.y = 0;
this->shake.z = 0;
this->shake.count = 0;
this->shake.timer = 0;
- this->shake.tap = 1;
this->shake.impulse_3 = 1;
this->shake.impulse_6 = 1;
this->shake.impulse_8 = 1;
@@ -321,7 +320,7 @@
*
* @return A 'best guess' of the current posture of the device, based on instanataneous data.
*/
-BasicGesture MicroBitAccelerometer::instantaneousPosture()
+uint16_t MicroBitAccelerometer::instantaneousPosture()
{
bool shakeDetected = false;
@@ -366,28 +365,28 @@
// Shake events take the highest priority, as under high levels of change, other events
// are likely to be transient.
if (shake.shaken)
- return GESTURE_SHAKE;
+ return MICROBIT_ACCELEROMETER_EVT_SHAKE;
// Determine our posture.
if (getX() < (-1000 + MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
- return GESTURE_LEFT;
+ return MICROBIT_ACCELEROMETER_EVT_TILT_LEFT;
if (getX() > (1000 - MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
- return GESTURE_RIGHT;
+ return MICROBIT_ACCELEROMETER_EVT_TILT_RIGHT;
if (getY() < (-1000 + MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
- return GESTURE_DOWN;
+ return MICROBIT_ACCELEROMETER_EVT_TILT_DOWN;
if (getY() > (1000 - MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
- return GESTURE_UP;
+ return MICROBIT_ACCELEROMETER_EVT_TILT_UP;
if (getZ() < (-1000 + MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
- return GESTURE_FACE_UP;
+ return MICROBIT_ACCELEROMETER_EVT_FACE_UP;
if (getZ() > (1000 - MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
- return GESTURE_FACE_DOWN;
+ return MICROBIT_ACCELEROMETER_EVT_FACE_DOWN;
- return GESTURE_NONE;
+ return MICROBIT_ACCELEROMETER_EVT_NONE;
}
/**
@@ -405,17 +404,17 @@
{
if (force > MICROBIT_ACCELEROMETER_3G_THRESHOLD && !shake.impulse_3)
{
- MicroBitEvent e(MICROBIT_ID_GESTURE, GESTURE_3G);
+ MicroBitEvent e(MICROBIT_ID_GESTURE, MICROBIT_ACCELEROMETER_EVT_3G);
shake.impulse_3 = 1;
}
if (force > MICROBIT_ACCELEROMETER_6G_THRESHOLD && !shake.impulse_6)
{
- MicroBitEvent e(MICROBIT_ID_GESTURE, GESTURE_6G);
+ MicroBitEvent e(MICROBIT_ID_GESTURE, MICROBIT_ACCELEROMETER_EVT_6G);
shake.impulse_6 = 1;
}
if (force > MICROBIT_ACCELEROMETER_8G_THRESHOLD && !shake.impulse_8)
{
- MicroBitEvent e(MICROBIT_ID_GESTURE, GESTURE_8G);
+ MicroBitEvent e(MICROBIT_ID_GESTURE, MICROBIT_ACCELEROMETER_EVT_8G);
shake.impulse_8 = 1;
}
@@ -430,7 +429,7 @@
// Determine what it looks like we're doing based on the latest sample...
- BasicGesture g = instantaneousPosture();
+ uint16_t g = instantaneousPosture();
// Perform some low pass filtering to reduce jitter from any detected effects
if (g == currentGesture)
@@ -688,7 +687,7 @@
* display.scroll("SHAKE!");
* @endcode
*/
-BasicGesture MicroBitAccelerometer::getGesture()
+uint16_t MicroBitAccelerometer::getGesture()
{
return lastGesture;
}
