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.
Revision:
6:c1b8fb74072e
Parent:
4:007539036889
Child:
7:34014895dda8
diff -r c3ba16d6612d -r c1b8fb74072e main.cpp
--- a/main.cpp	Mon Dec 14 15:53:22 2015 +0000
+++ b/main.cpp	Thu Dec 17 13:53:13 2015 +0000
@@ -1,7 +1,40 @@
+/**
+ ******************************************************************************
+ * @file    main.cpp
+ * @author  AST / EST
+ * @version V0.0.1
+ * @date    16-Dec-2015
+ * @brief   main of Bluemicrosystem1 application
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *   1. Redistributions of source code must retain the above copyright notice,
+ *      this list of conditions and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above copyright notice,
+ *      this list of conditions and the following disclaimer in the documentation
+ *      and/or other materials provided with the distribution.
+ *   3. Neither the name of STMicroelectronics nor the names of its contributors
+ *      may be used to endorse or promote products derived from this software
+ *      without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
 #include "mbed.h"
-
-/*L0_BlueNRG_xx version main*/
-
 #include <cmath>
 #include <math.h>
 #include "mbed.h"
@@ -25,6 +58,10 @@
     int32_t AXIS_Z;
 } AxesRaw_TypeDef;
 
+#ifdef CUST_BLEERR_MNGT
+#include "CustomBleErrManagement.h"
+#endif
+
 #ifdef CUST_CONS_SERV
 #include "CustomConsoleService.h"
 #endif
@@ -79,7 +116,9 @@
 static CustomConfigService     * p_customconfigservice     = NULL;
 #endif
 
-
+#ifdef CUST_BLEERR_MNGT
+static CustomBleErrManagement  * p_customBleErrManagement = NULL;
+#endif
 
 /***************************    Calibration functions    **************************/
 
@@ -345,12 +384,10 @@
     if (p_customsensorservice)
         p_customsensorservice->enNotify (handle);
 #endif
-
 #ifdef CUST_SW_SERV
     if (p_customsoftwareservice)
         p_customsoftwareservice->enNotify (handle);
 #endif
-
 #ifdef CUST_CONFIG_SERV
     if (p_customconfigservice) {
         p_customconfigservice->enNotify (handle);
@@ -362,7 +399,11 @@
     if (p_customconsoleservice)
         p_customconsoleservice->enNotify (handle);
 #endif
-    /* TODO inform other obj implementing BLE services */
+#ifdef CUST_BLEERR_MNGT
+    if (p_customBleErrManagement)
+        p_customBleErrManagement->clearTxErr();
+#endif
+   /* TODO inform other obj implementing BLE services if any other service is added */
 }
 
 static void onUpdatesDisabledCallback(Gap::Handle_t handle)
@@ -372,12 +413,10 @@
     if (p_customsensorservice)
         p_customsensorservice->disNotify (handle);
 #endif
-
 #ifdef CUST_SW_SERV
     if (p_customsoftwareservice)
         p_customsoftwareservice->disNotify (handle);
 #endif
-
 #ifdef CUST_CONFIG_SERV
     if (p_customconfigservice)
         p_customconfigservice->disNotify (handle);
@@ -386,7 +425,11 @@
     if (p_customconsoleservice)
         p_customconsoleservice->disNotify (handle);
 #endif
-    /* TODO inform other obj implementing BLE services */
+#ifdef CUST_BLEERR_MNGT
+    if (p_customBleErrManagement)
+        p_customBleErrManagement->clearTxErr();
+#endif
+    /* TODO inform other obj implementing BLE services if any other service is added */
 }
 
 //static void onDisconnectionCallback(const Gap::Handle_t handle, const Gap::DisconnectionReason_t disConnectionReason)
@@ -411,7 +454,12 @@
 #ifdef CUST_CONS_SERV
     if (p_customconsoleservice)
         p_customconsoleservice->updateConnectionStatus(DISCONNECTED);
+#endif    
+#ifdef CUST_BLEERR_MNGT
+    if (p_customBleErrManagement)
+        p_customBleErrManagement->updateConnectionStatus(DISCONNECTED);
 #endif
