Motion and Environmental sensor reader application connected via BLE to ST BlueMS iOS/Android application.

Dependencies:   HTS221 LIS3MDL LPS22HB LSM303AGR LSM6DSL

Fork of MOTENV_Mbed by ST Expansion SW Team

This application supports three different sets of ST hardware boards:

  • STEVAL-STLKT01V1 (aka SensorTile)
  • X-NUCLEO-IDB05A1 and X-NUCLEO-IKS01A2 expansion boards
  • B-L475E-IOT01A IoT Discovery board

    and runs over four different target configurations:

  • Nucleo F401RE + X-NUCLEO-IDB05A1 + X-NUCLEO-IKS01A2 (set target NUCLEO_F401RE)
  • DISCO_L475VG_IOT01A (set target DISCO_L475VG_IOT01A)
  • Nucleo L476RG + CRADLE + SENSORTILE (set compile target NUCLEO_L476RG)
  • Nucleo L476RG + CRADLE_EXPANSION_BOARD + SENSORTILE (set compile target NUCLEO_L476RG, remove macro MINI_CRADLE from mbed_app.json)

The first 2 configurations do not require any HW modifications (just use the above indicated targets).

Third configuration (CRADLE ) only requires to remove the two ST-LINK jumpers and JP6 from the Nucleo L476RG board in order to allow flashing the SensorTile through the Nucleo Jtag controller. Once flashed, if the battery is properly plugged and charged, the SensorTile could be mounted in the plastic enclosure being able to run as a small stand alone wearable device. Please note that this configuration do not provide a serial console for printf.

To enable last configuration (CRADLE_EXPANSION_BOARD), follow the steps below:

  • On Nucleo L476RG
    • open the two "ST-LINK" jumpers
    • open the MCU power supply jumper JP6
    • close the solder bridges SB63 and SB62 (to enable the serial console)
  • On SensorTile Arduino Cradle close the solder bridges SB21 and SB10 (to enable the serial console) and move the jumper J2 to the 5V position
  • Plug the Sensor Tile on the Arduino Cradle
  • Plug the Cradle on the Nucleo Arduino connector and connect the debug flat cable between Cradle and Nucleo Jtag connector (the cradle pin1 -identified by a dot- must be connected to the Nucleo pin1 (dot) of SWD CN4 jtag connector)
  • Plug the Nucleo USB cable on PC (a new COM port should appear); no need to plug the micro USB cable on the cradle.
  • Open a PC terminal to see the messages
  • Compile from mbed CLI or on-line compiler removing macro MINI_CRADLE from mbed_app.json file and selecting NUCLEO_ L476RG target
  • Flash the board with the binary

For all configurations on an Android or iOS device download and open the ST BlueMS application and connect to "MotEnvMbedOS" BLE device to see the sensor data.

For all configurations is also possible to add a 9 axis MotionFX sensor fusion library, which is part of the X-CUBE-MEMS package at this link.
The library comes in three flavours, choose your preferred according to the toolchain used (IAR, Keil or GC, Keil version should be used for the online compiler) and copy it in the Middlewares\ST\STM32_MotionFX_Library\Lib directory changing the file extension according to the toolchain used (.a for GCC, .ar for Keil).
In the file mbed_app.json add the macro definition "USE_SENSOR_FUSION_LIB" to the chosen target.
If compiling from CLI and using GCC_ARM toolchain option, in the file \mbed-os\tools\toolchains\gcc.py change the compiling option from

        if target.core == "Cortex-M4F":
            self.cpu.append("-mfpu=fpv4-sp-d16")
            self.cpu.append("-mfloat-abi=softfp")

to

        if target.core == "Cortex-M4F":
            self.cpu.append("-mfpu=fpv4-sp-d16")
            self.cpu.append("-mfloat-abi=hard")

and compile.

