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

master
Joe Finney 7 years ago
parent 1e71169550
commit ef613e9d86
  1. 2
      inc/MicroBit.h
  2. 7
      inc/MicroBitConfig.h
  3. 1
      source/CMakeLists.txt
  4. 4
      source/MicroBit.cpp
  5. 2
      source/ble-services/MicroBitMagnetometerService.cpp

@ -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.

@ -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

@ -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)

@ -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));

@ -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));

Loading…
Cancel
Save