microbit: Added BLE Magnetometer service compilation, initialization and configuration options

This commit is contained in:
Joe Finney 2015-09-19 22:19:57 +01:00
parent 1e71169550
commit ef613e9d86
5 changed files with 15 additions and 1 deletions

View file

@ -37,6 +37,7 @@
#include "MicroBitEventService.h"
#include "MicroBitLEDService.h"
#include "MicroBitAccelerometerService.h"
#include "MicroBitMagnetometerService.h"
#include "ExternalEvents.h"
// MicroBit::flags values
@ -111,6 +112,7 @@ class MicroBit
MicroBitEventService *ble_event_service;
MicroBitLEDService *ble_led_service;
MicroBitAccelerometerService *ble_accelerometer_service;
MicroBitMagnetometerService *ble_magnetometer_service;
/**
* Constructor.

View file

@ -167,6 +167,13 @@
#define MICROBIT_BLE_ACCELEROMETER_SERVICE 1
#endif
// Enable/Disable BLE Service: MicroBitMagnetometerService
// This enables live access to the on board 3 axis magnetometer.
// Set '1' to enable.
#ifndef MICROBIT_BLE_MAGNETOMETER_SERVICE
#define MICROBIT_BLE_MAGNETOMETER_SERVICE 1
#endif
// Defines the maximum length strong that can be written to the
// display over BLE.
#ifndef MICROBIT_BLE_MAXIMUM_SCROLLTEXT

View file

@ -32,6 +32,7 @@ set(YOTTA_AUTO_MICROBIT-DAL_CPP_FILES
"ble-services/MicroBitEventService.cpp"
"ble-services/MicroBitLEDService.cpp"
"ble-services/MicroBitAccelerometerService.cpp"
"ble-services/MicroBitMagnetometerService.cpp"
)
if (YOTTA_CFG_MICROBIT_CONFIGFILE)

View file

@ -125,6 +125,10 @@ void MicroBit::init()
ble_accelerometer_service = new MicroBitAccelerometerService(*ble);
#endif
#if CONFIG_ENABLED(MICROBIT_BLE_MAGNETOMETER_SERVICE)
ble_magnetometer_service = new MicroBitMagnetometerService(*ble);
#endif
// Setup advertising.
ble->accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
ble->accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)MICROBIT_BLE_DEVICE_NAME, sizeof(MICROBIT_BLE_DEVICE_NAME));

View file

@ -71,7 +71,7 @@ void MicroBitMagnetometerService::magnetometerUpdate(MicroBitEvent e)
magnetometerDataCharacteristicBuffer[0] = uBit.compass.getX();
magnetometerDataCharacteristicBuffer[1] = uBit.compass.getY();
magnetometerDataCharacteristicBuffer[2] = uBit.compass.getZ();
magnetometerBearingCharacteristicBuffer = (uint16_t) uBit.compass.bearing();
magnetometerBearingCharacteristicBuffer = (uint16_t) uBit.compass.heading();
ble.gattServer().notify(magnetometerDataCharacteristicHandle,(uint8_t *)magnetometerDataCharacteristicBuffer, sizeof(magnetometerDataCharacteristicBuffer));
ble.gattServer().notify(magnetometerDataCharacteristicHandle,(uint8_t *)magnetometerBearingCharacteristicBuffer, sizeof(magnetometerDataCharacteristicBuffer));