update init() to match the chagnes around initializationCompleteCallback.

refer to https://github.com/ARMmbed/ble/pull/91 and https://github.com/ARMmbed/ble/issues/90
master
Rohit Grover 2015-10-28 14:05:27 +00:00
parent aba22463c8
commit 20b07e38bc
2 changed files with 27 additions and 5 deletions

View File

@ -38,7 +38,7 @@ createBLEInstance(void)
return (&deviceInstance);
}
nRF5xn::nRF5xn(void)
nRF5xn::nRF5xn(void) : initialized(false), instanceID(BLE::DEFAULT_INSTANCE)
{
}
@ -72,11 +72,24 @@ const char *nRF5xn::getVersion(void)
return versionString;
}
ble_error_t nRF5xn::init(void)
ble_error_t nRF5xn::init(BLE::InstanceID_t instanceID, BLE::InitializationCompleteCallback_t callback)
{
if (initialized) {
if (callback) {
callback(BLE::Instance(instanceID), BLE_ERROR_ALREADY_INITIALIZED);
}
return BLE_ERROR_ALREADY_INITIALIZED;
}
instanceID = instanceID;
/* ToDo: Clear memory contents, reset the SD, etc. */
btle_init();
initialized = true;
if (callback) {
callback(BLE::Instance(instanceID), BLE_ERROR_NONE);
}
return BLE_ERROR_NONE;
}

View File

@ -17,13 +17,15 @@
#ifndef __NRF51822_H__
#define __NRF51822_H__
#include "mbed.h"
#include "ble/blecommon.h"
#include "ble/BLE.h"
#include "ble/blecommon.h"
#include "ble/BLEInstanceBase.h"
#include "nRF5xGap.h"
#include "nRF5xGattServer.h"
#include "nRF5xGattClient.h"
#include "nRF5xSecurityManager.h"
#include "btle.h"
class nRF5xn : public BLEInstanceBase
@ -32,7 +34,10 @@ public:
nRF5xn(void);
virtual ~nRF5xn(void);
virtual ble_error_t init(void);
virtual ble_error_t init(BLE::InstanceID_t instanceID, BLE::InitializationCompleteCallback_t);
virtual bool hasInitialized(void) const {
return initialized;
}
virtual ble_error_t shutdown(void);
virtual const char *getVersion(void);
@ -58,6 +63,10 @@ public:
return nRF5xSecurityManager::getInstance();
}
virtual void waitForEvent(void);
private:
bool initialized;
BLE::InstanceID_t instanceID;
};
#endif