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.
Fork of Nucleo_BLE_DemoApp by
Revision 0:866f2c528c01, committed 2015-05-10
- Comitter:
- berlingeradam
- Date:
- Sun May 10 15:41:38 2015 +0000
- Child:
- 1:fd7adeffebbe
- Commit message:
- Initial commit - 2 sliders 1 button
Changed in this revision
| DemoAppService.cpp | Show annotated file Show diff for this revision Revisions of this file |
| DemoAppService.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DemoAppService.cpp Sun May 10 15:41:38 2015 +0000
@@ -0,0 +1,21 @@
+#include "DemoAppService.h"
+
+const uint8_t DemoAppService::ServiceUUID[LENGTH_OF_LONG_UUID] = {
+ 0x6E, 0x40, 0x00, 0x10, 0xB5, 0xA3, 0xF3, 0x93,
+ 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E,
+};
+
+const uint8_t DemoAppService::buttonCharacteristicUUID[LENGTH_OF_LONG_UUID] = {
+ 0x6E, 0x40, 0x00, 0x11, 0xB5, 0xA3, 0xF3, 0x93,
+ 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E,
+};
+
+const uint8_t DemoAppService::slider1CharacteristicUUID[LENGTH_OF_LONG_UUID] = {
+ 0x6E, 0x40, 0x00, 0x12, 0xB5, 0xA3, 0xF3, 0x93,
+ 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E,
+};
+
+const uint8_t DemoAppService::slider2CharacteristicUUID[LENGTH_OF_LONG_UUID] = {
+ 0x6E, 0x40, 0x00, 0x13, 0xB5, 0xA3, 0xF3, 0x93,
+ 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E,
+};
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DemoAppService.h Sun May 10 15:41:38 2015 +0000
@@ -0,0 +1,71 @@
+#ifndef __BLE_DEMOAPP_SERVICE_H__
+#define __BLE_DEMOAPP_SERVICE_H__
+
+#include "Stream.h"
+
+#include "UUID.h"
+#include "BLEDevice.h"
+#include "Utils.h"
+
+class DemoAppService {
+ public:
+ static const uint8_t ServiceUUID[LENGTH_OF_LONG_UUID];
+ static const uint8_t slider1CharacteristicUUID[LENGTH_OF_LONG_UUID];
+ static const uint8_t slider2CharacteristicUUID[LENGTH_OF_LONG_UUID];
+ static const uint8_t buttonCharacteristicUUID[LENGTH_OF_LONG_UUID];
+ protected:
+ BLEDevice &ble;
+
+ GattCharacteristic slider1Characteristic;
+ GattCharacteristic slider2Characteristic;
+ GattCharacteristic buttonCharacteristic;
+
+ uint16_t lastButtonPressed;
+ uint16_t slider1Value;
+ uint16_t slider2Value;
+ public:
+ DemoAppService(BLEDevice &_ble) :
+ ble(_ble),
+ slider1Characteristic(slider1CharacteristicUUID, (uint8_t*)&slider1Value, 1, 2,
+ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE),
+ slider2Characteristic(slider2CharacteristicUUID, (uint8_t*)&slider2Value, 1, 2,
+ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE),
+ buttonCharacteristic(buttonCharacteristicUUID, (uint8_t*)&lastButtonPressed, 1, 2,
+ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE){
+
+ GattCharacteristic *charTable[] = {&slider1Characteristic, &slider2Characteristic, &buttonCharacteristic};
+ GattService demoService(ServiceUUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
+
+ ble.addService(demoService);
+ ble.onDataWritten(this, &DemoAppService::onDataWritten);
+ }
+
+ virtual void onDataWritten(const GattCharacteristicWriteCBParams *params) {
+ DEBUG("Demo service onWrite\n\r");
+ if (params->charHandle == slider1Characteristic.getValueAttribute().getHandle()) {
+ uint16_t bytesRead = params->len;
+ if (bytesRead == 2) {
+ memcpy(&slider1Value, params->data, 2);
+ DEBUG("Slider1: %d\n\r", slider1Value);
+ }
+ }
+ else if (params->charHandle == slider2Characteristic.getValueAttribute().getHandle()) {
+ uint16_t bytesRead = params->len;
+ if (bytesRead == 2) {
+ memcpy(&slider2Value, params->data, 2);
+ DEBUG("Slider2: %d\n\r", slider2Value);
+ }
+ }
+ else if (params->charHandle == buttonCharacteristic.getValueAttribute().getHandle()) {
+ uint16_t bytesRead = params->len;
+ if (bytesRead == 2) {
+ memcpy(&lastButtonPressed, params->data, 2);
+ }
+ }
+ }
+
+ uint16_t getSlider1Value()const{return slider1Value;}
+ uint16_t getSlider2Value()const{return slider2Value;}
+};
+
+#endif
\ No newline at end of file
