Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822 circular_buffer
AccelService.cpp
- Committer:
- agufal
- Date:
- 2016-05-25
- Revision:
- 13:e4c3b3e00e3d
- Parent:
- 12:172acb80fcab
File content as of revision 13:e4c3b3e00e3d:
#include "AccelService.h"
AccelService::AccelService() :
_accelState( CHARACTERISTIC_UUID, _values, 6, 6, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)
{
const static char DEVICE_NAME[] = "AccelBike";
const uint16_t uuid16_list[] = { SERVICE_UUID };
// Segun la documentacion, a BLE hay que tratarlo como un singleton
BLE::Instance().init();
BLE::Instance().gap().onDisconnection(disconnectionCallback);
BLE::Instance().gap().onConnection(connectionCallback);
/* setup advertising */
BLE::Instance().gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
BLE::Instance().gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
BLE::Instance().gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
BLE::Instance().gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
BLE::Instance().gap().setAdvertisingInterval(1000); /* 1000ms. */
BLE::Instance().gap().startAdvertising();
/* setup service */
GattCharacteristic *charTable[] = { &_accelState };
GattService accelService ( SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *) );
BLE::Instance().gattServer().addService(accelService);
}
void AccelService::updateAccelState(Vector v)
{
// Partimos los ejes en dos bytes para mandarlos
_values[0] = (uint8_t)(v.x >> 8); // MSB
_values[1] = (uint8_t)(v.x & 0x00FF); // LSB
_values[2] = (uint8_t)(v.y >> 8); // MSB
_values[3] = (uint8_t)(v.y & 0x00FF); // LSB
_values[4] = (uint8_t)(v.z >> 8); // MSB
_values[5] = (uint8_t)(v.z & 0x00FF); // LSB
BLE::Instance().gattServer().write(_accelState.getValueHandle(), _values, 6);
}