+   /* TODO inform other obj implementing BLE services if any other service is added */
     if (p_BLEdev)
         p_BLEdev->startAdvertising();
 }
@@ -440,6 +488,11 @@
     if (p_customconsoleservice)
         p_customconsoleservice->updateConnectionStatus(CONNECTED);
 #endif
+#ifdef CUST_BLEERR_MNGT
+    if (p_customBleErrManagement)
+        p_customBleErrManagement->updateConnectionStatus(CONNECTED);
+#endif
+   /* TODO inform other obj implementing BLE services if any other service is added */
 }
 
 static void onDataReadCallback(const GattReadCallbackParams *eventDataP)
@@ -644,15 +697,16 @@
     AxesRaw_TypeDef Gyro;
     bool isgyro_lsm6ds0Present=false;
     bool isgyro_lsm6ds3Present=false;    
-#ifdef CUST_CONS_SERV   
-//    static uint8_t          BufferToWrite[256];
-//    static uint8_t          BytesToWrite;           
-#endif    
+  
     static bool SensorFusionOK = false;
 
     DevI2C *i2c = new DevI2C(I2C_SDA, I2C_SCL);
     i2c->frequency(NUCLEO_I2C_SHIELDS_SPEED);
 
+#ifdef CUST_BLEERR_MNGT
+    p_customBleErrManagement = CustomBleErrManagement::Instance();
+#endif
+
 #ifdef CUST_SENS_SERV
     p_mems_expansion_board = X_NUCLEO_IKS01A1::Instance(i2c);
     if (p_mems_expansion_board->gyro_lsm6ds0) isgyro_lsm6ds0Present=true;
@@ -706,7 +760,7 @@
     p_BLEdev->gattServer().onConfirmationReceived(onConfirmationReceivedCallback);    
     p_BLEdev->gattServer().onDataSent(onDataSentCallback);
     p_BLEdev->gattServer().onDataRead(onDataReadCallback);
-        p_BLEdev->gattServer().onDataWritten(myonDataWriteCallback);
+    p_BLEdev->gattServer().onDataWritten(myonDataWriteCallback);
     p_BLEdev->gap().onConnection(onConnectionCallback);
     p_BLEdev->gap().onDisconnection(onDisconnectionCallback);
     p_BLEdev->gap().onTimeout(onTimeoutCallback);
@@ -724,7 +778,7 @@
     }   
         
 #ifdef CUST_CONFIG_SERV
-    p_customconfigservice = new CustomConfigService(*p_BLEdev);
+    p_customconfigservice = new CustomConfigService(*p_BLEdev, p_customBleErrManagement);
     if (!p_customconfigservice) {
         printf("SW      Service W2ST calibration add FAILED!\n\r");
         return 0;  
@@ -732,7 +786,7 @@
     printf("SW      Service W2ST calibration added successfully\r\n");
 #endif
 #ifdef CUST_CONS_SERV
-    p_customconsoleservice = new CustomConsoleService(*p_BLEdev);
+    p_customconsoleservice = new CustomConsoleService(*p_BLEdev, p_customBleErrManagement);
     if (!p_customconsoleservice) {
         printf("\n\rHW      Service W2ST console add FAILED!\n\r");
         return 0;
@@ -740,7 +794,7 @@
     printf("\rHW      Service W2ST console added successfully\r\n");
 #endif
 #ifdef CUST_SENS_SERV
-    p_customsensorservice = new CustomSensorService(*p_BLEdev);
+    p_customsensorservice = new CustomSensorService(*p_BLEdev, p_customBleErrManagement);
     if (!p_customsensorservice) {
         printf("\n\rHW      Service W2ST sensors add FAILED!\n\r");
         return 0;
@@ -751,7 +805,7 @@
         AxesRaw_TypeDef quat_axes[SEND_N_QUATERNIONS];
         float QuatFloat[SEND_N_QUATERNIONS];        
         if (SensorFusionOK) {
-            p_customsoftwareservice = new CustomSoftwareService(*p_BLEdev);
+            p_customsoftwareservice = new CustomSoftwareService(*p_BLEdev, p_customBleErrManagement);
             if (!p_customsoftwareservice) {
                     printf("SW      Service W2ST quaternions add FAILED!\n\r");
                     return 0;