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
ESS2.h
00001 /* ARM University Program Microcontroller Library 00002 * 00003 * Environmental Sensing Service 00004 * 00005 * This software is distributed under an "AS IS" BASIS, 00006 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00007 */ 00008 00009 #ifndef __BLE_ENVIRONMENTAL_SENSING_SERVICE2_H__ 00010 #define __BLE_ENVIRONMENTAL_SENSING_SERVICE2_H__ 00011 00012 #include <mbed.h> 00013 #include "blecommon.h" 00014 #include "Gap.h" 00015 #include "GattServer.h" 00016 #include "BLEDeviceInstanceBase.h" 00017 //#include "BLEDevice.h" 00018 00019 /* Environmental Sensing Service */ 00020 /* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.environmental_sensing.xml */ 00021 /* True wind direction characteristic: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.true_wind_direction.xml*/ 00022 /* Pressure characteristic: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.pressure.xml */ 00023 00024 00025 class EnvironmentalSensingService2 { 00026 00027 public: 00028 /** 00029 * Constructor. 00030 * 00031 * param[in] _ble 00032 * Reference to the underlying BLEDevice. 00033 * param[in] True Wind Direction in degrees (16-bit unsigned, 2 decimals). Wind coming from: 0=North, 90=East, 180=South and 270=West. 00034 * initial value for the temperature 00035 * param[in] pressure in Pascals (32-bit unsigned, 1 decimal). 00036 * initial value for the pressure value. 00037 */ 00038 EnvironmentalSensingService2(BLEDevice &_ble, uint16_t winddirection, uint32_t pressure) : 00039 ble(_ble), 00040 00041 00042 00043 winddirectionchar(0x2A71, (uint8_t *)&winddirection, 00044 sizeof(uint16_t), sizeof(uint16_t), 00045 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), 00046 00047 pressurechar(GattCharacteristic::UUID_PRESSURE_CHAR, (uint8_t *)&pressure, 00048 sizeof(uint32_t), sizeof(uint32_t), 00049 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) 00050 00051 { // Setup Service 00052 00053 00054 GattCharacteristic *charTable[] = { &winddirectionchar, &pressurechar }; 00055 00056 GattService EnvironmentalService2(0x181A, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); 00057 00058 ble.gattServer().addService(EnvironmentalService2); 00059 } 00060 00061 00062 /* Set a new 16-bit value for the wind direction measurement. */ 00063 void updateWinddirection(uint16_t winddirection) { 00064 ble.gattServer().write(winddirectionchar.getValueAttribute().getHandle(), (uint8_t *)&winddirection, sizeof(uint16_t)); 00065 } 00066 /* Set a new 32-bit value for the pressure measurement. */ 00067 void updatePressure(uint32_t pressure) { 00068 ble.gattServer().write(pressurechar.getValueAttribute().getHandle(), (uint8_t *)&pressure, sizeof(uint32_t)); 00069 } 00070 00071 00072 private: 00073 BLEDevice &ble; 00074 GattCharacteristic winddirectionchar; 00075 GattCharacteristic pressurechar; 00076 }; 00077 00078 #endif /* #ifndef __BLE_ENVIRONMENTAL_SENSING_SERVICE2_H__*/ 00079 00080 00081 // *******************************ARM University Program Copyright © ARM Ltd 2015*************************************//
Generated on Tue Jul 18 2023 16:19:15 by
1.7.2