![](/media/cache/group/ST_logo_2020_blue_V_cmyk.jpg.50x50_q85.jpg)
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
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.
CustomSensorsService.h@12:baf8b5294320, 2016-06-20 (annotated)
- Committer:
- mapellil
- Date:
- Mon Jun 20 15:46:53 2016 +0000
- Revision:
- 12:baf8b5294320
- Parent:
- 11:ff82699c696e
- Child:
- 13:d00147d01d4e
Fixed BLE handles offset according to updated BLE API
Who changed what in which revision?
User | Revision | Line number | New 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>© 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 | 12:baf8b5294320 | 226 | void enNotify (Gap::Handle_t a_handle) { |
mapellil | 12:baf8b5294320 | 227 | Gap::Handle_t handle = a_handle-2; |
mapellil | 11:ff82699c696e | 228 | if (isTempHandle(handle)) { |
mapellil | 11:ff82699c696e | 229 | isEnabledTempNotify = true; |
mapellil | 11:ff82699c696e | 230 | memset(pastenvTemperature,0,TEMP_DATA_LEN); |
mapellil | 11:ff82699c696e | 231 | return; |
mapellil | 11:ff82699c696e | 232 | } |
mapellil | 11:ff82699c696e | 233 | if (isHumHandle(handle)) { |
mapellil | 11:ff82699c696e | 234 | isEnabledHumNotify = true; |
mapellil | 11:ff82699c696e | 235 | memset(pastenvHumidity,0,HUM_DATA_LEN); |
mapellil | 11:ff82699c696e | 236 | return; |
mapellil | 11:ff82699c696e | 237 | } |
mapellil | 11:ff82699c696e | 238 | if (isPresHandle(handle)) { |
mapellil | 11:ff82699c696e | 239 | isEnabledPresNotify = true; |
mapellil | 11:ff82699c696e | 240 | memset(pastenvPressure,0,PRES_DATA_LEN); |
mapellil | 11:ff82699c696e | 241 | return; |
mapellil | 11:ff82699c696e | 242 | } |
mapellil | 11:ff82699c696e | 243 | if (isGyroHandle(handle)) { |
mapellil | 11:ff82699c696e | 244 | isEnabledGyroNotify = true; |
mapellil | 11:ff82699c696e | 245 | return; |
mapellil | 11:ff82699c696e | 246 | } |
mapellil | 11:ff82699c696e | 247 | if (isAccHandle(handle)) { |
mapellil | 11:ff82699c696e | 248 | isEnabledAccNotify = true; |
mapellil | 11:ff82699c696e | 249 | return; |
mapellil | 11:ff82699c696e | 250 | } |
mapellil | 11:ff82699c696e | 251 | if (isMagHandle(handle)) { |
mapellil | 11:ff82699c696e | 252 | isEnabledMagNotify = true; |
mapellil | 11:ff82699c696e | 253 | return; |
mapellil | 11:ff82699c696e | 254 | } |
mapellil | 11:ff82699c696e | 255 | if (isAccGyroMagHandle(handle)) { |
mapellil | 11:ff82699c696e | 256 | isEnabledAccGyroMagNotify = true; |
mapellil | 11:ff82699c696e | 257 | return; |
mapellil | 11:ff82699c696e | 258 | } |
mapellil | 0:e93a11b4e044 | 259 | } |
mapellil | 0:e93a11b4e044 | 260 | |
mapellil | 12:baf8b5294320 | 261 | void disNotify (Gap::Handle_t a_handle) { |
mapellil | 12:baf8b5294320 | 262 | Gap::Handle_t handle = a_handle-2; |
mapellil | 11:ff82699c696e | 263 | if (isTempHandle(handle)) { |
mapellil | 11:ff82699c696e | 264 | isEnabledTempNotify = false; |
mapellil | 11:ff82699c696e | 265 | memset(pastenvTemperature,0,TEMP_DATA_LEN); |
mapellil | 11:ff82699c696e | 266 | return; |
mapellil | 11:ff82699c696e | 267 | } |
mapellil | 11:ff82699c696e | 268 | if (isHumHandle(handle)) { |
mapellil | 11:ff82699c696e | 269 | isEnabledHumNotify = false; |
mapellil | 11:ff82699c696e | 270 | memset(pastenvHumidity,0,HUM_DATA_LEN); |
mapellil | 11:ff82699c696e | 271 | return; |
mapellil | 11:ff82699c696e | 272 | } |
mapellil | 11:ff82699c696e | 273 | if (isPresHandle(handle)) { |
mapellil | 11:ff82699c696e | 274 | isEnabledPresNotify = false; |
mapellil | 11:ff82699c696e | 275 | memset(pastenvPressure,0,PRES_DATA_LEN); |
mapellil | 11:ff82699c696e | 276 | return; |
mapellil | 11:ff82699c696e | 277 | } |
mapellil | 11:ff82699c696e | 278 | if (isGyroHandle(handle)) { |
mapellil | 11:ff82699c696e | 279 | isEnabledGyroNotify = false; |
mapellil | 11:ff82699c696e | 280 | return; |
mapellil | 11:ff82699c696e | 281 | } |
mapellil | 11:ff82699c696e | 282 | if (isAccHandle(handle)) { |
mapellil | 11:ff82699c696e | 283 | isEnabledAccNotify = false; |
mapellil | 11:ff82699c696e | 284 | return; |
mapellil | 11:ff82699c696e | 285 | } |
mapellil | 11:ff82699c696e | 286 | if (isMagHandle(handle)) { |
mapellil | 11:ff82699c696e | 287 | isEnabledMagNotify = false; |
mapellil | 11:ff82699c696e | 288 | return; |
mapellil | 11:ff82699c696e | 289 | } |
mapellil | 11:ff82699c696e | 290 | if (isAccGyroMagHandle(handle)) { |
mapellil | 11:ff82699c696e | 291 | isEnabledAccGyroMagNotify = false; |
mapellil | 11:ff82699c696e | 292 | return; |
mapellil | 11:ff82699c696e | 293 | } |
mapellil | 0:e93a11b4e044 | 294 | } |
mapellil | 11:ff82699c696e | 295 | |
mapellil | 0:e93a11b4e044 | 296 | bool isTempNotificationEn (void) { |
mapellil | 11:ff82699c696e | 297 | return isEnabledTempNotify; |
mapellil | 0:e93a11b4e044 | 298 | } |
mapellil | 11:ff82699c696e | 299 | |
mapellil | 0:e93a11b4e044 | 300 | bool isHumNotificationEn (void) { |
mapellil | 11:ff82699c696e | 301 | return isEnabledHumNotify; |
mapellil | 0:e93a11b4e044 | 302 | } |
mapellil | 0:e93a11b4e044 | 303 | |
mapellil | 0:e93a11b4e044 | 304 | bool isPresNotificationEn (void) { |
mapellil | 11:ff82699c696e | 305 | return isEnabledPresNotify; |
mapellil | 0:e93a11b4e044 | 306 | } |
mapellil | 0:e93a11b4e044 | 307 | |
mapellil | 0:e93a11b4e044 | 308 | bool isGyroNotificationEn (void) { |
mapellil | 11:ff82699c696e | 309 | return isEnabledGyroNotify; |
mapellil | 11:ff82699c696e | 310 | } |
mapellil | 0:e93a11b4e044 | 311 | |
mapellil | 0:e93a11b4e044 | 312 | bool isAccNotificationEn (void) { |
mapellil | 11:ff82699c696e | 313 | return isEnabledAccNotify; |
mapellil | 11:ff82699c696e | 314 | } |
mapellil | 11:ff82699c696e | 315 | |
mapellil | 0:e93a11b4e044 | 316 | bool isMagNotificationEn (void) { |
mapellil | 11:ff82699c696e | 317 | return isEnabledMagNotify; |
mapellil | 11:ff82699c696e | 318 | } |
mapellil | 11:ff82699c696e | 319 | |
mapellil | 0:e93a11b4e044 | 320 | bool isAccGyroMagNotificationEn (void) { |
mapellil | 11:ff82699c696e | 321 | return isEnabledAccGyroMagNotify; |
mapellil | 11:ff82699c696e | 322 | } |
mapellil | 11:ff82699c696e | 323 | |
mapellil | 0:e93a11b4e044 | 324 | bool isTempHandle (Gap::Handle_t handle) { |
mapellil | 12:baf8b5294320 | 325 | if (handle == envTemperatureCharacteristic.getValueAttribute().getHandle()-1) return true; |
mapellil | 11:ff82699c696e | 326 | return false; |
mapellil | 0:e93a11b4e044 | 327 | } |
mapellil | 0:e93a11b4e044 | 328 | |
mapellil | 0:e93a11b4e044 | 329 | bool isHumHandle (Gap::Handle_t handle) { |
mapellil | 12:baf8b5294320 | 330 | if (handle == envHumidityCharacteristic.getValueAttribute().getHandle()-1) return true; |
mapellil | 11:ff82699c696e | 331 | return false; |
mapellil | 0:e93a11b4e044 | 332 | } |
mapellil | 11:ff82699c696e | 333 | |
mapellil | 0:e93a11b4e044 | 334 | bool isPresHandle (Gap::Handle_t handle) { |
mapellil | 12:baf8b5294320 | 335 | if (handle == envPressureCharacteristic.getValueAttribute().getHandle()-1) return true; |
mapellil | 11:ff82699c696e | 336 | return false; |
mapellil | 11:ff82699c696e | 337 | } |
mapellil | 0:e93a11b4e044 | 338 | |
mapellil | 0:e93a11b4e044 | 339 | bool isMagHandle (Gap::Handle_t handle) { |
mapellil | 12:baf8b5294320 | 340 | if (handle == envMagnetometerCharacteristic.getValueAttribute().getHandle()-1) return true; |
mapellil | 11:ff82699c696e | 341 | return false; |
mapellil | 0:e93a11b4e044 | 342 | } |
mapellil | 0:e93a11b4e044 | 343 | bool isAccHandle (Gap::Handle_t handle) { |
mapellil | 12:baf8b5294320 | 344 | if (handle == envAccelerometerCharacteristic.getValueAttribute().getHandle()-1) return true; |
mapellil | 11:ff82699c696e | 345 | return false; |
mapellil | 0:e93a11b4e044 | 346 | } |
mapellil | 0:e93a11b4e044 | 347 | bool isGyroHandle (Gap::Handle_t handle) { |
mapellil | 12:baf8b5294320 | 348 | if (handle == envGyroCharacteristic.getValueAttribute().getHandle()-1) return true; |
mapellil | 11:ff82699c696e | 349 | return false; |
mapellil | 0:e93a11b4e044 | 350 | } |
mapellil | 0:e93a11b4e044 | 351 | bool isAccGyroMagHandle (Gap::Handle_t handle) { |
mapellil | 12:baf8b5294320 | 352 | if (handle == envAccGyroMagCharacteristic.getValueAttribute().getHandle()-1) return true; |
mapellil | 11:ff82699c696e | 353 | return false; |
mapellil | 0:e93a11b4e044 | 354 | } |
mapellil | 11:ff82699c696e | 355 | |
mapellil | 11:ff82699c696e | 356 | void updateConnectionStatus(ConnectionStatus_t status) { |
mapellil | 11:ff82699c696e | 357 | isEnabledTempNotify = false; |
mapellil | 11:ff82699c696e | 358 | isEnabledHumNotify = false; |
mapellil | 11:ff82699c696e | 359 | isEnabledPresNotify = false; |
mapellil | 11:ff82699c696e | 360 | isEnabledGyroNotify = false; |
mapellil | 11:ff82699c696e | 361 | isEnabledAccNotify = false; |
mapellil | 11:ff82699c696e | 362 | isEnabledMagNotify = false; |
mapellil | 11:ff82699c696e | 363 | isEnabledAccGyroMagNotify = false; |
mapellil | 11:ff82699c696e | 364 | |
mapellil | 11:ff82699c696e | 365 | isTempCalibrated = false; |
mapellil | 11:ff82699c696e | 366 | isHumCalibrated = false; |
mapellil | 11:ff82699c696e | 367 | isPresCalibrated = false; |
mapellil | 11:ff82699c696e | 368 | isMagCalibrated = false; |
mapellil | 11:ff82699c696e | 369 | isAccCalibrated = false; |
mapellil | 11:ff82699c696e | 370 | isAGyroCalibrated = false; |
mapellil | 11:ff82699c696e | 371 | |
mapellil | 11:ff82699c696e | 372 | memset (pastenvTemperature, 0, TEMP_DATA_LEN); |
mapellil | 11:ff82699c696e | 373 | memset (pastenvHumidity, 0, HUM_DATA_LEN); |
mapellil | 11:ff82699c696e | 374 | memset (pastenvPressure, 0, PRES_DATA_LEN); |
mapellil | 11:ff82699c696e | 375 | isBTLEConnected = status; |
mapellil | 0:e93a11b4e044 | 376 | } |
mapellil | 11:ff82699c696e | 377 | |
mapellil | 11:ff82699c696e | 378 | |
mapellil | 0:e93a11b4e044 | 379 | private: |
mapellil | 9:2693f9ef8ff7 | 380 | BLE &ble; |
mapellil | 0:e93a11b4e044 | 381 | uint8_t envTemperature [TEMP_DATA_LEN]; /* in C */ |
mapellil | 11:ff82699c696e | 382 | uint8_t pastenvTemperature [TEMP_DATA_LEN]; |
mapellil | 0:e93a11b4e044 | 383 | uint8_t envHumidity [HUM_DATA_LEN]; /* in % */ |
mapellil | 11:ff82699c696e | 384 | uint8_t pastenvHumidity [HUM_DATA_LEN]; |
mapellil | 0:e93a11b4e044 | 385 | uint8_t envPressure [PRES_DATA_LEN]; /* in mBar */ |
mapellil | 11:ff82699c696e | 386 | uint8_t pastenvPressure [PRES_DATA_LEN]; |
mapellil | 11:ff82699c696e | 387 | uint8_t envMagn [MAG_DATA_LEN]; |
mapellil | 0:e93a11b4e044 | 388 | uint8_t envGyro [GYRO_DATA_LEN]; |
mapellil | 0:e93a11b4e044 | 389 | uint8_t envAcce [ACC_DATA_LEN]; |
mapellil | 0:e93a11b4e044 | 390 | uint8_t envAccGyroMag [ACCGYROMAG_DATA_LEN]; |
mapellil | 0:e93a11b4e044 | 391 | |
mapellil | 11:ff82699c696e | 392 | GattCharacteristic envTemperatureCharacteristic; |
mapellil | 11:ff82699c696e | 393 | GattCharacteristic envHumidityCharacteristic; |
mapellil | 0:e93a11b4e044 | 394 | GattCharacteristic envPressureCharacteristic; |
mapellil | 0:e93a11b4e044 | 395 | |
mapellil | 0:e93a11b4e044 | 396 | GattCharacteristic envMagnetometerCharacteristic; |
mapellil | 0:e93a11b4e044 | 397 | GattCharacteristic envAccelerometerCharacteristic; |
mapellil | 0:e93a11b4e044 | 398 | GattCharacteristic envGyroCharacteristic; |
mapellil | 0:e93a11b4e044 | 399 | GattCharacteristic envAccGyroMagCharacteristic; |
mapellil | 0:e93a11b4e044 | 400 | |
mapellil | 0:e93a11b4e044 | 401 | ConnectionStatus_t isBTLEConnected; |
mapellil | 0:e93a11b4e044 | 402 | |
mapellil | 0:e93a11b4e044 | 403 | bool isEnabledTempNotify; |
mapellil | 0:e93a11b4e044 | 404 | bool isEnabledHumNotify; |
mapellil | 0:e93a11b4e044 | 405 | bool isEnabledPresNotify; |
mapellil | 11:ff82699c696e | 406 | bool isEnabledGyroNotify; |
mapellil | 0:e93a11b4e044 | 407 | bool isEnabledAccNotify; |
mapellil | 0:e93a11b4e044 | 408 | bool isEnabledMagNotify; |
mapellil | 11:ff82699c696e | 409 | bool isEnabledAccGyroMagNotify; |
mapellil | 11:ff82699c696e | 410 | |
mapellil | 0:e93a11b4e044 | 411 | bool isTempCalibrated; |
mapellil | 0:e93a11b4e044 | 412 | bool isHumCalibrated; |
mapellil | 11:ff82699c696e | 413 | bool isPresCalibrated; |
mapellil | 0:e93a11b4e044 | 414 | bool isMagCalibrated; |
mapellil | 11:ff82699c696e | 415 | bool isAccCalibrated; |
mapellil | 11:ff82699c696e | 416 | bool isAGyroCalibrated; |
mapellil | 11:ff82699c696e | 417 | |
mapellil | 0:e93a11b4e044 | 418 | }; |
mapellil | 0:e93a11b4e044 | 419 | |
mapellil | 0:e93a11b4e044 | 420 | #endif /* #ifndef __CUSTOM_BLE_SENSORS_SERVICE_H__*/ |