@@ -41,7 +41,9 @@ internal static string createIdentifier(DataTypeBase dataType) {
4141
4242 private const byte ENABLE = 1 , MODE = 2 , OUTPUT_ENABLE = 3 ,
4343 CORRECTED_ACC = 4 , CORRECTED_ROT = 5 , CORRECTED_MAG = 6 ,
44- QUATERNION = 7 , EULER_ANGLES = 8 , GRAVITY_VECTOR = 9 , LINEAR_ACC = 0xa ;
44+ QUATERNION = 7 , EULER_ANGLES = 8 , GRAVITY_VECTOR = 9 , LINEAR_ACC = 0xa ,
45+ CALIBRATION_STATUS = 0xb ;
46+ private const byte CALIBRATION_STATE_REV = 1 ;
4547
4648 [ DataContract ]
4749 private class QuaternionDataType : DataTypeBase {
@@ -262,7 +264,7 @@ public override void Stop() {
262264 [ DataMember ] private byte dataEnableMask ;
263265 [ DataMember ] private DataTypeBase corrAccType , corrAngVelType , corrBFieldType , quaternionType , eulerAnglesType , gravityType , linAccType ;
264266
265- private TimedTask < byte [ ] > readConfigTask ;
267+ private TimedTask < byte [ ] > readValueTask ;
266268
267269 private IAsyncDataProducer correctedAcc = null , correctedAngularVel = null , correctedMag = null ,
268270 quaternion = null , eulerAngles = null ,
@@ -346,8 +348,9 @@ internal override void aggregateDataType(ICollection<DataTypeBase> collection) {
346348 }
347349
348350 protected override void init ( ) {
349- readConfigTask = new TimedTask < byte [ ] > ( ) ;
350- bridge . addRegisterResponseHandler ( Tuple . Create ( ( byte ) SENSOR_FUSION , Util . setRead ( MODE ) ) , response => readConfigTask . SetResult ( response ) ) ;
351+ readValueTask = new TimedTask < byte [ ] > ( ) ;
352+ bridge . addRegisterResponseHandler ( Tuple . Create ( ( byte ) SENSOR_FUSION , Util . setRead ( MODE ) ) , response => readValueTask . SetResult ( response ) ) ;
353+ bridge . addRegisterResponseHandler ( Tuple . Create ( ( byte ) SENSOR_FUSION , Util . setRead ( CALIBRATION_STATUS ) ) , response => readValueTask . SetResult ( response ) ) ;
351354 }
352355
353356 public void Configure ( Mode mode = Mode . Ndof , AccRange ar = AccRange . _16g , GyroRange gr = GyroRange . _2000dps ,
@@ -494,9 +497,18 @@ public void Stop() {
494497 }
495498
496499 public async Task PullConfigAsync ( ) {
497- var response = await readConfigTask . Execute ( "Did not receive sensor fusion config within {0}ms" , bridge . TimeForResponse ,
500+ var response = await readValueTask . Execute ( "Did not receive sensor fusion config within {0}ms" , bridge . TimeForResponse ,
498501 ( ) => bridge . sendCommand ( new byte [ ] { ( byte ) SENSOR_FUSION , Util . setRead ( MODE ) } ) ) ;
499502 mode = ( Mode ) response [ 2 ] ;
500503 }
504+
505+ public async Task < ImuCalibrationState > ReadCalibrationStateAsync ( ) {
506+ if ( bridge . lookupModuleInfo ( SENSOR_FUSION ) . revision >= CALIBRATION_STATE_REV ) {
507+ var response = await readValueTask . Execute ( "Did not received calibration state within {0}ms" , bridge . TimeForResponse ,
508+ ( ) => bridge . sendCommand ( new byte [ ] { ( byte ) SENSOR_FUSION , Util . setRead ( CALIBRATION_STATUS ) } ) ) ;
509+ return new ImuCalibrationState ( ( CalibrationAccuracy ) response [ 2 ] , ( CalibrationAccuracy ) response [ 3 ] , ( CalibrationAccuracy ) response [ 4 ] ) ;
510+ }
511+ throw new InvalidOperationException ( string . Format ( "Minimun firmware v1.4.1 required to use this function (current is {0})" , bridge . getFirmware ( ) . ToString ( ) ) ) ;
512+ }
501513 }
502514}
0 commit comments