Committer:
mapellil
Date:
Fri Jun 17 14:04:14 2016 +0000
Revision:
11:ff82699c696e
Parent:
9:2693f9ef8ff7
Child:
12:baf8b5294320
Updated BLE (with mac addr self generated) and Mbed

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 11:ff82699c696e 225
mapellil 0:e93a11b4e044 226 void enNotify (Gap::Handle_t handle) {
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 0:e93a11b4e044 260 void disNotify (Gap::Handle_t handle) {
mapellil 11:ff82699c696e 261 if (isTempHandle(handle)) {
mapellil 11:ff82699c696e 262 isEnabledTempNotify = false;
mapellil 11:ff82699c696e 263 memset(pastenvTemperature,0,TEMP_DATA_LEN);
mapellil 11:ff82699c696e 264 return;
mapellil 11:ff82699c696e 265 }
mapellil 11:ff82699c696e 266 if (isHumHandle(handle)) {
mapellil 11:ff82699c696e 267 isEnabledHumNotify = false;
mapellil 11:ff82699c696e 268 memset(pastenvHumidity,0,HUM_DATA_LEN);
mapellil 11:ff82699c696e 269 return;
mapellil 11:ff82699c696e 270 }
mapellil 11:ff82699c696e 271 if (isPresHandle(handle)) {
mapellil 11:ff82699c696e 272 isEnabledPresNotify = false;
mapellil 11:ff82699c696e 273 memset(pastenvPressure,0,PRES_DATA_LEN);
mapellil 11:ff82699c696e 274 return;
mapellil 11:ff82699c696e 275 }
mapellil 11:ff82699c696e 276 if (isGyroHandle(handle)) {
mapellil 11:ff82699c696e 277 isEnabledGyroNotify = false;
mapellil 11:ff82699c696e 278 return;
mapellil 11:ff82699c696e 279 }
mapellil 11:ff82699c696e 280 if (isAccHandle(handle)) {
mapellil 11:ff82699c696e 281 isEnabledAccNotify = false;
mapellil 11:ff82699c696e 282 return;
mapellil 11:ff82699c696e 283 }
mapellil 11:ff82699c696e 284 if (isMagHandle(handle)) {
mapellil 11:ff82699c696e 285 isEnabledMagNotify = false;
mapellil 11:ff82699c696e 286 return;
mapellil 11:ff82699c696e 287 }
mapellil 11:ff82699c696e 288 if (isAccGyroMagHandle(handle)) {
mapellil 11:ff82699c696e 289 isEnabledAccGyroMagNotify = false;
mapellil 11:ff82699c696e 290 return;
mapellil 11:ff82699c696e 291 }
mapellil 0:e93a11b4e044 292 }
mapellil 11:ff82699c696e 293
mapellil 0:e93a11b4e044 294 bool isTempNotificationEn (void) {
mapellil 11:ff82699c696e 295 return isEnabledTempNotify;
mapellil 0:e93a11b4e044 296 }
mapellil 11:ff82699c696e 297
mapellil 0:e93a11b4e044 298 bool isHumNotificationEn (void) {
mapellil 11:ff82699c696e 299 return isEnabledHumNotify;
mapellil 0:e93a11b4e044 300 }
mapellil 0:e93a11b4e044 301
mapellil 0:e93a11b4e044 302 bool isPresNotificationEn (void) {
mapellil 11:ff82699c696e 303 return isEnabledPresNotify;
mapellil 0:e93a11b4e044 304 }
mapellil 0:e93a11b4e044 305
mapellil 0:e93a11b4e044 306 bool isGyroNotificationEn (void) {
mapellil 11:ff82699c696e 307 return isEnabledGyroNotify;
mapellil 11:ff82699c696e 308 }
mapellil 0:e93a11b4e044 309
mapellil 0:e93a11b4e044 310 bool isAccNotificationEn (void) {
mapellil 11:ff82699c696e 311 return isEnabledAccNotify;
mapellil 11:ff82699c696e 312 }
mapellil 11:ff82699c696e 313
mapellil 0:e93a11b4e044 314 bool isMagNotificationEn (void) {
mapellil 11:ff82699c696e 315 return isEnabledMagNotify;
mapellil 11:ff82699c696e 316 }
mapellil 11:ff82699c696e 317
mapellil 0:e93a11b4e044 318 bool isAccGyroMagNotificationEn (void) {
mapellil 11:ff82699c696e 319 return isEnabledAccGyroMagNotify;
mapellil 11:ff82699c696e 320 }
mapellil 11:ff82699c696e 321
mapellil 0:e93a11b4e044 322 bool isTempHandle (Gap::Handle_t handle) {
mapellil 11:ff82699c696e 323 if (handle == envTemperatureCharacteristic.getValueAttribute().getHandle()+1) return true;
mapellil 11:ff82699c696e 324 return false;
mapellil 0:e93a11b4e044 325 }
mapellil 0:e93a11b4e044 326
mapellil 0:e93a11b4e044 327 bool isHumHandle (Gap::Handle_t handle) {
mapellil 11:ff82699c696e 328 if (handle == envHumidityCharacteristic.getValueAttribute().getHandle()+1) return true;
mapellil 11:ff82699c696e 329 return false;
mapellil 0:e93a11b4e044 330 }
mapellil 11:ff82699c696e 331
mapellil 0:e93a11b4e044 332 bool isPresHandle (Gap::Handle_t handle) {
mapellil 11:ff82699c696e 333 if (handle == envPressureCharacteristic.getValueAttribute().getHandle()+1) return true;
mapellil 11:ff82699c696e 334 return false;
mapellil 11:ff82699c696e 335 }
mapellil 0:e93a11b4e044 336
mapellil 0:e93a11b4e044 337 bool isMagHandle (Gap::Handle_t handle) {
mapellil 11:ff82699c696e 338 if (handle == envMagnetometerCharacteristic.getValueAttribute().getHandle()+1) return true;
mapellil 11:ff82699c696e 339 return false;
mapellil 0:e93a11b4e044 340 }
mapellil 0:e93a11b4e044 341 bool isAccHandle (Gap::Handle_t handle) {
mapellil 11:ff82699c696e 342 if (handle == envAccelerometerCharacteristic.getValueAttribute().getHandle()+1) return true;
mapellil 11:ff82699c696e 343 return false;
mapellil 0:e93a11b4e044 344 }
mapellil 0:e93a11b4e044 345 bool isGyroHandle (Gap::Handle_t handle) {
mapellil 11:ff82699c696e 346 if (handle == envGyroCharacteristic.getValueAttribute().getHandle()+1) return true;
mapellil 11:ff82699c696e 347 return false;
mapellil 0:e93a11b4e044 348 }
mapellil 0:e93a11b4e044 349 bool isAccGyroMagHandle (Gap::Handle_t handle) {
mapellil 11:ff82699c696e 350 if (handle == envAccGyroMagCharacteristic.getValueAttribute().getHandle()+1) return true;
mapellil 11:ff82699c696e 351 return false;
mapellil 0:e93a11b4e044 352 }
mapellil 11:ff82699c696e 353
mapellil 11:ff82699c696e 354 void updateConnectionStatus(ConnectionStatus_t status) {
mapellil 11:ff82699c696e 355 isEnabledTempNotify = false;
mapellil 11:ff82699c696e 356 isEnabledHumNotify = false;
mapellil 11:ff82699c696e 357 isEnabledPresNotify = false;
mapellil 11:ff82699c696e 358 isEnabledGyroNotify = false;
mapellil 11:ff82699c696e 359 isEnabledAccNotify = false;
mapellil 11:ff82699c696e 360 isEnabledMagNotify = false;
mapellil 11:ff82699c696e 361 isEnabledAccGyroMagNotify = false;
mapellil 11:ff82699c696e 362
mapellil 11:ff82699c696e 363 isTempCalibrated = false;
mapellil 11:ff82699c696e 364 isHumCalibrated = false;
mapellil 11:ff82699c696e 365 isPresCalibrated = false;
mapellil 11:ff82699c696e 366 isMagCalibrated = false;
mapellil 11:ff82699c696e 367 isAccCalibrated = false;
mapellil 11:ff82699c696e 368 isAGyroCalibrated = false;
mapellil 11:ff82699c696e 369
mapellil 11:ff82699c696e 370 memset (pastenvTemperature, 0, TEMP_DATA_LEN);
mapellil 11:ff82699c696e 371 memset (pastenvHumidity, 0, HUM_DATA_LEN);
mapellil 11:ff82699c696e 372 memset (pastenvPressure, 0, PRES_DATA_LEN);
mapellil 11:ff82699c696e 373 isBTLEConnected = status;
mapellil 0:e93a11b4e044 374 }
mapellil 11:ff82699c696e 375
mapellil 11:ff82699c696e 376
mapellil 0:e93a11b4e044 377 private:
mapellil 9:2693f9ef8ff7 378 BLE &ble;
mapellil 0:e93a11b4e044 379 uint8_t envTemperature [TEMP_DATA_LEN]; /* in C */
mapellil 11:ff82699c696e 380 uint8_t pastenvTemperature [TEMP_DATA_LEN];
mapellil 0:e93a11b4e044 381 uint8_t envHumidity [HUM_DATA_LEN]; /* in % */
mapellil 11:ff82699c696e 382 uint8_t pastenvHumidity [HUM_DATA_LEN];
mapellil 0:e93a11b4e044 383 uint8_t envPressure [PRES_DATA_LEN]; /* in mBar */
mapellil 11:ff82699c696e 384 uint8_t pastenvPressure [PRES_DATA_LEN];
mapellil 11:ff82699c696e 385 uint8_t envMagn [MAG_DATA_LEN];
mapellil 0:e93a11b4e044 386 uint8_t envGyro [GYRO_DATA_LEN];
mapellil 0:e93a11b4e044 387 uint8_t envAcce [ACC_DATA_LEN];
mapellil 0:e93a11b4e044 388 uint8_t envAccGyroMag [ACCGYROMAG_DATA_LEN];
mapellil 0:e93a11b4e044 389
mapellil 11:ff82699c696e 390 GattCharacteristic envTemperatureCharacteristic;
mapellil 11:ff82699c696e 391 GattCharacteristic envHumidityCharacteristic;
mapellil 0:e93a11b4e044 392 GattCharacteristic envPressureCharacteristic;
mapellil 0:e93a11b4e044 393
mapellil 0:e93a11b4e044 394 GattCharacteristic envMagnetometerCharacteristic;
mapellil 0:e93a11b4e044 395 GattCharacteristic envAccelerometerCharacteristic;
mapellil 0:e93a11b4e044 396 GattCharacteristic envGyroCharacteristic;
mapellil 0:e93a11b4e044 397 GattCharacteristic envAccGyroMagCharacteristic;
mapellil 0:e93a11b4e044 398
mapellil 0:e93a11b4e044 399 ConnectionStatus_t isBTLEConnected;
mapellil 0:e93a11b4e044 400
mapellil 0:e93a11b4e044 401 bool isEnabledTempNotify;
mapellil 0:e93a11b4e044 402 bool isEnabledHumNotify;
mapellil 0:e93a11b4e044 403 bool isEnabledPresNotify;
mapellil 11:ff82699c696e 404 bool isEnabledGyroNotify;
mapellil 0:e93a11b4e044 405 bool isEnabledAccNotify;
mapellil 0:e93a11b4e044 406 bool isEnabledMagNotify;
mapellil 11:ff82699c696e 407 bool isEnabledAccGyroMagNotify;
mapellil 11:ff82699c696e 408
mapellil 0:e93a11b4e044 409 bool isTempCalibrated;
mapellil 0:e93a11b4e044 410 bool isHumCalibrated;
mapellil 11:ff82699c696e 411 bool isPresCalibrated;
mapellil 0:e93a11b4e044 412 bool isMagCalibrated;
mapellil 11:ff82699c696e 413 bool isAccCalibrated;
mapellil 11:ff82699c696e 414 bool isAGyroCalibrated;
mapellil 11:ff82699c696e 415
mapellil 0:e93a11b4e044 416 };
mapellil 0:e93a11b4e044 417
mapellil 0:e93a11b4e044 418 #endif /* #ifndef __CUSTOM_BLE_SENSORS_SERVICE_H__*/