Permalink
Browse files

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
  • Loading branch information...
finneyj committed Jul 6, 2018
1 parent f4e7e01 commit ce4c078a4279ad9ab61f08c7cc386f41f113133a
Showing with 8 additions and 8 deletions.
  1. +2 −3 inc/MicroBit.h
  2. +6 −5 source/MicroBit.cpp
@@ -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;

@@ -68,17 +68,18 @@ 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,
MICROBIT_ID_IO_P6,MICROBIT_ID_IO_P7,MICROBIT_ID_IO_P8,
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:

0 comments on commit ce4c078

Please sign in to comment.