@@ -285,12 +285,13 @@ uint16_t BNO080::parseCommandReport(void)
285285// shtpData[5 + 0]: Then a feature report ID (0x01 for Accel, 0x05 for Rotation Vector)
286286// shtpData[5 + 1]: Sequence number (See 6.5.18.2)
287287// shtpData[5 + 2]: Status
288- // shtpData[3]: Delay
289- // shtpData[4:5]: i/accel x/gyro x/etc
290- // shtpData[6:7]: j/accel y/gyro y/etc
291- // shtpData[8:9]: k/accel z/gyro z/etc
292- // shtpData[10:11]: real/gyro temp/etc
293- // shtpData[12:13]: Accuracy estimate
288+ // shtpData[5 + 3]: Delay
289+ // shtpData[5 + 4:5]: i/accel x/gyro x/etc
290+ // shtpData[5 + 6:7]: j/accel y/gyro y/etc
291+ // shtpData[5 + 8:9]: k/accel z/gyro z/etc
292+ // shtpData[5 + 10:11]: real/gyro temp/etc
293+ // shtpData[5 + 12:13]: Accuracy estimate: Raw Accel/Gyro/Mag Timestap part1
294+ // shtpData[5 + 14:15]: Raw Accel/Gyro/Mag Timestap part2
294295uint16_t BNO080::parseInputReport (void )
295296{
296297 // Calculate the number of data bytes in this packet
@@ -311,7 +312,7 @@ uint16_t BNO080::parseInputReport(void)
311312 rawFastGyroX = (uint16_t )shtpData[9 ] << 8 | shtpData[8 ];
312313 rawFastGyroY = (uint16_t )shtpData[11 ] << 8 | shtpData[10 ];
313314 rawFastGyroZ = (uint16_t )shtpData[13 ] << 8 | shtpData[12 ];
314-
315+ hasNewFastGyro_ = true ;
315316 return SENSOR_REPORTID_GYRO_INTEGRATED_ROTATION_VECTOR;
316317 }
317318
@@ -321,6 +322,7 @@ uint16_t BNO080::parseInputReport(void)
321322 uint16_t data3 = (uint16_t )shtpData[5 + 9 ] << 8 | shtpData[5 + 8 ];
322323 uint16_t data4 = 0 ;
323324 uint16_t data5 = 0 ; // We would need to change this to uin32_t to capture time stamp value on Raw Accel/Gyro/Mag reports
325+ uint32_t memstimeStamp = 0 ; // Timestamp of MEMS sensor reading
324326
325327 if (dataLength - 5 > 9 )
326328 {
@@ -330,6 +332,11 @@ uint16_t BNO080::parseInputReport(void)
330332 {
331333 data5 = (uint16_t )shtpData[5 + 13 ] << 8 | shtpData[5 + 12 ];
332334 }
335+ // only for Raw Reports 0x14, 0x15, 0x16
336+ if (dataLength - 5 >= 15 )
337+ {
338+ memstimeStamp = ((uint32_t )shtpData[5 + 15 ] << (8 * 3 )) | ((uint32_t )shtpData[5 + 14 ] << (8 * 2 )) | ((uint32_t )shtpData[5 + 13 ] << (8 * 1 )) | ((uint32_t )shtpData[5 + 12 ] << (8 * 0 ));
339+ }
333340
334341 // Store these generic values to their proper global variable
335342 if (shtpData[5 ] == SENSOR_REPORTID_ACCELEROMETER || shtpData[5 ] == SENSOR_REPORTID_GRAVITY)
@@ -342,20 +349,23 @@ uint16_t BNO080::parseInputReport(void)
342349 }
343350 else if (shtpData[5 ] == SENSOR_REPORTID_LINEAR_ACCELERATION)
344351 {
352+ hasNewLinAccel_ = true ;
345353 accelLinAccuracy = status;
346354 rawLinAccelX = data1;
347355 rawLinAccelY = data2;
348356 rawLinAccelZ = data3;
349357 }
350358 else if (shtpData[5 ] == SENSOR_REPORTID_GYROSCOPE)
351359 {
360+ hasNewGyro_ = true ;
352361 gyroAccuracy = status;
353362 rawGyroX = data1;
354363 rawGyroY = data2;
355364 rawGyroZ = data3;
356365 }
357366 else if (shtpData[5 ] == SENSOR_REPORTID_MAGNETIC_FIELD)
358367 {
368+ hasNewMag_ = true ;
359369 magAccuracy = status;
360370 rawMagX = data1;
361371 rawMagY = data2;
@@ -418,21 +428,28 @@ uint16_t BNO080::parseInputReport(void)
418428 }
419429 else if (shtpData[5 ] == SENSOR_REPORTID_RAW_ACCELEROMETER)
420430 {
431+ hasNewRawAccel_ = true ;
421432 memsRawAccelX = data1;
422433 memsRawAccelY = data2;
423434 memsRawAccelZ = data3;
435+ memsAccelTimeStamp = memstimeStamp;
424436 }
425437 else if (shtpData[5 ] == SENSOR_REPORTID_RAW_GYROSCOPE)
426438 {
439+ hasNewRawGyro_ = true ;
427440 memsRawGyroX = data1;
428441 memsRawGyroY = data2;
429442 memsRawGyroZ = data3;
443+ memsRawGyroTemp = data4;
444+ memsGyroTimeStamp = memstimeStamp;
430445 }
431446 else if (shtpData[5 ] == SENSOR_REPORTID_RAW_MAGNETOMETER)
432447 {
448+ hasNewRawMag_ = true ;
433449 memsRawMagX = data1;
434450 memsRawMagY = data2;
435451 memsRawMagZ = data3;
452+ memsMagTimeStamp = memstimeStamp;
436453 }
437454 else if (shtpData[5 ] == SHTP_REPORT_COMMAND_RESPONSE)
438455 {
@@ -552,6 +569,16 @@ void BNO080::getQuat(float &i, float &j, float &k, float &real, float &radAccura
552569 hasNewQuaternion = false ;
553570}
554571
572+ bool BNO080::getNewQuat (float &i, float &j, float &k, float &real, float &radAccuracy, uint8_t &accuracy)
573+ {
574+ if (hasNewQuaternion)
575+ {
576+ getQuat (i, j, k, real, radAccuracy, accuracy);
577+ return true ;
578+ }
579+ return false ;
580+ }
581+
555582void BNO080::getGameQuat (float &i, float &j, float &k, float &real, uint8_t &accuracy)
556583{
557584 i = qToFloat (rawGameQuatI, rotationVector_Q1);
@@ -562,6 +589,16 @@ void BNO080::getGameQuat(float &i, float &j, float &k, float &real, uint8_t &acc
562589 hasNewGameQuaternion = false ;
563590}
564591
592+ bool BNO080::getNewGameQuat (float &i, float &j, float &k, float &real, uint8_t &accuracy)
593+ {
594+ if (hasNewGameQuaternion)
595+ {
596+ getGameQuat (i, j, k, real, accuracy);
597+ return true ;
598+ }
599+ return false ;
600+ }
601+
565602void BNO080::getMagQuat (float &i, float &j, float &k, float &real, float &radAccuracy, uint8_t &accuracy)
566603{
567604 i = qToFloat (rawMagQuatI, rotationVector_Q1);
@@ -573,6 +610,16 @@ void BNO080::getMagQuat(float &i, float &j, float &k, float &real, float &radAcc
573610 hasNewMagQuaternion = false ;
574611}
575612
613+ bool BNO080::getNewMagQuat (float &i, float &j, float &k, float &real, float &radAccuracy, uint8_t &accuracy)
614+ {
615+ if (hasNewMagQuaternion)
616+ {
617+ getMagQuat (i, j, k, real, radAccuracy, accuracy);
618+ return true ;
619+ }
620+ return false ;
621+ }
622+
576623bool BNO080::hasNewQuat () {
577624 return hasNewQuaternion;
578625}
@@ -678,6 +725,21 @@ void BNO080::getLinAccel(float &x, float &y, float &z, uint8_t &accuracy)
678725 y = qToFloat (rawLinAccelY, linear_accelerometer_Q1);
679726 z = qToFloat (rawLinAccelZ, linear_accelerometer_Q1);
680727 accuracy = accelLinAccuracy;
728+ hasNewLinAccel_ = false ;
729+ }
730+
731+ bool BNO080::getNewLinAccel (float &x, float &y, float &z, uint8_t &accuracy)
732+ {
733+ if (hasNewLinAccel_)
734+ {
735+ getLinAccel (x, y, z, accuracy);
736+ return true ;
737+ }
738+ return false ;
739+ }
740+
741+ bool BNO080::hasNewLinAccel () {
742+ return hasNewLinAccel_;
681743}
682744
683745// Return the acceleration component
@@ -715,6 +777,7 @@ void BNO080::getGyro(float &x, float &y, float &z, uint8_t &accuracy)
715777 y = qToFloat (rawGyroY, gyro_Q1);
716778 z = qToFloat (rawGyroZ, gyro_Q1);
717779 accuracy = gyroAccuracy;
780+ hasNewGyro_ = false ;
718781}
719782
720783// Return the gyro component
@@ -744,6 +807,10 @@ uint8_t BNO080::getGyroAccuracy()
744807 return (gyroAccuracy);
745808}
746809
810+ bool BNO080::hasNewGyro () {
811+ return hasNewGyro_;
812+ }
813+
747814// Gets the full mag vector
748815// x,y,z output floats
749816void BNO080::getMag (float &x, float &y, float &z, uint8_t &accuracy)
@@ -752,6 +819,7 @@ void BNO080::getMag(float &x, float &y, float &z, uint8_t &accuracy)
752819 y = qToFloat (rawMagY, magnetometer_Q1);
753820 z = qToFloat (rawMagZ, magnetometer_Q1);
754821 accuracy = magAccuracy;
822+ hasNewMag_=false ;
755823}
756824
757825// Return the magnetometer component
@@ -781,6 +849,10 @@ uint8_t BNO080::getMagAccuracy()
781849 return (magAccuracy);
782850}
783851
852+ bool BNO080::hasNewMag () {
853+ return hasNewMag_;
854+ }
855+
784856// Gets the full high rate gyro vector
785857// x,y,z output floats
786858void BNO080::getFastGyro (float &x, float &y, float &z)
@@ -811,6 +883,10 @@ float BNO080::getFastGyroZ()
811883 return (gyro);
812884}
813885
886+ bool BNO080::hasNewFastGyro () {
887+ return hasNewFastGyro_;
888+ }
889+
814890// Return the tap detector
815891uint8_t BNO080::getTapDetector ()
816892{
@@ -864,6 +940,29 @@ int16_t BNO080::getRawAccelZ()
864940 return (memsRawAccelZ);
865941}
866942
943+ void BNO080::getRawAccel (int16_t &x, int16_t &y, int16_t &z, uint32_t &timeStamp)
944+ {
945+ x = memsRawAccelX;
946+ y = memsRawAccelY;
947+ z = memsRawAccelZ;
948+ timeStamp = memsAccelTimeStamp;
949+ hasNewRawAccel_ = false ;
950+ }
951+
952+ bool BNO080::getNewRawAccel (int16_t &x, int16_t &y, int16_t &z, uint32_t &timeStamp)
953+ {
954+ if (hasNewRawAccel_)
955+ {
956+ getRawAccel (x, y, z, timeStamp);
957+ return true ;
958+ }
959+ return false ;
960+ }
961+
962+ bool BNO080::hasNewRawAccel () {
963+ return hasNewRawAccel_;
964+ }
965+
867966// Return raw mems value for the gyro
868967int16_t BNO080::getRawGyroX ()
869968{
@@ -878,6 +977,42 @@ int16_t BNO080::getRawGyroZ()
878977 return (memsRawGyroZ);
879978}
880979
980+ // From https://github.com/ceva-dsp/sh2/issues/15
981+ // Raw gyro temperature for BNO085 uses BMI055 gyro
982+ // memsRawGyroTemp is in 23°C + 0.5°C/LSB
983+ float BNO080::getGyroTemp ()
984+ {
985+ return (23.0 + (0 .5f * memsRawGyroTemp));
986+ }
987+
988+ void BNO080::resetNewRawGyro ()
989+ {
990+ hasNewRawGyro_ = false ;
991+ }
992+
993+ void BNO080::getRawGyro (int16_t &x, int16_t &y, int16_t &z, uint32_t &timeStamp)
994+ {
995+ x = memsRawGyroX;
996+ y = memsRawGyroY;
997+ z = memsRawGyroZ;
998+ timeStamp = memsGyroTimeStamp;
999+ hasNewRawGyro_ = false ;
1000+ }
1001+
1002+ bool BNO080::getNewRawGyro (int16_t &x, int16_t &y, int16_t &z, uint32_t &timeStamp)
1003+ {
1004+ if (hasNewRawGyro_)
1005+ {
1006+ getRawGyro (x, y, z, timeStamp);
1007+ return true ;
1008+ }
1009+ return false ;
1010+ }
1011+
1012+ bool BNO080::hasNewRawGyro () {
1013+ return hasNewRawGyro_;
1014+ }
1015+
8811016// Return raw mems value for the mag
8821017int16_t BNO080::getRawMagX ()
8831018{
@@ -892,6 +1027,29 @@ int16_t BNO080::getRawMagZ()
8921027 return (memsRawMagZ);
8931028}
8941029
1030+ void BNO080::getRawMag (int16_t &x, int16_t &y, int16_t &z, uint32_t &timeStamp)
1031+ {
1032+ x = memsRawMagX;
1033+ y = memsRawMagY;
1034+ z = memsRawMagZ;
1035+ timeStamp = memsMagTimeStamp;
1036+ hasNewRawMag_ = false ;
1037+ }
1038+
1039+ bool BNO080::getNewRawMag (int16_t &x, int16_t &y, int16_t &z, uint32_t &timeStamp)
1040+ {
1041+ if (hasNewRawMag_)
1042+ {
1043+ getRawMag (x, y, z, timeStamp);
1044+ return true ;
1045+ }
1046+ return false ;
1047+ }
1048+
1049+ bool BNO080::hasNewRawMag () {
1050+ return hasNewRawMag_;
1051+ }
1052+
8951053// Given a record ID, read the Q1 value from the metaData record in the FRS (ya, it's complicated)
8961054// Q1 is used for all sensor data calculations
8971055int16_t BNO080::getQ1 (uint16_t recordID)
0 commit comments