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: X_NUCLEO_IKS01A2
source/ESS2.h@1:b12ac7b02a21, 2020-04-29 (annotated)
- Committer:
- jim_lsj
- Date:
- Wed Apr 29 16:18:37 2020 +0000
- Revision:
- 1:b12ac7b02a21
- Parent:
- 0:9c0e0ac79e75
...;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jim_lsj | 0:9c0e0ac79e75 | 1 | /* ARM University Program Microcontroller Library |
jim_lsj | 0:9c0e0ac79e75 | 2 | * |
jim_lsj | 0:9c0e0ac79e75 | 3 | * Environmental Sensing Service |
jim_lsj | 0:9c0e0ac79e75 | 4 | * |
jim_lsj | 0:9c0e0ac79e75 | 5 | * This software is distributed under an "AS IS" BASIS, |
jim_lsj | 0:9c0e0ac79e75 | 6 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jim_lsj | 0:9c0e0ac79e75 | 7 | */ |
jim_lsj | 0:9c0e0ac79e75 | 8 | |
jim_lsj | 0:9c0e0ac79e75 | 9 | #ifndef __BLE_ENVIRONMENTAL_SENSING_SERVICE2_H__ |
jim_lsj | 0:9c0e0ac79e75 | 10 | #define __BLE_ENVIRONMENTAL_SENSING_SERVICE2_H__ |
jim_lsj | 0:9c0e0ac79e75 | 11 | |
jim_lsj | 1:b12ac7b02a21 | 12 | #include <mbed.h> |
jim_lsj | 0:9c0e0ac79e75 | 13 | #include "blecommon.h" |
jim_lsj | 0:9c0e0ac79e75 | 14 | #include "Gap.h" |
jim_lsj | 0:9c0e0ac79e75 | 15 | #include "GattServer.h" |
jim_lsj | 0:9c0e0ac79e75 | 16 | #include "BLEDeviceInstanceBase.h" |
jim_lsj | 0:9c0e0ac79e75 | 17 | //#include "BLEDevice.h" |
jim_lsj | 0:9c0e0ac79e75 | 18 | |
jim_lsj | 0:9c0e0ac79e75 | 19 | /* Environmental Sensing Service */ |
jim_lsj | 0:9c0e0ac79e75 | 20 | /* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.environmental_sensing.xml */ |
jim_lsj | 0:9c0e0ac79e75 | 21 | /* True wind direction characteristic: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.true_wind_direction.xml*/ |
jim_lsj | 0:9c0e0ac79e75 | 22 | /* Pressure characteristic: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.pressure.xml */ |
jim_lsj | 0:9c0e0ac79e75 | 23 | |
jim_lsj | 0:9c0e0ac79e75 | 24 | |
jim_lsj | 0:9c0e0ac79e75 | 25 | class EnvironmentalSensingService2 { |
jim_lsj | 0:9c0e0ac79e75 | 26 | |
jim_lsj | 0:9c0e0ac79e75 | 27 | public: |
jim_lsj | 0:9c0e0ac79e75 | 28 | /** |
jim_lsj | 0:9c0e0ac79e75 | 29 | * Constructor. |
jim_lsj | 0:9c0e0ac79e75 | 30 | * |
jim_lsj | 0:9c0e0ac79e75 | 31 | * param[in] _ble |
jim_lsj | 0:9c0e0ac79e75 | 32 | * Reference to the underlying BLEDevice. |
jim_lsj | 0:9c0e0ac79e75 | 33 | * param[in] True Wind Direction in degrees (16-bit unsigned, 2 decimals). Wind coming from: 0=North, 90=East, 180=South and 270=West. |
jim_lsj | 0:9c0e0ac79e75 | 34 | * initial value for the temperature |
jim_lsj | 0:9c0e0ac79e75 | 35 | * param[in] pressure in Pascals (32-bit unsigned, 1 decimal). |
jim_lsj | 0:9c0e0ac79e75 | 36 | * initial value for the pressure value. |
jim_lsj | 0:9c0e0ac79e75 | 37 | */ |
jim_lsj | 0:9c0e0ac79e75 | 38 | EnvironmentalSensingService2(BLEDevice &_ble, uint16_t winddirection, uint32_t pressure) : |
jim_lsj | 0:9c0e0ac79e75 | 39 | ble(_ble), |
jim_lsj | 0:9c0e0ac79e75 | 40 | |
jim_lsj | 0:9c0e0ac79e75 | 41 | |
jim_lsj | 0:9c0e0ac79e75 | 42 | |
jim_lsj | 0:9c0e0ac79e75 | 43 | winddirectionchar(0x2A71, (uint8_t *)&winddirection, |
jim_lsj | 0:9c0e0ac79e75 | 44 | sizeof(uint16_t), sizeof(uint16_t), |
jim_lsj | 0:9c0e0ac79e75 | 45 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), |
jim_lsj | 0:9c0e0ac79e75 | 46 | |
jim_lsj | 0:9c0e0ac79e75 | 47 | pressurechar(GattCharacteristic::UUID_PRESSURE_CHAR, (uint8_t *)&pressure, |
jim_lsj | 0:9c0e0ac79e75 | 48 | sizeof(uint32_t), sizeof(uint32_t), |
jim_lsj | 0:9c0e0ac79e75 | 49 | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) |
jim_lsj | 0:9c0e0ac79e75 | 50 | |
jim_lsj | 0:9c0e0ac79e75 | 51 | { // Setup Service |
jim_lsj | 0:9c0e0ac79e75 | 52 | |
jim_lsj | 0:9c0e0ac79e75 | 53 | |
jim_lsj | 0:9c0e0ac79e75 | 54 | GattCharacteristic *charTable[] = { &winddirectionchar, &pressurechar }; |
jim_lsj | 0:9c0e0ac79e75 | 55 | |
jim_lsj | 0:9c0e0ac79e75 | 56 | GattService EnvironmentalService(0x181A, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); |
jim_lsj | 0:9c0e0ac79e75 | 57 | |
jim_lsj | 1:b12ac7b02a21 | 58 | ble.gattServer().addService(EnvironmentalService); |
jim_lsj | 0:9c0e0ac79e75 | 59 | } |
jim_lsj | 0:9c0e0ac79e75 | 60 | |
jim_lsj | 0:9c0e0ac79e75 | 61 | |
jim_lsj | 0:9c0e0ac79e75 | 62 | /* Set a new 16-bit value for the wind direction measurement. */ |
jim_lsj | 0:9c0e0ac79e75 | 63 | void updateWinddirection(uint16_t winddirection) { |
jim_lsj | 1:b12ac7b02a21 | 64 | ble.gattServer().write(winddirectionchar.getValueAttribute().getHandle(), (uint8_t *)&winddirection, sizeof(uint16_t)); |
jim_lsj | 0:9c0e0ac79e75 | 65 | } |
jim_lsj | 0:9c0e0ac79e75 | 66 | /* Set a new 32-bit value for the pressure measurement. */ |
jim_lsj | 0:9c0e0ac79e75 | 67 | void updatePressure(uint32_t pressure) { |
jim_lsj | 1:b12ac7b02a21 | 68 | ble.gattServer().write(pressurechar.getValueAttribute().getHandle(), (uint8_t *)&pressure, sizeof(uint32_t)); |
jim_lsj | 0:9c0e0ac79e75 | 69 | } |
jim_lsj | 0:9c0e0ac79e75 | 70 | |
jim_lsj | 0:9c0e0ac79e75 | 71 | |
jim_lsj | 0:9c0e0ac79e75 | 72 | private: |
jim_lsj | 0:9c0e0ac79e75 | 73 | BLEDevice &ble; |
jim_lsj | 0:9c0e0ac79e75 | 74 | GattCharacteristic winddirectionchar; |
jim_lsj | 0:9c0e0ac79e75 | 75 | GattCharacteristic pressurechar; |
jim_lsj | 0:9c0e0ac79e75 | 76 | }; |
jim_lsj | 0:9c0e0ac79e75 | 77 | |
jim_lsj | 0:9c0e0ac79e75 | 78 | #endif /* #ifndef __BLE_ENVIRONMENTAL_SENSING_SERVICE2_H__*/ |
jim_lsj | 0:9c0e0ac79e75 | 79 | |
jim_lsj | 0:9c0e0ac79e75 | 80 | |
jim_lsj | 0:9c0e0ac79e75 | 81 | // *******************************ARM University Program Copyright © ARM Ltd 2015*************************************// |