Pull request for i.a. sensor buffer template
Dependencies: BLE_API MPU6050 mbed nRF51822
Diff: AccelerationService.h
- Revision:
- 6:ed0dc0647c01
- Child:
- 8:d1f5c8801d59
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AccelerationService.h Tue Oct 16 18:46:28 2018 +0000 @@ -0,0 +1,67 @@ +#ifndef __ACCELERATION_SERVICE_H__ +#define __ACCELERATION_SERVICE_H__ + +#include "ble/BLE.h" + +#define UUID_ACCELERATION_CHAR "5D34E2F0-3DD2-07AC-38F2-BBAD120EF853" +#define UUID_ACCELERATION_SERVICE "5D34E2F0-3DD2-07AC-38F1-BBAD120EF853" + + +/** +* @class AccelerationService +* @brief BLE Acceleration Service. This service displays the acceleration +*/ +class AccelerationService { +public: + /** + * @param[in] _ble + * BLE object for the underlying controller. + */ + AccelerationService(BLE &_ble) : + ble(_ble), + accelerationIndex(0), + accelerationCharacteristic(UUID(UUID_ACCELERATION_CHAR), &temp, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) { + //accelerationCharacteristic(0x1234, &temp, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) { + + GattCharacteristic *charTable[] = {&accelerationCharacteristic}; + GattService AccelerationService(UUID(UUID_ACCELERATION_SERVICE), charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); + + ble.addService(AccelerationService); + } + + /** + * @brief Update the temperature with a new value. Valid values lie between -2732 and above. + * + * @param newTemp + * Update to temperature. + */ + void addAcceleration(int16_t *newAccel) { + /* + temperature = newTemp; + uint16_t temp = (uint16_t)temperature; + ble.gattServer().write(accelerationCharacteristic.getValueHandle(), (const uint8_t*)&temp, sizeof(temperature)); + */ + } + +protected: + /** + * A reference to the underlying BLE instance that this object is attached to. + * The services and characteristics will be registered in this BLE instance. + */ + BLE &ble; + + /** + * The current temperature represented as 0.1 degrees Celsius. + */ + //int16_t acceleration[30][3]; + int16_t temp; + + uint16_t accelerationIndex; + /** + * A ReadOnlyGattCharacteristic that allows access to the peer device to the + * temperature value through BLE. + */ + ReadOnlyGattCharacteristic<int16_t> accelerationCharacteristic; +}; + +#endif /* #ifndef __ACCELERATION_SERVICE_H__*/ \ No newline at end of file