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:
Tue Jun 21 13:04:42 2016 +0000
Revision:
13:d00147d01d4e
Parent:
12:baf8b5294320
updated BLE lib link, defined BLE offsets as #define

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mapellil 9:2693f9ef8ff7 1 /**
mapellil 9:2693f9ef8ff7 2 ******************************************************************************
mapellil 9:2693f9ef8ff7 3 * @file CustomSensorService.h
mapellil 9:2693f9ef8ff7 4 * @author Central Labs / AST
mapellil 9:2693f9ef8ff7 5 * @version V0.9.0
mapellil 9:2693f9ef8ff7 6 * @date 23-Dec-2015
mapellil 9:2693f9ef8ff7 7 * @brief BLE MEMS and environmental sensors service
mapellil 9:2693f9ef8ff7 8 ******************************************************************************
mapellil 9:2693f9ef8ff7 9 * @attention
mapellil 9:2693f9ef8ff7 10 *
mapellil 9:2693f9ef8ff7 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mapellil 9:2693f9ef8ff7 12 *
mapellil 9:2693f9ef8ff7 13 * Redistribution and use in source and binary forms, with or without modification,
mapellil 9:2693f9ef8ff7 14 * are permitted provided that the following conditions are met:
mapellil 9:2693f9ef8ff7 15 * 1. Redistributions of source code must retain the above copyright notice,
mapellil 9:2693f9ef8ff7 16 * this list of conditions and the following disclaimer.
mapellil 9:2693f9ef8ff7 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
mapellil 9:2693f9ef8ff7 18 * this list of conditions and the following disclaimer in the documentation
mapellil 9:2693f9ef8ff7 19 * and/or other materials provided with the distribution.
mapellil 9:2693f9ef8ff7 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mapellil 9:2693f9ef8ff7 21 * may be used to endorse or promote products derived from this software
mapellil 9:2693f9ef8ff7 22 * without specific prior written permission.
mapellil 9:2693f9ef8ff7 23 *
mapellil 9:2693f9ef8ff7 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mapellil 9:2693f9ef8ff7 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mapellil 9:2693f9ef8ff7 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mapellil 9:2693f9ef8ff7 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mapellil 9:2693f9ef8ff7 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mapellil 9:2693f9ef8ff7 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mapellil 9:2693f9ef8ff7 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mapellil 9:2693f9ef8ff7 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mapellil 9:2693f9ef8ff7 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mapellil 9:2693f9ef8ff7 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mapellil 9:2693f9ef8ff7 34 *
mapellil 9:2693f9ef8ff7 35 ******************************************************************************
mapellil 9:2693f9ef8ff7 36 */
mapellil 0:e93a11b4e044 37
mapellil 0:e93a11b4e044 38 #ifndef __CUSTOM_BLE_SENSORS_SERVICE_H__
mapellil 0:e93a11b4e044 39 #define __CUSTOM_BLE_SENSORS_SERVICE_H__
mapellil 0:e93a11b4e044 40
mapellil 0:e93a11b4e044 41 #include "BLE.h"
mapellil 0:e93a11b4e044 42
mapellil 11:ff82699c696e 43 const LongUUIDBytes_t SENS_SERVICE_UUID_128 = { 0x00,0x00,0x00,0x00,0x00,0x01,0x11,0xe1,0x9a,0xb4,0x00,0x02,0xa5,0xd5,0xc5,0x1b }; // temp, pressure, humidity,
mapellil 11:ff82699c696e 44 const LongUUIDBytes_t SENS_TEMP_CHAR_UUID_128 = { 0x00,0x04,0x00,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b };
mapellil 11:ff82699c696e 45 const LongUUIDBytes_t SENS_HUMI_CHAR_UUID_128 = { 0x00,0x08,0x00,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b };
mapellil 11:ff82699c696e 46 const LongUUIDBytes_t SENS_PRES_CHAR_UUID_128 = { 0x00,0x10,0x00,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b };
mapellil 11:ff82699c696e 47 const LongUUIDBytes_t SENS_MAGN_CHAR_UUID_128 = { 0x00,0x20,0x00,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b };
mapellil 11:ff82699c696e 48 const LongUUIDBytes_t SENS_GYRO_CHAR_UUID_128 = { 0x00,0x40,0x00,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b };
mapellil 9:2693f9ef8ff7 49 const LongUUIDBytes_t SENS_ACCE_CHAR_UUID_128 = { 0x00,0x80,0x00,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b };
mapellil 9:2693f9ef8ff7 50 const LongUUIDBytes_t SENS_ACC_GYRO_MAG_CHAR_UUID_128 = { 0x00,0xE0,0x00,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b };
mapellil 8:b042fe719f51 51
mapellil 0:e93a11b4e044 52
mapellil 0:e93a11b4e044 53 #define TEMP_DATA_LEN 2+2
mapellil 0:e93a11b4e044 54 #define HUM_DATA_LEN 2+2
mapellil 0:e93a11b4e044 55 #define PRES_DATA_LEN 2+4
mapellil 11:ff82699c696e 56 #define ACC_DATA_LEN 6+2
mapellil 0:e93a11b4e044 57 #define MAG_DATA_LEN 6+2
mapellil 0:e93a11b4e044 58 #define GYRO_DATA_LEN 6+2
mapellil 0:e93a11b4e044 59 #define ACCGYROMAG_DATA_LEN 2+3*3*2
mapellil 0:e93a11b4e044 60
mapellil 0:e93a11b4e044 61
mapellil 0:e93a11b4e044 62 /* Custom Sensors Service */
mapellil 11:ff82699c696e 63 class CustomSensorService
mapellil 11:ff82699c696e 64 {
mapellil 0:e93a11b4e044 65 public:
mapellil 9:2693f9ef8ff7 66 CustomSensorService(BLE &_ble) :
mapellil 0:e93a11b4e044 67 ble(_ble),
mapellil 11:ff82699c696e 68 envTemperatureCharacteristic(SENS_TEMP_CHAR_UUID_128,envTemperature, TEMP_DATA_LEN, TEMP_DATA_LEN,
mapellil 11:ff82699c696e 69 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
mapellil 11:ff82699c696e 70 envHumidityCharacteristic(SENS_HUMI_CHAR_UUID_128, envHumidity, HUM_DATA_LEN, HUM_DATA_LEN,
mapellil 11:ff82699c696e 71 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
mapellil 11:ff82699c696e 72 envPressureCharacteristic(SENS_PRES_CHAR_UUID_128, envPressure, PRES_DATA_LEN, PRES_DATA_LEN,
mapellil 11:ff82699c696e 73 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
mapellil 11:ff82699c696e 74 envMagnetometerCharacteristic(SENS_MAGN_CHAR_UUID_128,envMagn, MAG_DATA_LEN, MAG_DATA_LEN,
mapellil 11:ff82699c696e 75 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
mapellil 11:ff82699c696e 76 envAccelerometerCharacteristic(SENS_ACCE_CHAR_UUID_128,envAcce, ACC_DATA_LEN, ACC_DATA_LEN,
mapellil 11:ff82699c696e 77 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
mapellil 11:ff82699c696e 78 envGyroCharacteristic(SENS_GYRO_CHAR_UUID_128,envGyro, GYRO_DATA_LEN, GYRO_DATA_LEN,
mapellil 11:ff82699c696e 79 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
mapellil 11:ff82699c696e 80 envAccGyroMagCharacteristic(SENS_ACC_GYRO_MAG_CHAR_UUID_128,envAccGyroMag, ACCGYROMAG_DATA_LEN, ACCGYROMAG_DATA_LEN,
mapellil 11:ff82699c696e 81 GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) {
mapellil 11:ff82699c696e 82
mapellil 0:e93a11b4e044 83 static bool serviceAdded = false; /* We should only ever need to add the env service once. */
mapellil 0:e93a11b4e044 84 if (serviceAdded) {
mapellil 0:e93a11b4e044 85 return;
mapellil 0:e93a11b4e044 86 }
mapellil 8:b042fe719f51 87
mapellil 0:e93a11b4e044 88 GattCharacteristic *charTable[] = {&envTemperatureCharacteristic, &envHumidityCharacteristic, &envPressureCharacteristic, &envMagnetometerCharacteristic,
mapellil 11:ff82699c696e 89 &envAccelerometerCharacteristic, &envGyroCharacteristic, &envAccGyroMagCharacteristic
mapellil 11:ff82699c696e 90 };
mapellil 11:ff82699c696e 91
mapellil 11:ff82699c696e 92 GattService envService(SENS_SERVICE_UUID_128, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
mapellil 11:ff82699c696e 93
mapellil 11:ff82699c696e 94 ble.gattServer().addService(envService);
mapellil 0:e93a11b4e044 95
mapellil 0:e93a11b4e044 96 isEnabledTempNotify = false;
mapellil 0:e93a11b4e044 97 isEnabledHumNotify = false;
mapellil 0:e93a11b4e044 98 isEnabledPresNotify = false;
mapellil 11:ff82699c696e 99 isEnabledGyroNotify = false;
mapellil 0:e93a11b4e044 100 isEnabledAccNotify = false;
mapellil 0:e93a11b4e044 101 isEnabledMagNotify = false;
mapellil 11:ff82699c696e 102 isEnabledAccGyroMagNotify = false;
mapellil 11:ff82699c696e 103
mapellil 0:e93a11b4e044 104 isTempCalibrated = false;
mapellil 0:e93a11b4e044 105 isHumCalibrated = false;
mapellil 11:ff82699c696e 106 isPresCalibrated = false;
mapellil 0:e93a11b4e044 107 isMagCalibrated = false;
mapellil 11:ff82699c696e 108 isAccCalibrated = false;
mapellil 11:ff82699c696e 109 isAGyroCalibrated = false;
mapellil 0:e93a11b4e044 110
mapellil 11:ff82699c696e 111 memset (pastenvTemperature, 0, TEMP_DATA_LEN);
mapellil 11:ff82699c696e 112 memset (pastenvHumidity, 0, HUM_DATA_LEN);
mapellil 11:ff82699c696e 113 memset (pastenvPressure, 0, PRES_DATA_LEN);
mapellil 11:ff82699c696e 114
mapellil 11:ff82699c696e 115 isBTLEConnected = DISCONNECTED;
mapellil 11:ff82699c696e 116 serviceAdded = true;
mapellil 0:e93a11b4e044 117 }
mapellil 0:e93a11b4e044 118
mapellil 8:b042fe719f51 119 uint32_t sendEnvTemperature (int16_t Temp, uint16_t TimeStamp) {
mapellil 11:ff82699c696e 120 STORE_LE_16(envTemperature,TimeStamp);
mapellil 11:ff82699c696e 121 STORE_LE_16(envTemperature+2,Temp);
mapellil 11:ff82699c696e 122 PRINTF("sendEnvTemperature!! handle: %d\n\r", envTemperatureCharacteristic.getValueAttribute().getHandle());
mapellil 11:ff82699c696e 123 memcpy (pastenvTemperature, envTemperature, TEMP_DATA_LEN);
mapellil 11:ff82699c696e 124 return ble.gattServer().write(envTemperatureCharacteristic.getValueAttribute().getHandle(), envTemperature, TEMP_DATA_LEN, 0);
mapellil 11:ff82699c696e 125 }
mapellil 11:ff82699c696e 126
mapellil 0:e93a11b4e044 127 /**
mapellil 0:e93a11b4e044 128 * Update the temperature with a new value. Valid values range from
mapellil 0:e93a11b4e044 129 * 0..100. Anything outside this range will be ignored.
mapellil 0:e93a11b4e044 130 * @param newLevel New level. */
mapellil 8:b042fe719f51 131 uint32_t updateEnvTemperature (int16_t Temp, uint16_t TimeStamp) {
mapellil 11:ff82699c696e 132 if (memcmp (&pastenvTemperature[2], &Temp, 2) != 0) {
mapellil 11:ff82699c696e 133 return sendEnvTemperature (Temp, TimeStamp);
mapellil 0:e93a11b4e044 134 }
mapellil 11:ff82699c696e 135 return 0;
mapellil 11:ff82699c696e 136 }
mapellil 11:ff82699c696e 137
mapellil 11:ff82699c696e 138 uint32_t sendEnvHumidity(uint16_t Hum, uint16_t TimeStamp) {
mapellil 11:ff82699c696e 139 STORE_LE_16(envHumidity,TimeStamp);
mapellil 11:ff82699c696e 140 STORE_LE_16(envHumidity+2,Hum);
mapellil 11:ff82699c696e 141 memcpy (pastenvHumidity, envHumidity, HUM_DATA_LEN);
mapellil 11:ff82699c696e 142 return ble.gattServer().write(envHumidityCharacteristic.getValueAttribute().getHandle(), envHumidity, HUM_DATA_LEN, 0);
mapellil 11:ff82699c696e 143 }
mapellil 11:ff82699c696e 144
mapellil 8:b042fe719f51 145 uint32_t updateEnvHumidity(uint16_t Hum, uint16_t TimeStamp) {
mapellil 11:ff82699c696e 146 if (memcmp (&pastenvHumidity[2], &Hum, 2) != 0) {
mapellil 11:ff82699c696e 147 return sendEnvHumidity(Hum, TimeStamp);
mapellil 11:ff82699c696e 148 }
mapellil 11:ff82699c696e 149 return 0;
mapellil 11:ff82699c696e 150 }
mapellil 11:ff82699c696e 151
mapellil 8:b042fe719f51 152 uint32_t sendEnvPressure(uint32_t Press, uint16_t TimeStamp) {
mapellil 11:ff82699c696e 153 STORE_LE_16(envPressure,TimeStamp);
mapellil 11:ff82699c696e 154 STORE_LE_32(envPressure+2,Press);
mapellil 11:ff82699c696e 155 memcpy (pastenvPressure, envPressure, PRES_DATA_LEN);
mapellil 11:ff82699c696e 156 return ble.gattServer().write(envPressureCharacteristic.getValueAttribute().getHandle(), envPressure, PRES_DATA_LEN, 0);
mapellil 11:ff82699c696e 157 }
mapellil 11:ff82699c696e 158
mapellil 8:b042fe719f51 159 uint32_t updateEnvPressure(uint32_t Press, uint16_t TimeStamp) {
mapellil 11:ff82699c696e 160 if (memcmp (&pastenvPressure[2], &Press, 2) != 0) {
mapellil 11:ff82699c696e 161 return sendEnvPressure(Press, TimeStamp);
mapellil 11:ff82699c696e 162 }
mapellil 11:ff82699c696e 163 return 0;
mapellil 11:ff82699c696e 164 }
mapellil 11:ff82699c696e 165
mapellil 11:ff82699c696e 166 uint32_t sendEnvMagnetometer(AxesRaw_TypeDef *Magn, uint16_t TimeStamp, osxMFX_calibFactor magOffset) {
mapellil 11:ff82699c696e 167 STORE_LE_16(envMagn,TimeStamp);
mapellil 11:ff82699c696e 168 STORE_LE_16(envMagn+2,(Magn->AXIS_X - magOffset.magOffX));
mapellil 11:ff82699c696e 169 STORE_LE_16(envMagn+4,(Magn->AXIS_Y - magOffset.magOffY));
mapellil 11:ff82699c696e 170 STORE_LE_16(envMagn+6,(Magn->AXIS_Z - magOffset.magOffZ));
mapellil 11:ff82699c696e 171 return ble.gattServer().write(envMagnetometerCharacteristic.getValueAttribute().getHandle(), envMagn, MAG_DATA_LEN, 0);
mapellil 11:ff82699c696e 172 }
mapellil 11:ff82699c696e 173
mapellil 11:ff82699c696e 174 uint32_t updateEnvMagnetometer(AxesRaw_TypeDef *Magn, uint16_t TimeStamp, osxMFX_calibFactor magOffset) {
mapellil 11:ff82699c696e 175 if (isMagNotificationEn()) return sendEnvMagnetometer(Magn, TimeStamp, magOffset);
mapellil 11:ff82699c696e 176 return 0;
mapellil 0:e93a11b4e044 177 }
mapellil 11:ff82699c696e 178
mapellil 11:ff82699c696e 179 uint32_t sendEnvAccelerometer (AxesRaw_TypeDef *Acc, uint16_t TimeStamp) {
mapellil 11:ff82699c696e 180 STORE_LE_16(envAcce,TimeStamp);
mapellil 11:ff82699c696e 181 STORE_LE_16(envAcce+2,Acc->AXIS_X);
mapellil 11:ff82699c696e 182 STORE_LE_16(envAcce+4,Acc->AXIS_Y);
mapellil 11:ff82699c696e 183 STORE_LE_16(envAcce+6,Acc->AXIS_Z);
mapellil 11:ff82699c696e 184 return ble.gattServer().write(envAccelerometerCharacteristic.getValueAttribute().getHandle(), envAcce, ACC_DATA_LEN, 0);
mapellil 11:ff82699c696e 185 }
mapellil 11:ff82699c696e 186
mapellil 11:ff82699c696e 187 uint32_t updateEnvAccelerometer (AxesRaw_TypeDef *Acc, uint16_t TimeStamp) {
mapellil 11:ff82699c696e 188 if (isAccNotificationEn()) return sendEnvAccelerometer (Acc, TimeStamp);
mapellil 11:ff82699c696e 189 return 0;
mapellil 0:e93a11b4e044 190 }
mapellil 0:e93a11b4e044 191
mapellil 11:ff82699c696e 192 uint32_t sendEnvGyroscope (AxesRaw_TypeDef *Gyro, uint16_t TimeStamp) {
mapellil 11:ff82699c696e 193 STORE_LE_16(envGyro,TimeStamp);
mapellil 11:ff82699c696e 194 STORE_LE_16(envGyro+2,Gyro->AXIS_X);
mapellil 11:ff82699c696e 195 STORE_LE_16(envGyro+4,Gyro->AXIS_Y);
mapellil 11:ff82699c696e 196 STORE_LE_16(envGyro+6,Gyro->AXIS_Z);
mapellil 11:ff82699c696e 197 return ble.gattServer().write(envGyroCharacteristic.getValueAttribute().getHandle(), envGyro, GYRO_DATA_LEN, 0);
mapellil 11:ff82699c696e 198 }
mapellil 11:ff82699c696e 199
mapellil 11:ff82699c696e 200 uint32_t updateEnvGyroscope (AxesRaw_TypeDef *Gyro, uint16_t TimeStamp) {
mapellil 11:ff82699c696e 201 if (isGyroNotificationEn()) return sendEnvGyroscope (Gyro, TimeStamp);
mapellil 11:ff82699c696e 202 return 0;
mapellil 11:ff82699c696e 203 }
mapellil 0:e93a11b4e044 204
mapellil 8:b042fe719f51 205 uint32_t sendEnvAccGyroMag (AxesRaw_TypeDef *Acc, AxesRaw_TypeDef *Gyro, AxesRaw_TypeDef *Magn, uint16_t TimeStamp, osxMFX_calibFactor magOffset) {
mapellil 11:ff82699c696e 206 STORE_LE_16(envAccGyroMag,TimeStamp);
mapellil 11:ff82699c696e 207 STORE_LE_16(envAccGyroMag+2,Acc->AXIS_X);
mapellil 11:ff82699c696e 208 STORE_LE_16(envAccGyroMag+4,Acc->AXIS_Y);
mapellil 11:ff82699c696e 209 STORE_LE_16(envAccGyroMag+6,Acc->AXIS_Z);
mapellil 11:ff82699c696e 210
mapellil 11:ff82699c696e 211 STORE_LE_16(envAccGyroMag+8,Gyro->AXIS_X);
mapellil 11:ff82699c696e 212 STORE_LE_16(envAccGyroMag+10,Gyro->AXIS_Y);
mapellil 11:ff82699c696e 213 STORE_LE_16(envAccGyroMag+12,Gyro->AXIS_Z);
mapellil 11:ff82699c696e 214
mapellil 11:ff82699c696e 215 STORE_LE_16(envAccGyroMag+14,(Magn->AXIS_X - magOffset.magOffX));
mapellil 11:ff82699c696e 216 STORE_LE_16(envAccGyroMag+16,(Magn->AXIS_Y - magOffset.magOffY));
mapellil 11:ff82699c696e 217 STORE_LE_16(envAccGyroMag+18,(Magn->AXIS_Z - magOffset.magOffZ));
mapellil 11:ff82699c696e 218 return ble.gattServer().write(envAccGyroMagCharacteristic.getValueAttribute().getHandle(), envAccGyroMag, ACCGYROMAG_DATA_LEN, 0);
mapellil 11:ff82699c696e 219 }
mapellil 11:ff82699c696e 220
mapellil 11:ff82699c696e 221 uint32_t updateEnvAccGyroMag (AxesRaw_TypeDef *Acc, AxesRaw_TypeDef *Gyro, AxesRaw_TypeDef *Magn, uint16_t TimeStamp, osxMFX_calibFactor magOffset) {
mapellil 11:ff82699c696e 222 if (isAccGyroMagNotificationEn()) return sendEnvAccGyroMag (Acc, Gyro, Magn, TimeStamp, magOffset);
mapellil 11:ff82699c696e 223 return 0;
mapellil 0:e93a11b4e044 224 }
mapellil 12:baf8b5294320 225 void enNotify (Gap::Handle_t a_handle) {
mapellil 13:d00147d01d4e 226 Gap::Handle_t handle = a_handle - BLE_HANDLE_EN_DIS_OFFSET;
mapellil 11:ff82699c696e 227 if (isTempHandle(handle)) {
mapellil 11:ff82699c696e 228 isEnabledTempNotify = true;
mapellil 11:ff82699c696e 229 memset(pastenvTemperature,0,TEMP_DATA_LEN);
mapellil 11:ff82699c696e 230 return;
mapellil 11:ff82699c696e 231 }
mapellil 11:ff82699c696e 232 if (isHumHandle(handle)) {
mapellil 11:ff82699c696e 233 isEnabledHumNotify = true;
mapellil 11:ff82699c696e 234 memset(pastenvHumidity,0,HUM_DATA_LEN);
mapellil 11:ff82699c696e 235 return;
mapellil 11:ff82699c696e 236 }
mapellil 11:ff82699c696e 237 if (isPresHandle(handle)) {
mapellil 11:ff82699c696e 238 isEnabledPresNotify = true;
mapellil 11:ff82699c696e 239 memset(pastenvPressure,0,PRES_DATA_LEN);
mapellil 11:ff82699c696e 240 return;
mapellil 11:ff82699c696e 241 }
mapellil 11:ff82699c696e 242 if (isGyroHandle(handle)) {
mapellil 11:ff82699c696e 243 isEnabledGyroNotify = true;
mapellil 11:ff82699c696e 244 return;
mapellil 11:ff82699c696e 245 }
mapellil 11:ff82699c696e 246 if (isAccHandle(handle)) {
mapellil 11:ff82699c696e 247 isEnabledAccNotify = true;
mapellil 11:ff82699c696e 248 return;
mapellil 11:ff82699c696e 249 }
mapellil 11:ff82699c696e 250 if (isMagHandle(handle)) {
mapellil 11:ff82699c696e 251 isEnabledMagNotify = true;
mapellil 11:ff82699c696e 252 return;
mapellil 11:ff82699c696e 253 }
mapellil 11:ff82699c696e 254 if (isAccGyroMagHandle(handle)) {
mapellil 11:ff82699c696e 255 isEnabledAccGyroMagNotify = true;
mapellil 11:ff82699c696e 256 return;
mapellil 11:ff82699c696e 257 }
mapellil 0:e93a11b4e044 258 }
mapellil 0:e93a11b4e044 259
mapellil 12:baf8b5294320 260 void disNotify (Gap::Handle_t a_handle) {
mapellil 13:d00147d01d4e 261 Gap::Handle_t handle = a_handle - BLE_HANDLE_EN_DIS_OFFSET;
mapellil 13:d00147d01d4e 262 if (isTempHandle(handle)) {
mapellil 11:ff82699c696e 263 isEnabledTempNotify = false;
mapellil 11:ff82699c696e 264 memset(pastenvTemperature,0,TEMP_DATA_LEN);
mapellil 11:ff82699c696e 265 return;
mapellil 11:ff82699c696e 266 }
mapellil 11:ff82699c696e 267 if (isHumHandle(handle)) {
mapellil 11:ff82699c696e 268 isEnabledHumNotify = false;
mapellil 11:ff82699c696e 269 memset(pastenvHumidity,0,HUM_DATA_LEN);
mapellil 11:ff82699c696e 270 return;
mapellil 11:ff82699c696e 271 }
mapellil 11:ff82699c696e 272 if (isPresHandle(handle)) {
mapellil 11:ff82699c696e 273 isEnabledPresNotify = false;
mapellil 11:ff82699c696e 274 memset(pastenvPressure,0,PRES_DATA_LEN);
mapellil 11:ff82699c696e 275 return;
mapellil 11:ff82699c696e 276 }
mapellil 11:ff82699c696e 277 if (isGyroHandle(handle)) {
mapellil 11:ff82699c696e 278 isEnabledGyroNotify = false;
mapellil 11:ff82699c696e 279 return;
mapellil 11:ff82699c696e 280 }
mapellil 11:ff82699c696e 281 if (isAccHandle(handle)) {
mapellil 11:ff82699c696e 282 isEnabledAccNotify = false;
mapellil 11:ff82699c696e 283 return;
mapellil 11:ff82699c696e 284 }
mapellil 13:d00147d01d4e 285 if (isMagHandle(handle)) {
mapellil 11:ff82699c696e 286 isEnabledMagNotify = false;
mapellil 11:ff82699c696e 287 return;
mapellil 11:ff82699c696e 288 }
mapellil 11:ff82699c696e 289 if (isAccGyroMagHandle(handle)) {
mapellil 11:ff82699c696e 290 isEnabledAccGyroMagNotify = false;
mapellil 11:ff82699c696e 291 return;
mapellil 11:ff82699c696e 292 }
mapellil 0:e93a11b4e044 293 }
mapellil 11:ff82699c696e 294
mapellil 0:e93a11b4e044 295 bool isTempNotificationEn (void) {
mapellil 11:ff82699c696e 296 return isEnabledTempNotify;
mapellil 0:e93a11b4e044 297 }
mapellil 11:ff82699c696e 298
mapellil 0:e93a11b4e044 299 bool isHumNotificationEn (void) {
mapellil 11:ff82699c696e 300 return isEnabledHumNotify;
mapellil 0:e93a11b4e044 301 }
mapellil 0:e93a11b4e044 302
mapellil 0:e93a11b4e044 303 bool isPresNotificationEn (void) {
mapellil 11:ff82699c696e 304 return isEnabledPresNotify;
mapellil 0:e93a11b4e044 305 }
mapellil 0:e93a11b4e044 306
mapellil 0:e93a11b4e044 307 bool isGyroNotificationEn (void) {
mapellil 11:ff82699c696e 308 return isEnabledGyroNotify;
mapellil 11:ff82699c696e 309 }
mapellil 0:e93a11b4e044 310
mapellil 0:e93a11b4e044 311 bool isAccNotificationEn (void) {
mapellil 11:ff82699c696e 312 return isEnabledAccNotify;
mapellil 11:ff82699c696e 313 }
mapellil 11:ff82699c696e 314
mapellil 0:e93a11b4e044 315 bool isMagNotificationEn (void) {
mapellil 11:ff82699c696e 316 return isEnabledMagNotify;
mapellil 11:ff82699c696e 317 }
mapellil 11:ff82699c696e 318
mapellil 0:e93a11b4e044 319 bool isAccGyroMagNotificationEn (void) {
mapellil 11:ff82699c696e 320 return isEnabledAccGyroMagNotify;
mapellil 11:ff82699c696e 321 }
mapellil 11:ff82699c696e 322
mapellil 0:e93a11b4e044 323 bool isTempHandle (Gap::Handle_t handle) {
mapellil 13:d00147d01d4e 324 if (handle == envTemperatureCharacteristic.getValueAttribute().getHandle() - BLE_HANDLE_VALUE_OFFSET) return true;
mapellil 11:ff82699c696e 325 return false;
mapellil 0:e93a11b4e044 326 }
mapellil 0:e93a11b4e044 327
mapellil 0:e93a11b4e044 328 bool isHumHandle (Gap::Handle_t handle) {
mapellil 13:d00147d01d4e 329 if (handle == envHumidityCharacteristic.getValueAttribute().getHandle() - BLE_HANDLE_VALUE_OFFSET) return true;
mapellil 11:ff82699c696e 330 return false;
mapellil 0:e93a11b4e044 331 }
mapellil 11:ff82699c696e 332
mapellil 0:e93a11b4e044 333 bool isPresHandle (Gap::Handle_t handle) {
mapellil 13:d00147d01d4e 334 if (handle == envPressureCharacteristic.getValueAttribute().getHandle() - BLE_HANDLE_VALUE_OFFSET) return true;
mapellil 11:ff82699c696e 335 return false;
mapellil 11:ff82699c696e 336 }
mapellil 0:e93a11b4e044 337
mapellil 0:e93a11b4e044 338 bool isMagHandle (Gap::Handle_t handle) {
mapellil 13:d00147d01d4e 339 if (handle == envMagnetometerCharacteristic.getValueAttribute().getHandle() - BLE_HANDLE_VALUE_OFFSET) return true;
mapellil 11:ff82699c696e 340 return false;
mapellil 0:e93a11b4e044 341 }
mapellil 0:e93a11b4e044 342 bool isAccHandle (Gap::Handle_t handle) {
mapellil 13:d00147d01d4e 343 if (handle == envAccelerometerCharacteristic.getValueAttribute().getHandle() - BLE_HANDLE_VALUE_OFFSET) return true;
mapellil 11:ff82699c696e 344 return false;
mapellil 0:e93a11b4e044 345 }
mapellil 0:e93a11b4e044 346 bool isGyroHandle (Gap::Handle_t handle) {
mapellil 13:d00147d01d4e 347 if (handle == envGyroCharacteristic.getValueAttribute().getHandle() - BLE_HANDLE_VALUE_OFFSET) return true;
mapellil 11:ff82699c696e 348 return false;
mapellil 0:e93a11b4e044 349 }
mapellil 0:e93a11b4e044 350 bool isAccGyroMagHandle (Gap::Handle_t handle) {
mapellil 13:d00147d01d4e 351 if (handle == envAccGyroMagCharacteristic.getValueAttribute().getHandle() - BLE_HANDLE_VALUE_OFFSET) return true;
mapellil 11:ff82699c696e 352 return false;
mapellil 0:e93a11b4e044 353 }
mapellil 11:ff82699c696e 354
mapellil 11:ff82699c696e 355 void updateConnectionStatus(ConnectionStatus_t status) {
mapellil 11:ff82699c696e 356 isEnabledTempNotify = false;
mapellil 11:ff82699c696e 357 isEnabledHumNotify = false;
mapellil 11:ff82699c696e 358 isEnabledPresNotify = false;
mapellil 11:ff82699c696e 359 isEnabledGyroNotify = false;
mapellil 11:ff82699c696e 360 isEnabledAccNotify = false;
mapellil 11:ff82699c696e 361 isEnabledMagNotify = false;
mapellil 11:ff82699c696e 362 isEnabledAccGyroMagNotify = false;
mapellil 11:ff82699c696e 363
mapellil 11:ff82699c696e 364 isTempCalibrated = false;
mapellil 11:ff82699c696e 365 isHumCalibrated = false;
mapellil 11:ff82699c696e 366 isPresCalibrated = false;
mapellil 11:ff82699c696e 367 isMagCalibrated = false;
mapellil 11:ff82699c696e 368 isAccCalibrated = false;
mapellil 11:ff82699c696e 369 isAGyroCalibrated = false;
mapellil 11:ff82699c696e 370
mapellil 11:ff82699c696e 371 memset (pastenvTemperature, 0, TEMP_DATA_LEN);
mapellil 11:ff82699c696e 372 memset (pastenvHumidity, 0, HUM_DATA_LEN);
mapellil 11:ff82699c696e 373 memset (pastenvPressure, 0, PRES_DATA_LEN);
mapellil 11:ff82699c696e 374 isBTLEConnected = status;
mapellil 0:e93a11b4e044 375 }
mapellil 11:ff82699c696e 376
mapellil 11:ff82699c696e 377
mapellil 0:e93a11b4e044 378 private:
mapellil 9:2693f9ef8ff7 379 BLE &ble;
mapellil 0:e93a11b4e044 380 uint8_t envTemperature [TEMP_DATA_LEN]; /* in C */
mapellil 11:ff82699c696e 381 uint8_t pastenvTemperature [TEMP_DATA_LEN];
mapellil 0:e93a11b4e044 382 uint8_t envHumidity [HUM_DATA_LEN]; /* in % */
mapellil 11:ff82699c696e 383 uint8_t pastenvHumidity [HUM_DATA_LEN];
mapellil 0:e93a11b4e044 384 uint8_t envPressure [PRES_DATA_LEN]; /* in mBar */
mapellil 11:ff82699c696e 385 uint8_t pastenvPressure [PRES_DATA_LEN];
mapellil 11:ff82699c696e 386 uint8_t envMagn [MAG_DATA_LEN];
mapellil 0:e93a11b4e044 387 uint8_t envGyro [GYRO_DATA_LEN];
mapellil 0:e93a11b4e044 388 uint8_t envAcce [ACC_DATA_LEN];
mapellil 0:e93a11b4e044 389 uint8_t envAccGyroMag [ACCGYROMAG_DATA_LEN];
mapellil 0:e93a11b4e044 390
mapellil 11:ff82699c696e 391 GattCharacteristic envTemperatureCharacteristic;
mapellil 11:ff82699c696e 392 GattCharacteristic envHumidityCharacteristic;
mapellil 0:e93a11b4e044 393 GattCharacteristic envPressureCharacteristic;
mapellil 0:e93a11b4e044 394
mapellil 0:e93a11b4e044 395 GattCharacteristic envMagnetometerCharacteristic;
mapellil 0:e93a11b4e044 396 GattCharacteristic envAccelerometerCharacteristic;
mapellil 0:e93a11b4e044 397 GattCharacteristic envGyroCharacteristic;
mapellil 0:e93a11b4e044 398 GattCharacteristic envAccGyroMagCharacteristic;
mapellil 0:e93a11b4e044 399
mapellil 0:e93a11b4e044 400 ConnectionStatus_t isBTLEConnected;
mapellil 0:e93a11b4e044 401
mapellil 0:e93a11b4e044 402 bool isEnabledTempNotify;
mapellil 0:e93a11b4e044 403 bool isEnabledHumNotify;
mapellil 0:e93a11b4e044 404 bool isEnabledPresNotify;
mapellil 11:ff82699c696e 405 bool isEnabledGyroNotify;
mapellil 0:e93a11b4e044 406 bool isEnabledAccNotify;
mapellil 0:e93a11b4e044 407 bool isEnabledMagNotify;
mapellil 11:ff82699c696e 408 bool isEnabledAccGyroMagNotify;
mapellil 11:ff82699c696e 409
mapellil 0:e93a11b4e044 410 bool isTempCalibrated;
mapellil 0:e93a11b4e044 411 bool isHumCalibrated;
mapellil 11:ff82699c696e 412 bool isPresCalibrated;
mapellil 0:e93a11b4e044 413 bool isMagCalibrated;
mapellil 11:ff82699c696e 414 bool isAccCalibrated;
mapellil 11:ff82699c696e 415 bool isAGyroCalibrated;
mapellil 11:ff82699c696e 416
mapellil 0:e93a11b4e044 417 };
mapellil 0:e93a11b4e044 418
mapellil 0:e93a11b4e044 419 #endif /* #ifndef __CUSTOM_BLE_SENSORS_SERVICE_H__*/