Pull request for i.a. sensor buffer template
Dependencies: BLE_API MPU6050 mbed nRF51822
Revision 6:ed0dc0647c01, committed 2018-10-16
- Comitter:
- pietermaljaars
- Date:
- Tue Oct 16 18:46:28 2018 +0000
- Parent:
- 5:614164945894
- Child:
- 7:d92f1383bd81
- Commit message:
- update....
Changed in this revision
--- /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
--- a/TemperatureService.h Wed Sep 19 19:49:39 2018 +0000 +++ b/TemperatureService.h Tue Oct 16 18:46:28 2018 +0000 @@ -1,4 +1,3 @@ - #ifndef __TEMPERATURE_SERVICE_H__ #define __TEMPERATURE_SERVICE_H__
--- a/main.cpp Wed Sep 19 19:49:39 2018 +0000 +++ b/main.cpp Tue Oct 16 18:46:28 2018 +0000 @@ -10,6 +10,7 @@ #include "BatteryService.h" #include "DeviceInformationService.h" #include "TemperatureService.h" +//#include "AccelerationService.h" #define LOG(...) { pc.printf(__VA_ARGS__); } @@ -169,6 +170,7 @@ BatteryService battery(ble); DeviceInformationService deviceInfo(ble, MANUFACTURER, MODELNUMBER, SERIALNUMBER, HARDWAREREVISION, FIRMWAREREVISION, SOFTWAREREVISION); TemperatureService tempService(ble); + //AccelerationService accelerationService(ble); ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ ble.gap().startAdvertising(); @@ -183,19 +185,28 @@ batteryVoltageChanged = false; } else if (startMeasure == true) { - float a[3]; - mpu.getAccelero(a); - LOG("Acceleration %.2f;%.2f;%.2f\n", a[0], a[1], a[2]); - startMeasure = false; + //float a[3]; + //mpu.getAccelero(a); + //LOG("Acceleration %.2f;%.2f;%.2f\n", a[0], a[1], a[2]); + /* + int a[3]; + mpu.getAcceleroRaw(a); + accelerationService.addAcceleration((int16_t*)a); + LOG("Acceleration %d;%d;%d\n", a[0], a[1], a[2]); + */ float temp = mpu.getTemp(); LOG("Temp = %.01f\n", temp); int16_t tempRaw = mpu.getTempRaw(); + // convert into 0.1 degrees Celsius tempRaw *= 10; tempRaw += 5210; tempRaw /= 340; tempRaw += 350; + // update BLE tmperature tempService.updateTemperature(tempRaw); + + startMeasure = false; } } }
--- a/mbed.bld Wed Sep 19 19:49:39 2018 +0000 +++ b/mbed.bld Tue Oct 16 18:46:28 2018 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/7130f322cb7e \ No newline at end of file +https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187 \ No newline at end of file