mbed.org local branch of microbit-dal. The real version lives in git at https://github.com/lancaster-university/microbit-dal

Dependencies:   BLE_API nRF51822 mbed-dev-bin

Dependents:   microbit Microbit IoTChallenge1 microbit ... more

Embed: (wiki syntax)

« Back to documentation index

MicroBitBLEManager Class Reference

MicroBitBLEManager Class Reference

Class definition for the MicroBitBLEManager. More...

#include <MicroBitBLEManager.h>

Inherits MicroBitComponent.

Public Member Functions

 MicroBitBLEManager (MicroBitStorage &_storage)
 Constructor.
 MicroBitBLEManager ()
 Constructor.
void init (ManagedString deviceName, ManagedString serialNumber, EventModel &messageBus, bool enableBonding)
 Post constructor initialisation method as the BLE stack cannot be brought up in a static context.
int setTransmitPower (int power)
 Change the output power level of the transmitter to the given value.
void pairingMode (MicroBitDisplay &display, MicroBitButton &authorisationButton)
 Enter pairing mode.
void advertise ()
 When called, the micro:bit will begin advertising for a predefined period, MICROBIT_BLE_ADVERTISING_TIMEOUT seconds to bonded devices.
int getBondCount ()
 Determines the number of devices currently bonded with this micro:bit.
void pairingRequested (ManagedString passKey)
 A request to pair has been received from a BLE device.
void pairingComplete (bool success)
 A pairing request has been sucessfully completed.
void idleTick ()
 Periodic callback in thread context.

Private Member Functions

virtual void systemTick ()
 The system timer will call this member function once the component has been added to the array of system components using system_timer_add_component.

Detailed Description

Class definition for the MicroBitBLEManager.

Definition at line 90 of file MicroBitBLEManager.h.


Constructor & Destructor Documentation

Constructor.

Configure and manage the micro:bit's Bluetooth Low Energy (BLE) stack.

Parameters:
_storagean instance of MicroBitStorage used to persist sys attribute information. (This is required for compatability with iOS).
Note:
The BLE stack *cannot* be brought up in a static context (the software simply hangs or corrupts itself). Hence, the init() member function should be used to initialise the BLE stack.

Definition at line 211 of file MicroBitBLEManager.cpp.

Constructor.

Configure and manage the micro:bit's Bluetooth Low Energy (BLE) stack.

Note:
The BLE stack *cannot* be brought up in a static context (the software simply hangs or corrupts itself). Hence, the init() member function should be used to initialise the BLE stack.

Definition at line 227 of file MicroBitBLEManager.cpp.


Member Function Documentation

void advertise (  )

When called, the micro:bit will begin advertising for a predefined period, MICROBIT_BLE_ADVERTISING_TIMEOUT seconds to bonded devices.

Definition at line 239 of file MicroBitBLEManager.cpp.

int getBondCount (  )

Determines the number of devices currently bonded with this micro:bit.

Returns:
The number of active bonds.

Definition at line 409 of file MicroBitBLEManager.cpp.

void idleTick (  ) [virtual]

Periodic callback in thread context.

We use this here purely to safely issue a disconnect operation after a pairing operation is complete.

Reimplemented from MicroBitComponent.

Definition at line 455 of file MicroBitBLEManager.cpp.

void init ( ManagedString  deviceName,
ManagedString  serialNumber,
EventModel messageBus,
bool  enableBonding 
)

Post constructor initialisation method as the BLE stack cannot be brought up in a static context.

Parameters:
deviceNameThe name used when advertising
serialNumberThe serial number exposed by the device information service
messageBusAn instance of an EventModel, used during pairing.
enableBondingIf true, the security manager enabled bonding.
 bleManager.init(uBit.getName(), uBit.getSerial(), uBit.messageBus, true);

Definition at line 258 of file MicroBitBLEManager.cpp.

void pairingComplete ( bool  success )

A pairing request has been sucessfully completed.

If we're in pairing mode, display a success or failure message.

Note:
for internal use only.

Definition at line 440 of file MicroBitBLEManager.cpp.

void pairingMode ( MicroBitDisplay display,
MicroBitButton authorisationButton 
)

Enter pairing mode.

This is mode is called to initiate pairing, and to enable FOTA programming of the micro:bit in cases where BLE is disabled during normal operation.

Parameters:
displayAn instance of MicroBitDisplay used when displaying pairing information.
authorizationButtonThe button to use to authorise a pairing request.
 // initiate pairing mode
 bleManager.pairingMode(uBit.display, uBit.buttonA);

Definition at line 475 of file MicroBitBLEManager.cpp.

void pairingRequested ( ManagedString  passKey )

A request to pair has been received from a BLE device.

If we're in pairing mode, display the passkey to the user. Also, purge the bonding table if it has reached capacity.

Note:
for internal use only.

Definition at line 427 of file MicroBitBLEManager.cpp.

int setTransmitPower ( int  power )

Change the output power level of the transmitter to the given value.

Parameters:
powera value in the range 0..7, where 0 is the lowest power and 7 is the highest.
Returns:
MICROBIT_OK on success, or MICROBIT_INVALID_PARAMETER if the value is out of range.
 // maximum transmission power.
 bleManager.setTransmitPower(7);

Definition at line 394 of file MicroBitBLEManager.cpp.