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 3:b1f65162c95b, committed 2016-10-29
- Comitter:
- 16038618
- Date:
- Sat Oct 29 14:16:34 2016 +0000
- Parent:
- 2:510cac0a0250
- Commit message:
- IOTIO
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 |
diff -r 510cac0a0250 -r b1f65162c95b DemoAppService.cpp --- a/DemoAppService.cpp Wed May 27 18:58:49 2015 +0000 +++ b/DemoAppService.cpp Sat Oct 29 14:16:34 2016 +0000 @@ -85,5 +85,5 @@ ble->setAdvertisingInterval(160); ble->startAdvertising(); - return new DemoAppService(*ble); + return new DemoAppService(*ble,20,50,70,225); } \ No newline at end of file
diff -r 510cac0a0250 -r b1f65162c95b DemoAppService.h --- a/DemoAppService.h Wed May 27 18:58:49 2015 +0000 +++ b/DemoAppService.h Sat Oct 29 14:16:34 2016 +0000 @@ -1,20 +1,3 @@ -/* Demo BLE service - * Copyright (c) 2006-2013 ARM Limited - * Copyright (c) 2015 Adam Berlinger - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - #ifndef __BLE_DEMOAPP_SERVICE_H__ #define __BLE_DEMOAPP_SERVICE_H__ @@ -38,7 +21,10 @@ static const uint8_t buttonCharacteristicUUID[LENGTH_OF_LONG_UUID]; protected: BLEDevice &ble; - + GattCharacteristic humiditychar; + GattCharacteristic temperaturechar; + GattCharacteristic winddirectionchar; + GattCharacteristic pressurechar; DemoAppCallback eventCallback; GattCharacteristic slider1Characteristic; GattCharacteristic slider2Characteristic; @@ -48,8 +34,23 @@ uint16_t slider1Value; uint16_t slider2Value; public: - DemoAppService(BLEDevice &_ble) : + DemoAppService(BLEDevice &_ble, uint16_t humidity, int16_t temperature, uint16_t winddirection, uint32_t pressure) : ble(_ble), + humiditychar(GattCharacteristic::UUID_HUMIDITY_CHAR, (uint8_t *)&humidity, + sizeof(uint16_t), sizeof(uint16_t), + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), + + temperaturechar(GattCharacteristic::UUID_TEMPERATURE_CHAR, (uint8_t *)&temperature, + sizeof(int16_t), sizeof(int16_t), + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), + + winddirectionchar(GattCharacteristic::UUID_TRUE_WIND_DIRECTION_CHAR, (uint8_t *)&winddirection, + sizeof(uint16_t), sizeof(uint16_t), + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), + + pressurechar(GattCharacteristic::UUID_PRESSURE_CHAR, (uint8_t *)&pressure, + sizeof(uint32_t), sizeof(uint32_t), + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), eventCallback(NULL), slider1Characteristic(slider1CharacteristicUUID, (uint8_t*)&slider1Value, 2, 2, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE), @@ -57,13 +58,42 @@ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE), buttonCharacteristic(buttonCharacteristicUUID, (uint8_t*)&lastButtonPressed, 2, 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); + + GattCharacteristic *charTable[] = {&humiditychar, &temperaturechar, }; + GattCharacteristic *charTable2[] = {&winddirectionchar, &pressurechar}; + + GattService EnvironmentalService(GattService::UUID_ENVIRONMENTAL_SENSING_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); + GattService EnvironmentalService2(GattService::UUID_ENVIRONMENTAL_SENSING_SERVICE, charTable2, sizeof(charTable2) / sizeof(GattCharacteristic *)); + + ble.addService(EnvironmentalService); + ble.addService(EnvironmentalService2); + +// ble.onDataWritten(this, &DemoAppService::onDataWritten); } + /* Set a new 16-bit value for the humidity measurement. */ + void updateHumidity(uint16_t humidity) { + ble.updateCharacteristicValue(humiditychar.getValueAttribute().getHandle(), (uint8_t *)&humidity, sizeof(uint16_t)); + } + + /* Set a new 16-bit value for the temperature measurement. */ + void updateTemperature(int16_t temperature) { + ble.updateCharacteristicValue(temperaturechar.getValueAttribute().getHandle(), (uint8_t *)&temperature, sizeof(int16_t)); + } + + + /* Set a new 16-bit value for the wind direction measurement. */ + void updateWinddirection(uint16_t winddirection) { + ble.updateCharacteristicValue(winddirectionchar.getValueAttribute().getHandle(), (uint8_t *)&winddirection, sizeof(uint16_t)); + } + + /* Set a new 32-bit value for the pressure measurement. */ + void updatePressure(uint32_t pressure) { + ble.updateCharacteristicValue(pressurechar.getValueAttribute().getHandle(), (uint8_t *)&pressure, sizeof(uint32_t)); + } + + + void setCallback(DemoAppCallback callback){eventCallback = callback;} void waitForEvent(void){ble.waitForEvent(); }