Followed lateest libraries (BLE ,mbed and nRF51822)
Dependencies: BLE_API mbed nRF51822 BLE_HTM_by_InTempSensr_pub
Dependents: BLE_HTM_by_InTempSensr_pub
Fork of BLE_HTM_by_InTempSensr by
Diff: main.cpp
- Revision:
- 7:b8e9a93ba3b5
- Parent:
- 6:182013fa5592
- Child:
- 8:ae7255b477e6
--- a/main.cpp Sun Apr 26 11:54:42 2015 +0000 +++ b/main.cpp Wed Aug 26 02:04:52 2015 +0000 @@ -1,5 +1,6 @@ /* mbed Microcontroller Library * Copyright (c) 2006-2013 ARM Limited + * Copyright (c) 2014-2015 T.Naka * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +16,7 @@ */ #include "mbed.h" -#include "BLEDevice.h" +#include "BLE.h" // #include "ble_hrs.h" // #include "ble_hts.h" @@ -75,17 +76,16 @@ DEBUG("Disconnected handle %u!\n\r", handle); DEBUG("Restarting the advertising process\n\r"); led2 = 0; - ble.startAdvertising(); - + ble.gap().startAdvertising(); } -void onConnectionCallback(Gap::Handle_t handle,Gap::addr_type_t peerAddrType, const Gap::address_t peerAddr, const Gap::ConnectionParams_t *params) //Mod +void onConnectionCallback(const Gap::ConnectionCallbackParams_t *params) { - DEBUG("connected. Got handle %u\r\n", handle); + DEBUG("connected. Got handle %u\r\n", params->handle); connectionParams.slaveLatency = 1; led2 = 1; - if (ble.updateConnectionParams(handle, &connectionParams) != BLE_ERROR_NONE) { + if (ble.gap().updateConnectionParams(params->handle, &connectionParams) != BLE_ERROR_NONE) { DEBUG("failed to update connection paramter\r\n"); } @@ -118,24 +118,24 @@ ticker.attach(periodicCallback, 1.0 ); DEBUG("Initialising the nRF51822\n\r"); ble.init(); - ble.onDisconnection(disconnectionCallback); - ble.onConnection(onConnectionCallback); + ble.gap().onDisconnection(disconnectionCallback); + ble.gap().onConnection(onConnectionCallback); - ble.getPreferredConnectionParams(&connectionParams); + ble.gap().getPreferredConnectionParams(&connectionParams); /* setup advertising */ - ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); - ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t*)uuid16_list, sizeof(uuid16_list)); - ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_THERMOMETER); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t*)uuid16_list, sizeof(uuid16_list)); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_THERMOMETER); - ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); - ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); - ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ - ble.startAdvertising(); + ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); + ble.gap().setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ + ble.gap().startAdvertising(); - ble.addService(htmService); - ble.addService(battService); + ble.gattServer().addService(htmService); + ble.gattServer().addService(battService); while (true) { if (triggerSensorPolling) { @@ -169,9 +169,9 @@ batt <=50 ? batt=100 : batt--;; bpm2[0] = batt; - if (ble.getGapState().connected ) { - ble.updateCharacteristicValue(tempChar.getValueAttribute().getHandle(), thermTempPayload, sizeof(thermTempPayload)); - ble.updateCharacteristicValue(battLevel.getValueAttribute().getHandle(), (uint8_t *)&batt, sizeof(batt)); + if (ble.gap().getState().connected ) { + ble.gattServer().write(tempChar.getValueAttribute().getHandle(), thermTempPayload, sizeof(thermTempPayload)); + ble.gattServer().write(battLevel.getValueAttribute().getHandle(), (uint8_t *)&batt, sizeof(batt)); } }