Updates to support alternative accelerometer and magnetomter sensors

Minor updates to make use of new functionality in microbit-dal that performs
autodetection of attached sensors and instatiation of drivers. Also some code
cleanups to remove unused code.

More specifically:

- Changed MicroBitAccelerometer and MicroBitCompass objects to be references.
  This is to support dynamic autodetection and instantiation of drivers for such hardware.
- Updates to initialise MicroBitAccelerometer and MicroBitCompass references
  through the MicroBitAccelerometer::autoDetect() and MicroBitCompass::autoDetect() methods, respectively.
- Add storage object to MicroBitCompassCalibrator constructor to enable
  persistent storing of calibration data.
- Updated use of accelerometer updateSample() to more commonly used getSample()
  method to improve clarity and to provide a reference example.
- Exposed sensor IRQ lines via MicroBitIO.
- Removed redundant include of Matrix4.h
This commit is contained in:
Joe Finney 2018-07-06 05:17:19 +01:00
parent f4e7e01c1d
commit ce4c078a42
2 changed files with 8 additions and 8 deletions

View file

@ -33,7 +33,6 @@ DEALINGS IN THE SOFTWARE.
#include "MicroBitDevice.h"
#include "ErrorNo.h"
#include "MicroBitSystemTimer.h"
#include "Matrix4.h"
#include "MicroBitCompat.h"
#include "MicroBitComponent.h"
#include "ManagedType.h"
@ -112,8 +111,8 @@ class MicroBit
MicroBitButton buttonA;
MicroBitButton buttonB;
MicroBitMultiButton buttonAB;
MicroBitAccelerometer accelerometer;
MicroBitCompass compass;
MicroBitAccelerometer &accelerometer;
MicroBitCompass &compass;
MicroBitCompassCalibrator compassCalibrator;
MicroBitThermometer thermometer;

View file

@ -68,9 +68,9 @@ MicroBit::MicroBit() :
buttonA(MICROBIT_PIN_BUTTON_A, MICROBIT_ID_BUTTON_A),
buttonB(MICROBIT_PIN_BUTTON_B, MICROBIT_ID_BUTTON_B),
buttonAB(MICROBIT_ID_BUTTON_A,MICROBIT_ID_BUTTON_B, MICROBIT_ID_BUTTON_AB),
accelerometer(i2c),
compass(i2c, accelerometer, storage),
compassCalibrator(compass, accelerometer, display),
accelerometer(MicroBitAccelerometer::autoDetect(i2c)),
compass(MicroBitCompass::autoDetect(i2c)),
compassCalibrator(compass, accelerometer, display, storage),
thermometer(storage),
io(MICROBIT_ID_IO_P0,MICROBIT_ID_IO_P1,MICROBIT_ID_IO_P2,
MICROBIT_ID_IO_P3,MICROBIT_ID_IO_P4,MICROBIT_ID_IO_P5,
@ -78,7 +78,8 @@ MicroBit::MicroBit() :
MICROBIT_ID_IO_P9,MICROBIT_ID_IO_P10,MICROBIT_ID_IO_P11,
MICROBIT_ID_IO_P12,MICROBIT_ID_IO_P13,MICROBIT_ID_IO_P14,
MICROBIT_ID_IO_P15,MICROBIT_ID_IO_P16,MICROBIT_ID_IO_P19,
MICROBIT_ID_IO_P20),
MICROBIT_ID_IO_P20, MICROBIT_ID_IO_INT1, MICROBIT_ID_IO_INT2,
MICROBIT_ID_IO_INT3),
bleManager(storage),
radio(),
ble(NULL)
@ -211,7 +212,7 @@ void MicroBit::onListenerRegisteredEvent(MicroBitEvent evt)
case MICROBIT_ID_GESTURE:
// A listener has been registered for the accelerometer.
// The accelerometer uses lazy instantiation, we just need to read the data once to start it running.
accelerometer.updateSample();
accelerometer.getSample();
break;
case MICROBIT_ID_THERMOMETER: