![](/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.
Diff: main.cpp
- Revision:
- 10:d19d8a60d3e5
- Parent:
- 9:2693f9ef8ff7
- Child:
- 11:ff82699c696e
--- a/main.cpp Wed Dec 23 11:13:08 2015 +0000 +++ b/main.cpp Wed Apr 13 09:06:47 2016 +0000 @@ -97,7 +97,6 @@ static uint32_t timeoutMems =0; static BLE * p_BLEdev = NULL; static int32_t CounterAGM =0; -static uint32_t bleTxErrCnt =0; #ifdef CUST_CONS_SERV static CustomConsoleService * p_customconsoleservice = NULL; @@ -452,7 +451,6 @@ #endif if (p_BLEdev) p_BLEdev->startAdvertising(); - bleTxErrCnt =0; } static void onConnectionCallback(const Gap::ConnectionCallbackParams_t * connectionParams) @@ -479,7 +477,6 @@ if (p_customconsoleservice) p_customconsoleservice->updateConnectionStatus(CONNECTED); #endif - bleTxErrCnt =0; } static void onDataReadCallback(const GattReadCallbackParams *eventDataP) @@ -734,7 +731,7 @@ return 0; } const Gap::Address_t BLE_address_BE = {BLE_DEV_MAC}; - p_BLEdev->gap().setAddress(Gap::ADDR_TYPE_PUBLIC, BLE_address_BE); + p_BLEdev->gap().setAddress(BLEProtocol::AddressType::PUBLIC, BLE_address_BE); p_BLEdev->init(); @@ -746,14 +743,15 @@ 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); /* Initialize MotionFX library */ - bool DS3_OnBoard = DS3_ONBOARD; +#ifdef USE_SENSOR_FUSION_LIB + bool DS3_OnBoard = DS3_ONBOARD; if (MotionFX_manager_init(DS3_OnBoard, magOffset)) { MotionFX_manager_start_9X(); SensorFusionOK = true; @@ -762,7 +760,11 @@ printf("sensor fusion lib init failed: likely because of wrong license \n\r"); SensorFusionOK = false; } - +#else + printf("sensor fusion lib disabled \n\r"); + SensorFusionOK = false; +#endif + #ifdef CUST_CONFIG_SERV p_customconfigservice = new CustomConfigService(*p_BLEdev); if (!p_customconfigservice) { @@ -870,76 +872,27 @@ timeoutMems =0; #ifdef CUST_SENS_SERV - int32_t err; - err = p_mems_expansion_board->GetAccelerometer()->Get_X_Axes((int32_t *)&Acc); - if (err != IMU_6AXES_OK) { - printf ("= * ERROR %d GetAccelerometer\n\r", err); - } - err = p_mems_expansion_board->GetGyroscope()->Get_G_Axes((int32_t *)&Gyro); - if (err != IMU_6AXES_OK) { - printf ("= * ERROR %d GetGyroscope\n\r", err); - } - err = p_mems_expansion_board->magnetometer->Get_M_Axes((int32_t *)&Magn); - if (err != MAGNETO_OK) { - printf ("= * ERROR %d Get_M_Axes\n\r", err); - } + int32_t err; + err = p_mems_expansion_board->GetAccelerometer()->Get_X_Axes((int32_t *)&Acc); + if (err != IMU_6AXES_OK) { + printf ("= * ERROR %d GetAccelerometer\n\r", err); + } + err = p_mems_expansion_board->GetGyroscope()->Get_G_Axes((int32_t *)&Gyro); + if (err != IMU_6AXES_OK) { + printf ("= * ERROR %d GetGyroscope\n\r", err); + } + err = p_mems_expansion_board->magnetometer->Get_M_Axes((int32_t *)&Magn); + if (err != MAGNETO_OK) { + printf ("= * ERROR %d Get_M_Axes\n\r", err); + } if(CounterAGM >= ACC_GYRO_MAG_UPDATE_MUL_10MS) { CounterAGM=0; - uint32_t bleerr; -#ifdef BLE_TX_ERR_MNG - if (bleTxErrCnt == 0) { -#endif - bleerr = p_customsensorservice->updateEnvAccelerometer (&Acc, TimeStamp); -#ifdef BLE_TX_ERR_MNG - if (bleerr) { - bleTxErrCnt = BLE_TX_SKIP_NUM; - printf ("===> BLE_TX_ERR %d\n\r", err); - } - } else { - bleTxErrCnt--; - } -#endif -#ifdef BLE_TX_ERR_MNG - if (bleTxErrCnt == 0) { -#endif - bleerr = p_customsensorservice->updateEnvGyroscope(&Gyro, TimeStamp); -#ifdef BLE_TX_ERR_MNG - if (bleerr) { - bleTxErrCnt = BLE_TX_SKIP_NUM; - printf ("===> BLE_TX_ERR %d\n\r", err); - } - } else { - bleTxErrCnt--; - } -#endif -#ifdef BLE_TX_ERR_MNG - if (bleTxErrCnt == 0) { -#endif - bleerr = p_customsensorservice->updateEnvMagnetometer(&Magn, TimeStamp, magOffset); -#ifdef BLE_TX_ERR_MNG - if (bleerr) { - bleTxErrCnt = BLE_TX_SKIP_NUM; - printf ("===> BLE_TX_ERR %d\n\r", err); - } - } else { - bleTxErrCnt--; - } -#endif -#ifdef BLE_TX_ERR_MNG - if (bleTxErrCnt == 0) { -#endif - bleerr = p_customsensorservice->updateEnvAccGyroMag (&Acc, &Gyro, &Magn, TimeStamp, magOffset); -#ifdef BLE_TX_ERR_MNG - if (bleerr) { - bleTxErrCnt = BLE_TX_SKIP_NUM; - printf ("===> BLE_TX_ERR %d\n\r", err); - } - } else { - bleTxErrCnt--; - } + p_customsensorservice->updateEnvAccelerometer (&Acc, TimeStamp); + p_customsensorservice->updateEnvGyroscope(&Gyro, TimeStamp); + p_customsensorservice->updateEnvMagnetometer(&Magn, TimeStamp, magOffset); + p_customsensorservice->updateEnvAccGyroMag (&Acc, &Gyro, &Magn, TimeStamp, magOffset); } #endif -#endif #ifdef USE_SENSOR_FUSION_LIB if (SensorFusionOK) { @@ -960,21 +913,8 @@ quat_axes[QuaternionNumber].AXIS_Z = (int)(p_MotionFX_Engine_Out->quaternion_9X[2] * 10000); } - uint32_t bleerr; if (QuaternionNumber == SEND_N_QUATERNIONS-1) { -#ifdef BLE_TX_ERR_MNG - if (bleTxErrCnt == 0) { -#endif - bleerr = p_customsoftwareservice->updateQuaternions(quat_axes, TimeStamp); -#ifdef BLE_TX_ERR_MNG - if (bleerr) { - bleTxErrCnt = BLE_TX_SKIP_NUM; - printf ("===> BLE_TX_ERR %d\n\r", bleerr); - } - } else { - bleTxErrCnt--; - } -#endif + p_customsoftwareservice->updateQuaternions(quat_axes, TimeStamp); QuaternionNumber =0; } else { QuaternionNumber++; @@ -992,25 +932,12 @@ QuatFloat[1] = p_MotionFX_Engine_Out->quaternion_9X[1]; QuatFloat[2] = p_MotionFX_Engine_Out->quaternion_9X[2]; } - uint32_t bleerr; -#ifdef BLE_TX_ERR_MNG - if (bleTxErrCnt == 0) { -#endif - bleerr = p_customsoftwareservice->updateFloatQuaternions(QuatFloat, TimeStamp); -#ifdef BLE_TX_ERR_MNG - if (bleerr) { - bleTxErrCnt = BLE_TX_SKIP_NUM; - printf ("===> BLE_TX_ERR %d\n\r", bleerr); - } - } else { - bleTxErrCnt--; - } -#endif + p_customsoftwareservice->updateFloatQuaternions(QuatFloat, TimeStamp); CounterFloat=0; } else { CounterFloat++; } - } + } #endif } @@ -1059,20 +986,7 @@ } else { floatToInt(temp, &intPart, &decPart, 1); TempToSend = intPart*10+decPart; - uint32_t bleerr; -#ifdef BLE_TX_ERR_MNG - if (bleTxErrCnt == 0) { -#endif - bleerr = p_customsensorservice->updateEnvTemperature(TempToSend, TimeStamp); -#ifdef BLE_TX_ERR_MNG - if (bleerr) { - bleTxErrCnt = BLE_TX_SKIP_NUM; - printf ("===> BLE_TX_ERR %d\n\r", bleerr); - } - } else { - bleTxErrCnt--; - } -#endif + p_customsensorservice->updateEnvTemperature(TempToSend, TimeStamp); } } @@ -1083,20 +997,7 @@ } else { floatToInt(hum, &intPart, &decPart, 1); HumToSend = intPart*10+decPart; -uint32_t bleerr; -#ifdef BLE_TX_ERR_MNG - if (bleTxErrCnt == 0) { -#endif - bleerr = p_customsensorservice->updateEnvHumidity(HumToSend, TimeStamp); -#ifdef BLE_TX_ERR_MNG - if (bleerr) { - bleTxErrCnt = BLE_TX_SKIP_NUM; - printf ("===> BLE_TX_ERR %d\n\r", err); - } - } else { - bleTxErrCnt--; - } -#endif + p_customsensorservice->updateEnvHumidity(HumToSend, TimeStamp); } } @@ -1107,20 +1008,7 @@ } else { floatToInt(pres, &intPart, &decPart, 1); PresToSend = intPart*100+decPart; -uint32_t bleerr; -#ifdef BLE_TX_ERR_MNG - if (bleTxErrCnt == 0) { -#endif - bleerr = p_customsensorservice->updateEnvPressure(PresToSend, TimeStamp); -#ifdef BLE_TX_ERR_MNG - if (bleerr) { - bleTxErrCnt = BLE_TX_SKIP_NUM; - printf ("===> BLE_TX_ERR %d\n\r", err); - } - } else { - bleTxErrCnt--; - } -#endif + p_customsensorservice->updateEnvPressure(PresToSend, TimeStamp); } } #endif