X-NUCLEO-IKS01A1 Environmental/Motion sensors data transmitted via X-NUCLEO-IDB04A1 BLE board. Compatible with iOS/Android ST BlueMS V2.1 application.

Dependencies:   BLE_API X_NUCLEO_IDB0XA1 X_NUCLEO_IKS01A1 mbed

Fork of Bluemicrosystem1 by ST Expansion SW Team

BlueMicrosystem application

This application is the mbed equivalent of ST BlueMicrosystem1 and provides an example of motion and environmental data exported via Bluetooth Low Energy to an Android or IOS device.
It runs on a ST NUCLEO-F401RE board connected with a X-NUCLEO-IKS01A1 and a X-NUCLEO-IDB04A1 expansion boards and is compatible with Android and iOS ST BlueMS smartphone applications (based on Android and iOS BlueST SDKs).
By default the application is not providing sensor fusion and activity recognition features. However sensor fusion can be enabled following the steps below:

  • Download and install osxMotionFX library on your PC.
  • Obtain the free license for your board following the instructions
  • Copy the correct license into Middlewares/ST/STM32_OSX_MotionFX_Library/osx_license.h of your mbed program folder
  • Copy Middlewares/ST/STM32_OSX_MotionFX_Library/Inc/osx_motion_fx.h file
  • Rename the provided .lib Keil binary library giving it a .ar extension, then copy it into Middlewares/ST/STM32_OSX_MotionFX_Library/Lib of your mbed program folder
  • Enable USE_SENSOR_FUSION_LIB macro into MotionFX_Manager.h file and recompile.
