Added BLE connect/disconnect events and fixed bug in MagnetometerService re: bearing characteristic
This commit is contained in:
parent
0639d7df6a
commit
87f7233a84
|
@ -33,6 +33,9 @@ DEALINGS IN THE SOFTWARE.
|
|||
#define MICROBIT_ID_BLE 1000
|
||||
#define MICROBIT_ID_BLE_UART 1001
|
||||
|
||||
#define MICROBIT_BLE_CONNECTED 1
|
||||
#define MICROBIT_BLE_DISCONNECTED 2
|
||||
|
||||
#include "MESEvents.h"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -109,12 +109,22 @@ static void storeSystemAttributes(Gap::Handle_t handle)
|
|||
*/
|
||||
static void bleDisconnectionCallback(const Gap::DisconnectionCallbackParams_t *reason)
|
||||
{
|
||||
MicroBitEvent(MICROBIT_ID_BLE,MICROBIT_BLE_DISCONNECTED);
|
||||
|
||||
storeSystemAttributes(reason->handle);
|
||||
|
||||
if (manager)
|
||||
manager->advertise();
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback when a BLE connection is established.
|
||||
*/
|
||||
static void bleConnectionCallback(const Gap::ConnectionCallbackParams_t *params)
|
||||
{
|
||||
MicroBitEvent(MICROBIT_ID_BLE,MICROBIT_BLE_CONNECTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback when a BLE SYS_ATTR_MISSING.
|
||||
*/
|
||||
|
@ -267,6 +277,9 @@ void MicroBitBLEManager::init(ManagedString deviceName, ManagedString serialNumb
|
|||
// automatically restart advertising after a device disconnects.
|
||||
ble->gap().onDisconnection(bleDisconnectionCallback);
|
||||
ble->gattServer().onSysAttrMissing(bleSysAttrMissingCallback);
|
||||
|
||||
// generate an event when a Bluetooth connection is lost
|
||||
ble->gap().onConnection(bleConnectionCallback);
|
||||
|
||||
// Configure the stack to hold onto the CPU during critical timing events.
|
||||
// mbed-classic performs __disable_irq() calls in its timers that can cause
|
||||
|
|
|
@ -74,7 +74,7 @@ MicroBitMagnetometerService::MicroBitMagnetometerService(BLEDevice &_ble, MicroB
|
|||
magnetometerPeriodCharacteristicHandle = magnetometerPeriodCharacteristic.getValueHandle();
|
||||
|
||||
ble.gattServer().notify(magnetometerDataCharacteristicHandle,(uint8_t *)magnetometerDataCharacteristicBuffer, sizeof(magnetometerDataCharacteristicBuffer));
|
||||
ble.gattServer().notify(magnetometerBearingCharacteristicHandle,(uint8_t *)&magnetometerBearingCharacteristicBuffer, sizeof(magnetometerDataCharacteristicBuffer));
|
||||
ble.gattServer().notify(magnetometerBearingCharacteristicHandle,(uint8_t *)&magnetometerBearingCharacteristicBuffer, sizeof(magnetometerBearingCharacteristicBuffer));
|
||||
ble.gattServer().write(magnetometerPeriodCharacteristicHandle, (const uint8_t *)&magnetometerPeriodCharacteristicBuffer, sizeof(magnetometerPeriodCharacteristicBuffer));
|
||||
|
||||
ble.onDataWritten(this, &MicroBitMagnetometerService::onDataWritten);
|
||||
|
|
Loading…
Reference in New Issue