Committer:
mapellil
Date:
Mon Dec 21 13:05:16 2015 +0000
Revision:
8:b042fe719f51
Parent:
7:34014895dda8
Child:
9:2693f9ef8ff7
Reworked ble congestion control

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mapellil 8:b042fe719f51 1 /* mbed Microcontroller Library
mapellil 8:b042fe719f51 2 * Copyright (c) 2006-2013 ARM Limited
mapellil 0:e93a11b4e044 3 *
mapellil 8:b042fe719f51 4 * Licensed under the Apache License, Version 2.0 (the "License");
mapellil 8:b042fe719f51 5 * you may not use this file except in compliance with the License.
mapellil 8:b042fe719f51 6 * You may obtain a copy of the License at
mapellil 0:e93a11b4e044 7 *
mapellil 8:b042fe719f51 8 * http://www.apache.org/licenses/LICENSE-2.0
mapellil 0:e93a11b4e044 9 *
mapellil 8:b042fe719f51 10 * Unless required by applicable law or agreed to in writing, software
mapellil 8:b042fe719f51 11 * distributed under the License is distributed on an "AS IS" BASIS,
mapellil 8:b042fe719f51 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mapellil 8:b042fe719f51 13 * See the License for the specific language governing permissions and
mapellil 8:b042fe719f51 14 * limitations under the License.
mapellil 0:e93a11b4e044 15 */
mapellil 0:e93a11b4e044 16
mapellil 0:e93a11b4e044 17 #ifndef __CUSTOM_BLE_SENSORS_SERVICE_H__
mapellil 0:e93a11b4e044 18 #define __CUSTOM_BLE_SENSORS_SERVICE_H__
mapellil 0:e93a11b4e044 19
mapellil 0:e93a11b4e044 20 #include "BLE.h"
mapellil 0:e93a11b4e044 21
mapellil 8:b042fe719f51 22 const LongUUIDBytes_t SENS_SERVICE_UUID_128 = { 0x1b,0xc5,0xa5,0xd5,0x02,0x00,0xb4,0x9a,0xe1,0x11,0x01,0x00,0x00,0x00,0x00,0x00}; // temp, pressure, humidity,
mapellil 8:b042fe719f51 23
mapellil 8:b042fe719f51 24 const LongUUIDBytes_t SENS_TEMP_CHAR_UUID_128 = { 0x1b,0xc5,0xa5,0xd5,0x02,0x00,0x36,0xac,0xe1,0x11,0x01,0x00,0x00,0x00,0x04,0x00 };
mapellil 8:b042fe719f51 25 const LongUUIDBytes_t SENS_HUMI_CHAR_UUID_128 = { 0x1b,0xc5,0xa5,0xd5,0x02,0x00,0x36,0xac,0xe1,0x11,0x01,0x00,0x00,0x00,0x08,0x00};
mapellil 8:b042fe719f51 26 const LongUUIDBytes_t SENS_PRES_CHAR_UUID_128 = { 0x1b,0xc5,0xa5,0xd5,0x02,0x00,0x36,0xac,0xe1,0x11,0x01,0x00,0x00,0x00,0x10,0x00};
mapellil 8:b042fe719f51 27 const LongUUIDBytes_t SENS_MAGN_CHAR_UUID_128 = { 0x1b,0xc5,0xa5,0xd5,0x02,0x00,0x36,0xac,0xe1,0x11,0x01,0x00,0x00,0x00,0x20,0x00};
mapellil 8:b042fe719f51 28 const LongUUIDBytes_t SENS_GYRO_CHAR_UUID_128 = { 0x1b,0xc5,0xa5,0xd5,0x02,0x00,0x36,0xac,0xe1,0x11,0x01,0x00,0x00,0x00,0x40,0x00};
mapellil 8:b042fe719f51 29 const LongUUIDBytes_t SENS_ACCE_CHAR_UUID_128 = { 0x1b,0xc5,0xa5,0xd5,0x02,0x00,0x36,0xac,0xe1,0x11,0x01,0x00,0x00,0x00,0x80,0x00};
mapellil 8:b042fe719f51 30 const LongUUIDBytes_t SENS_ACC_GYRO_MAG_CHAR_UUID_128 = { 0x1b,0xc5,0xa5,0xd5,0x02,0x00,0x36,0xac,0xe1,0x11,0x01,0x00,0x00,0x00,0xE0,0x00};
mapellil 8:b042fe719f51 31
mapellil 0:e93a11b4e044 32
mapellil 0:e93a11b4e044 33 #define TEMP_DATA_LEN 2+2
mapellil 0:e93a11b4e044 34 #define HUM_DATA_LEN 2+2
mapellil 0:e93a11b4e044 35 #define PRES_DATA_LEN 2+4
mapellil 0:e93a11b4e044 36 #define ACC_DATA_LEN 6+2
mapellil 0:e93a11b4e044 37 #define MAG_DATA_LEN 6+2
mapellil 0:e93a11b4e044 38 #define GYRO_DATA_LEN 6+2
mapellil 0:e93a11b4e044 39 #define ACCGYROMAG_DATA_LEN 2+3*3*2
mapellil 0:e93a11b4e044 40
mapellil 0:e93a11b4e044 41
mapellil 0:e93a11b4e044 42 /* Custom Sensors Service */
mapellil 0:e93a11b4e044 43 class CustomSensorService {
mapellil 0:e93a11b4e044 44 public:
mapellil 8:b042fe719f51 45 CustomSensorService(BLEDevice &_ble) :
mapellil 0:e93a11b4e044 46 ble(_ble),
mapellil 0:e93a11b4e044 47 envTemperatureCharacteristic(SENS_TEMP_CHAR_UUID_128,envTemperature, TEMP_DATA_LEN, TEMP_DATA_LEN,
mapellil 0:e93a11b4e044 48 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
mapellil 0:e93a11b4e044 49 envHumidityCharacteristic(SENS_HUMI_CHAR_UUID_128, envHumidity, HUM_DATA_LEN, HUM_DATA_LEN,
mapellil 0:e93a11b4e044 50 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
mapellil 0:e93a11b4e044 51 envPressureCharacteristic(SENS_PRES_CHAR_UUID_128, envPressure, PRES_DATA_LEN, PRES_DATA_LEN,
mapellil 0:e93a11b4e044 52 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
mapellil 0:e93a11b4e044 53 envMagnetometerCharacteristic(SENS_MAGN_CHAR_UUID_128,envMagn, MAG_DATA_LEN, MAG_DATA_LEN,
mapellil 0:e93a11b4e044 54 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
mapellil 0:e93a11b4e044 55 envAccelerometerCharacteristic(SENS_ACCE_CHAR_UUID_128,envAcce, ACC_DATA_LEN, ACC_DATA_LEN,
mapellil 0:e93a11b4e044 56 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
mapellil 0:e93a11b4e044 57 envGyroCharacteristic(SENS_GYRO_CHAR_UUID_128,envGyro, GYRO_DATA_LEN, GYRO_DATA_LEN,
mapellil 0:e93a11b4e044 58 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
mapellil 0:e93a11b4e044 59 envAccGyroMagCharacteristic(SENS_ACC_GYRO_MAG_CHAR_UUID_128,envAccGyroMag, ACCGYROMAG_DATA_LEN, ACCGYROMAG_DATA_LEN,
mapellil 0:e93a11b4e044 60 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
mapellil 0:e93a11b4e044 61 {
mapellil 0:e93a11b4e044 62
mapellil 0:e93a11b4e044 63 static bool serviceAdded = false; /* We should only ever need to add the env service once. */
mapellil 0:e93a11b4e044 64 if (serviceAdded) {
mapellil 0:e93a11b4e044 65 return;
mapellil 0:e93a11b4e044 66 }
mapellil 8:b042fe719f51 67
mapellil 0:e93a11b4e044 68 GattCharacteristic *charTable[] = {&envTemperatureCharacteristic, &envHumidityCharacteristic, &envPressureCharacteristic, &envMagnetometerCharacteristic,
mapellil 0:e93a11b4e044 69 &envAccelerometerCharacteristic, &envGyroCharacteristic, &envAccGyroMagCharacteristic};
mapellil 0:e93a11b4e044 70
mapellil 0:e93a11b4e044 71 GattService envService(SENS_SERVICE_UUID_128, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
mapellil 0:e93a11b4e044 72
mapellil 0:e93a11b4e044 73 ble.gattServer().addService(envService);
mapellil 0:e93a11b4e044 74
mapellil 0:e93a11b4e044 75 isEnabledTempNotify = false;
mapellil 0:e93a11b4e044 76 isEnabledHumNotify = false;
mapellil 0:e93a11b4e044 77 isEnabledPresNotify = false;
mapellil 0:e93a11b4e044 78 isEnabledGyroNotify = false;
mapellil 0:e93a11b4e044 79 isEnabledAccNotify = false;
mapellil 0:e93a11b4e044 80 isEnabledMagNotify = false;
mapellil 0:e93a11b4e044 81 isEnabledAccGyroMagNotify = false;
mapellil 0:e93a11b4e044 82
mapellil 0:e93a11b4e044 83 isTempCalibrated = false;
mapellil 0:e93a11b4e044 84 isHumCalibrated = false;
mapellil 0:e93a11b4e044 85 isPresCalibrated = false;
mapellil 0:e93a11b4e044 86 isMagCalibrated = false;
mapellil 0:e93a11b4e044 87 isAccCalibrated = false;
mapellil 0:e93a11b4e044 88 isAGyroCalibrated = false;
mapellil 0:e93a11b4e044 89
mapellil 0:e93a11b4e044 90 memset (pastenvTemperature, 0, TEMP_DATA_LEN);
mapellil 0:e93a11b4e044 91 memset (pastenvHumidity, 0, HUM_DATA_LEN);
mapellil 0:e93a11b4e044 92 memset (pastenvPressure, 0, PRES_DATA_LEN);
mapellil 0:e93a11b4e044 93
mapellil 0:e93a11b4e044 94 isBTLEConnected = DISCONNECTED;
mapellil 0:e93a11b4e044 95 serviceAdded = true;
mapellil 0:e93a11b4e044 96 }
mapellil 0:e93a11b4e044 97
mapellil 8:b042fe719f51 98 uint32_t sendEnvTemperature (int16_t Temp, uint16_t TimeStamp) {
mapellil 8:b042fe719f51 99 STORE_LE_16(envTemperature,TimeStamp);
mapellil 8:b042fe719f51 100 STORE_LE_16(envTemperature+2,Temp);
mapellil 8:b042fe719f51 101 PRINTF("sendEnvTemperature!! handle: %d\n\r", envTemperatureCharacteristic.getValueAttribute().getHandle());
mapellil 8:b042fe719f51 102 memcpy (pastenvTemperature, envTemperature, TEMP_DATA_LEN);
mapellil 8:b042fe719f51 103 return ble.gattServer().write(envTemperatureCharacteristic.getValueAttribute().getHandle(), envTemperature, TEMP_DATA_LEN, 0);
mapellil 0:e93a11b4e044 104 }
mapellil 0:e93a11b4e044 105
mapellil 0:e93a11b4e044 106 /**
mapellil 0:e93a11b4e044 107 * Update the temperature with a new value. Valid values range from
mapellil 0:e93a11b4e044 108 * 0..100. Anything outside this range will be ignored.
mapellil 0:e93a11b4e044 109 * @param newLevel New level. */
mapellil 8:b042fe719f51 110 uint32_t updateEnvTemperature (int16_t Temp, uint16_t TimeStamp) {
mapellil 0:e93a11b4e044 111 if (memcmp (&pastenvTemperature[2], &Temp, 2) != 0) {
mapellil 8:b042fe719f51 112 return sendEnvTemperature (Temp, TimeStamp);
mapellil 0:e93a11b4e044 113 }
mapellil 8:b042fe719f51 114 return 0;
mapellil 0:e93a11b4e044 115 }
mapellil 0:e93a11b4e044 116
mapellil 8:b042fe719f51 117 uint32_t sendEnvHumidity(uint16_t Hum, uint16_t TimeStamp) {
mapellil 8:b042fe719f51 118 STORE_LE_16(envHumidity,TimeStamp);
mapellil 8:b042fe719f51 119 STORE_LE_16(envHumidity+2,Hum);
mapellil 8:b042fe719f51 120 memcpy (pastenvHumidity, envHumidity, HUM_DATA_LEN);
mapellil 8:b042fe719f51 121 return ble.gattServer().write(envHumidityCharacteristic.getValueAttribute().getHandle(), envHumidity, HUM_DATA_LEN, 0);
mapellil 8:b042fe719f51 122 }
mapellil 0:e93a11b4e044 123
mapellil 8:b042fe719f51 124 uint32_t updateEnvHumidity(uint16_t Hum, uint16_t TimeStamp) {
mapellil 0:e93a11b4e044 125 if (memcmp (&pastenvHumidity[2], &Hum, 2) != 0) {
mapellil 8:b042fe719f51 126 return sendEnvHumidity(Hum, TimeStamp);
mapellil 0:e93a11b4e044 127 }
mapellil 8:b042fe719f51 128 return 0;
mapellil 0:e93a11b4e044 129 }
mapellil 0:e93a11b4e044 130
mapellil 8:b042fe719f51 131 uint32_t sendEnvPressure(uint32_t Press, uint16_t TimeStamp) {
mapellil 8:b042fe719f51 132 STORE_LE_16(envPressure,TimeStamp);
mapellil 8:b042fe719f51 133 STORE_LE_32(envPressure+2,Press);
mapellil 8:b042fe719f51 134 memcpy (pastenvPressure, envPressure, PRES_DATA_LEN);
mapellil 8:b042fe719f51 135 return ble.gattServer().write(envPressureCharacteristic.getValueAttribute().getHandle(), envPressure, PRES_DATA_LEN, 0);
mapellil 8:b042fe719f51 136 }
mapellil 0:e93a11b4e044 137
mapellil 8:b042fe719f51 138 uint32_t updateEnvPressure(uint32_t Press, uint16_t TimeStamp) {
mapellil 0:e93a11b4e044 139 if (memcmp (&pastenvPressure[2], &Press, 2) != 0) {
mapellil 8:b042fe719f51 140 return sendEnvPressure(Press, TimeStamp);
mapellil 8:b042fe719f51 141 }
mapellil 8:b042fe719f51 142 return 0;
mapellil 0:e93a11b4e044 143 }
mapellil 0:e93a11b4e044 144
mapellil 8:b042fe719f51 145 uint32_t sendEnvMagnetometer(AxesRaw_TypeDef *Magn, uint16_t TimeStamp, osxMFX_calibFactor magOffset) {
mapellil 8:b042fe719f51 146 STORE_LE_16(envMagn,TimeStamp);
mapellil 8:b042fe719f51 147 STORE_LE_16(envMagn+2,(Magn->AXIS_X - magOffset.magOffX));
mapellil 8:b042fe719f51 148 STORE_LE_16(envMagn+4,(Magn->AXIS_Y - magOffset.magOffY));
mapellil 8:b042fe719f51 149 STORE_LE_16(envMagn+6,(Magn->AXIS_Z - magOffset.magOffZ));
mapellil 8:b042fe719f51 150 return ble.gattServer().write(envMagnetometerCharacteristic.getValueAttribute().getHandle(), envMagn, MAG_DATA_LEN, 0);
mapellil 0:e93a11b4e044 151 }
mapellil 0:e93a11b4e044 152
mapellil 8:b042fe719f51 153 uint32_t updateEnvMagnetometer(AxesRaw_TypeDef *Magn, uint16_t TimeStamp, osxMFX_calibFactor magOffset) {
mapellil 8:b042fe719f51 154 if (isMagNotificationEn()) return sendEnvMagnetometer(Magn, TimeStamp, magOffset);
mapellil 8:b042fe719f51 155 return 0;
mapellil 0:e93a11b4e044 156 }
mapellil 0:e93a11b4e044 157
mapellil 8:b042fe719f51 158 uint32_t sendEnvAccelerometer (AxesRaw_TypeDef *Acc, uint16_t TimeStamp) {
mapellil 8:b042fe719f51 159 STORE_LE_16(envAcce,TimeStamp);
mapellil 8:b042fe719f51 160 STORE_LE_16(envAcce+2,Acc->AXIS_X);
mapellil 8:b042fe719f51 161 STORE_LE_16(envAcce+4,Acc->AXIS_Y);
mapellil 8:b042fe719f51 162 STORE_LE_16(envAcce+6,Acc->AXIS_Z);
mapellil 8:b042fe719f51 163 return ble.gattServer().write(envAccelerometerCharacteristic.getValueAttribute().getHandle(), envAcce, ACC_DATA_LEN, 0);
mapellil 0:e93a11b4e044 164 }
mapellil 0:e93a11b4e044 165
mapellil 8:b042fe719f51 166 uint32_t updateEnvAccelerometer (AxesRaw_TypeDef *Acc, uint16_t TimeStamp) {
mapellil 8:b042fe719f51 167 if (isAccNotificationEn()) return sendEnvAccelerometer (Acc, TimeStamp);
mapellil 8:b042fe719f51 168 return 0;
mapellil 0:e93a11b4e044 169 }
mapellil 0:e93a11b4e044 170
mapellil 8:b042fe719f51 171 uint32_t sendEnvGyroscope (AxesRaw_TypeDef *Gyro, uint16_t TimeStamp) {
mapellil 8:b042fe719f51 172 STORE_LE_16(envGyro,TimeStamp);
mapellil 8:b042fe719f51 173 STORE_LE_16(envGyro+2,Gyro->AXIS_X);
mapellil 8:b042fe719f51 174 STORE_LE_16(envGyro+4,Gyro->AXIS_Y);
mapellil 8:b042fe719f51 175 STORE_LE_16(envGyro+6,Gyro->AXIS_Z);
mapellil 8:b042fe719f51 176 return ble.gattServer().write(envGyroCharacteristic.getValueAttribute().getHandle(), envGyro, GYRO_DATA_LEN, 0);
mapellil 0:e93a11b4e044 177 }
mapellil 0:e93a11b4e044 178
mapellil 8:b042fe719f51 179 uint32_t updateEnvGyroscope (AxesRaw_TypeDef *Gyro, uint16_t TimeStamp) {
mapellil 8:b042fe719f51 180 if (isGyroNotificationEn()) return sendEnvGyroscope (Gyro, TimeStamp);
mapellil 8:b042fe719f51 181 return 0;
mapellil 0:e93a11b4e044 182 }
mapellil 0:e93a11b4e044 183
mapellil 8:b042fe719f51 184 uint32_t sendEnvAccGyroMag (AxesRaw_TypeDef *Acc, AxesRaw_TypeDef *Gyro, AxesRaw_TypeDef *Magn, uint16_t TimeStamp, osxMFX_calibFactor magOffset) {
mapellil 8:b042fe719f51 185 STORE_LE_16(envAccGyroMag,TimeStamp);
mapellil 8:b042fe719f51 186 STORE_LE_16(envAccGyroMag+2,Acc->AXIS_X);
mapellil 8:b042fe719f51 187 STORE_LE_16(envAccGyroMag+4,Acc->AXIS_Y);
mapellil 8:b042fe719f51 188 STORE_LE_16(envAccGyroMag+6,Acc->AXIS_Z);
mapellil 0:e93a11b4e044 189
mapellil 8:b042fe719f51 190 STORE_LE_16(envAccGyroMag+8,Gyro->AXIS_X);
mapellil 8:b042fe719f51 191 STORE_LE_16(envAccGyroMag+10,Gyro->AXIS_Y);
mapellil 8:b042fe719f51 192 STORE_LE_16(envAccGyroMag+12,Gyro->AXIS_Z);
mapellil 0:e93a11b4e044 193
mapellil 8:b042fe719f51 194 STORE_LE_16(envAccGyroMag+14,(Magn->AXIS_X - magOffset.magOffX));
mapellil 8:b042fe719f51 195 STORE_LE_16(envAccGyroMag+16,(Magn->AXIS_Y - magOffset.magOffY));
mapellil 8:b042fe719f51 196 STORE_LE_16(envAccGyroMag+18,(Magn->AXIS_Z - magOffset.magOffZ));
mapellil 8:b042fe719f51 197 return ble.gattServer().write(envAccGyroMagCharacteristic.getValueAttribute().getHandle(), envAccGyroMag, ACCGYROMAG_DATA_LEN, 0);
mapellil 0:e93a11b4e044 198 }
mapellil 0:e93a11b4e044 199
mapellil 8:b042fe719f51 200 uint32_t updateEnvAccGyroMag (AxesRaw_TypeDef *Acc, AxesRaw_TypeDef *Gyro, AxesRaw_TypeDef *Magn, uint16_t TimeStamp, osxMFX_calibFactor magOffset) {
mapellil 8:b042fe719f51 201 if (isAccGyroMagNotificationEn()) return sendEnvAccGyroMag (Acc, Gyro, Magn, TimeStamp, magOffset);
mapellil 8:b042fe719f51 202 return 0;
mapellil 0:e93a11b4e044 203 }
mapellil 0:e93a11b4e044 204
mapellil 0:e93a11b4e044 205 void enNotify (Gap::Handle_t handle) {
mapellil 0:e93a11b4e044 206 if (isTempHandle(handle)) { isEnabledTempNotify = true; memset(pastenvTemperature,0,TEMP_DATA_LEN); return; }
mapellil 0:e93a11b4e044 207 if (isHumHandle(handle)) { isEnabledHumNotify = true; memset(pastenvHumidity,0,HUM_DATA_LEN); return; }
mapellil 0:e93a11b4e044 208 if (isPresHandle(handle)) { isEnabledPresNotify = true; memset(pastenvPressure,0,PRES_DATA_LEN); return; }
mapellil 0:e93a11b4e044 209 if (isGyroHandle(handle)) { isEnabledGyroNotify = true; return; }
mapellil 0:e93a11b4e044 210 if (isAccHandle(handle)) { isEnabledAccNotify = true; return; }
mapellil 0:e93a11b4e044 211 if (isMagHandle(handle)) { isEnabledMagNotify = true; return; }
mapellil 0:e93a11b4e044 212 if (isAccGyroMagHandle(handle)) { isEnabledAccGyroMagNotify = true; return; }
mapellil 0:e93a11b4e044 213 }
mapellil 0:e93a11b4e044 214
mapellil 0:e93a11b4e044 215 void disNotify (Gap::Handle_t handle) {
mapellil 0:e93a11b4e044 216 if (isTempHandle(handle)) { isEnabledTempNotify = false; memset(pastenvTemperature,0,TEMP_DATA_LEN); return; }
mapellil 0:e93a11b4e044 217 if (isHumHandle(handle)) { isEnabledHumNotify = false; memset(pastenvHumidity,0,HUM_DATA_LEN); return; }
mapellil 0:e93a11b4e044 218 if (isPresHandle(handle)) { isEnabledPresNotify = false; memset(pastenvPressure,0,PRES_DATA_LEN); return; }
mapellil 0:e93a11b4e044 219 if (isGyroHandle(handle)) { isEnabledGyroNotify = false; return; }
mapellil 0:e93a11b4e044 220 if (isAccHandle(handle)) { isEnabledAccNotify = false; return; }
mapellil 0:e93a11b4e044 221 if (isMagHandle(handle)) { isEnabledMagNotify = false; return; }
mapellil 0:e93a11b4e044 222 if (isAccGyroMagHandle(handle)) { isEnabledAccGyroMagNotify = false; return; }
mapellil 0:e93a11b4e044 223 }
mapellil 0:e93a11b4e044 224
mapellil 0:e93a11b4e044 225 bool isTempNotificationEn (void) {
mapellil 0:e93a11b4e044 226 return isEnabledTempNotify;
mapellil 0:e93a11b4e044 227 }
mapellil 0:e93a11b4e044 228
mapellil 0:e93a11b4e044 229 bool isHumNotificationEn (void) {
mapellil 0:e93a11b4e044 230 return isEnabledHumNotify;
mapellil 0:e93a11b4e044 231 }
mapellil 0:e93a11b4e044 232
mapellil 0:e93a11b4e044 233 bool isPresNotificationEn (void) {
mapellil 0:e93a11b4e044 234 return isEnabledPresNotify;
mapellil 0:e93a11b4e044 235 }
mapellil 0:e93a11b4e044 236
mapellil 0:e93a11b4e044 237 bool isGyroNotificationEn (void) {
mapellil 0:e93a11b4e044 238 return isEnabledGyroNotify;
mapellil 0:e93a11b4e044 239 }
mapellil 0:e93a11b4e044 240
mapellil 0:e93a11b4e044 241 bool isAccNotificationEn (void) {
mapellil 0:e93a11b4e044 242 return isEnabledAccNotify;
mapellil 0:e93a11b4e044 243 }
mapellil 0:e93a11b4e044 244
mapellil 0:e93a11b4e044 245 bool isMagNotificationEn (void) {
mapellil 0:e93a11b4e044 246 return isEnabledMagNotify;
mapellil 0:e93a11b4e044 247 }
mapellil 0:e93a11b4e044 248
mapellil 0:e93a11b4e044 249 bool isAccGyroMagNotificationEn (void) {
mapellil 0:e93a11b4e044 250 return isEnabledAccGyroMagNotify;
mapellil 0:e93a11b4e044 251 }
mapellil 0:e93a11b4e044 252
mapellil 0:e93a11b4e044 253 bool isTempHandle (Gap::Handle_t handle) {
mapellil 0:e93a11b4e044 254 if (handle == envTemperatureCharacteristic.getValueAttribute().getHandle()) return true;
mapellil 0:e93a11b4e044 255 return false;
mapellil 0:e93a11b4e044 256 }
mapellil 0:e93a11b4e044 257
mapellil 0:e93a11b4e044 258 bool isHumHandle (Gap::Handle_t handle) {
mapellil 0:e93a11b4e044 259 if (handle == envHumidityCharacteristic.getValueAttribute().getHandle()) return true;
mapellil 0:e93a11b4e044 260 return false;
mapellil 0:e93a11b4e044 261 }
mapellil 0:e93a11b4e044 262
mapellil 0:e93a11b4e044 263 bool isPresHandle (Gap::Handle_t handle) {
mapellil 0:e93a11b4e044 264 if (handle == envPressureCharacteristic.getValueAttribute().getHandle()) return true;
mapellil 0:e93a11b4e044 265 return false;
mapellil 0:e93a11b4e044 266 }
mapellil 0:e93a11b4e044 267
mapellil 0:e93a11b4e044 268 bool isMagHandle (Gap::Handle_t handle) {
mapellil 0:e93a11b4e044 269 if (handle == envMagnetometerCharacteristic.getValueAttribute().getHandle()) return true;
mapellil 0:e93a11b4e044 270 return false;
mapellil 0:e93a11b4e044 271 }
mapellil 0:e93a11b4e044 272 bool isAccHandle (Gap::Handle_t handle) {
mapellil 0:e93a11b4e044 273 if (handle == envAccelerometerCharacteristic.getValueAttribute().getHandle()) return true;
mapellil 0:e93a11b4e044 274 return false;
mapellil 0:e93a11b4e044 275 }
mapellil 0:e93a11b4e044 276 bool isGyroHandle (Gap::Handle_t handle) {
mapellil 0:e93a11b4e044 277 if (handle == envGyroCharacteristic.getValueAttribute().getHandle()) return true;
mapellil 0:e93a11b4e044 278 return false;
mapellil 0:e93a11b4e044 279 }
mapellil 0:e93a11b4e044 280 bool isAccGyroMagHandle (Gap::Handle_t handle) {
mapellil 0:e93a11b4e044 281 if (handle == envAccGyroMagCharacteristic.getValueAttribute().getHandle()) return true;
mapellil 0:e93a11b4e044 282 return false;
mapellil 0:e93a11b4e044 283 }
mapellil 0:e93a11b4e044 284
mapellil 0:e93a11b4e044 285 void updateConnectionStatus(ConnectionStatus_t status) {
mapellil 0:e93a11b4e044 286 isEnabledTempNotify = false;
mapellil 0:e93a11b4e044 287 isEnabledHumNotify = false;
mapellil 0:e93a11b4e044 288 isEnabledPresNotify = false;
mapellil 0:e93a11b4e044 289 isEnabledGyroNotify = false;
mapellil 0:e93a11b4e044 290 isEnabledAccNotify = false;
mapellil 0:e93a11b4e044 291 isEnabledMagNotify = false;
mapellil 0:e93a11b4e044 292 isEnabledAccGyroMagNotify = false;
mapellil 0:e93a11b4e044 293
mapellil 0:e93a11b4e044 294 isTempCalibrated = false;
mapellil 0:e93a11b4e044 295 isHumCalibrated = false;
mapellil 0:e93a11b4e044 296 isPresCalibrated = false;
mapellil 0:e93a11b4e044 297 isMagCalibrated = false;
mapellil 0:e93a11b4e044 298 isAccCalibrated = false;
mapellil 0:e93a11b4e044 299 isAGyroCalibrated = false;
mapellil 0:e93a11b4e044 300
mapellil 0:e93a11b4e044 301 memset (pastenvTemperature, 0, TEMP_DATA_LEN);
mapellil 0:e93a11b4e044 302 memset (pastenvHumidity, 0, HUM_DATA_LEN);
mapellil 0:e93a11b4e044 303 memset (pastenvPressure, 0, PRES_DATA_LEN);
mapellil 0:e93a11b4e044 304 isBTLEConnected = status;
mapellil 0:e93a11b4e044 305 }
mapellil 0:e93a11b4e044 306
mapellil 0:e93a11b4e044 307
mapellil 0:e93a11b4e044 308 private:
mapellil 8:b042fe719f51 309 BLEDevice &ble;
mapellil 0:e93a11b4e044 310 uint8_t envTemperature [TEMP_DATA_LEN]; /* in C */
mapellil 0:e93a11b4e044 311 uint8_t pastenvTemperature [TEMP_DATA_LEN];
mapellil 0:e93a11b4e044 312 uint8_t envHumidity [HUM_DATA_LEN]; /* in % */
mapellil 0:e93a11b4e044 313 uint8_t pastenvHumidity [HUM_DATA_LEN];
mapellil 0:e93a11b4e044 314 uint8_t envPressure [PRES_DATA_LEN]; /* in mBar */
mapellil 0:e93a11b4e044 315 uint8_t pastenvPressure [PRES_DATA_LEN];
mapellil 0:e93a11b4e044 316 uint8_t envMagn [MAG_DATA_LEN];
mapellil 0:e93a11b4e044 317 uint8_t envGyro [GYRO_DATA_LEN];
mapellil 0:e93a11b4e044 318 uint8_t envAcce [ACC_DATA_LEN];
mapellil 0:e93a11b4e044 319 uint8_t envAccGyroMag [ACCGYROMAG_DATA_LEN];
mapellil 0:e93a11b4e044 320
mapellil 0:e93a11b4e044 321 GattCharacteristic envTemperatureCharacteristic;
mapellil 0:e93a11b4e044 322 GattCharacteristic envHumidityCharacteristic;
mapellil 0:e93a11b4e044 323 GattCharacteristic envPressureCharacteristic;
mapellil 0:e93a11b4e044 324
mapellil 0:e93a11b4e044 325 GattCharacteristic envMagnetometerCharacteristic;
mapellil 0:e93a11b4e044 326 GattCharacteristic envAccelerometerCharacteristic;
mapellil 0:e93a11b4e044 327 GattCharacteristic envGyroCharacteristic;
mapellil 0:e93a11b4e044 328 GattCharacteristic envAccGyroMagCharacteristic;
mapellil 0:e93a11b4e044 329
mapellil 0:e93a11b4e044 330 ConnectionStatus_t isBTLEConnected;
mapellil 0:e93a11b4e044 331
mapellil 0:e93a11b4e044 332 bool isEnabledTempNotify;
mapellil 0:e93a11b4e044 333 bool isEnabledHumNotify;
mapellil 0:e93a11b4e044 334 bool isEnabledPresNotify;
mapellil 0:e93a11b4e044 335 bool isEnabledGyroNotify;
mapellil 0:e93a11b4e044 336 bool isEnabledAccNotify;
mapellil 0:e93a11b4e044 337 bool isEnabledMagNotify;
mapellil 0:e93a11b4e044 338 bool isEnabledAccGyroMagNotify;
mapellil 0:e93a11b4e044 339
mapellil 0:e93a11b4e044 340 bool isTempCalibrated;
mapellil 0:e93a11b4e044 341 bool isHumCalibrated;
mapellil 0:e93a11b4e044 342 bool isPresCalibrated;
mapellil 0:e93a11b4e044 343 bool isMagCalibrated;
mapellil 0:e93a11b4e044 344 bool isAccCalibrated;
mapellil 0:e93a11b4e044 345 bool isAGyroCalibrated;
mapellil 0:e93a11b4e044 346
mapellil 0:e93a11b4e044 347 };
mapellil 0:e93a11b4e044 348
mapellil 0:e93a11b4e044 349 #endif /* #ifndef __CUSTOM_BLE_SENSORS_SERVICE_H__*/