From 057822b51c18d577326f0019546b17bdb074b63b Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Thu, 3 Mar 2016 18:22:26 -0300 Subject: [PATCH] AP_InertialSensor: AuxiliaryBus: fix return value We should return the number of bytes written/read, not 0 on success. This number may be useful in some cases so return it. While at it fix a simple wrong space in the header. --- libraries/AP_InertialSensor/AP_InertialSensor_MPU6000.cpp | 8 +++++--- libraries/AP_InertialSensor/AP_InertialSensor_MPU9250.cpp | 8 +++++--- libraries/AP_InertialSensor/AP_InertialSensor_MPU9250.h | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/libraries/AP_InertialSensor/AP_InertialSensor_MPU6000.cpp b/libraries/AP_InertialSensor/AP_InertialSensor_MPU6000.cpp index 677e36c80e..922db12bc1 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor_MPU6000.cpp +++ b/libraries/AP_InertialSensor/AP_InertialSensor_MPU6000.cpp @@ -771,7 +771,7 @@ int AP_MPU6000_AuxiliaryBusSlave::passthrough_write(uint8_t reg, uint8_t val) /* disable new writes */ backend._register_write(_mpu6000_ctrl, 0); - return 0; + return 1; } int AP_MPU6000_AuxiliaryBusSlave::read(uint8_t *buf) @@ -782,9 +782,11 @@ int AP_MPU6000_AuxiliaryBusSlave::read(uint8_t *buf) } auto &backend = AP_InertialSensor_MPU6000::from(_bus.get_backend()); - backend._block_read(MPUREG_EXT_SENS_DATA_00 + _ext_sens_data, buf, _sample_size); + if (!backend._block_read(MPUREG_EXT_SENS_DATA_00 + _ext_sens_data, buf, _sample_size)) { + return -1; + } - return 0; + return _sample_size; } /* MPU6000 provides up to 5 slave devices, but the 5th is way too different to diff --git a/libraries/AP_InertialSensor/AP_InertialSensor_MPU9250.cpp b/libraries/AP_InertialSensor/AP_InertialSensor_MPU9250.cpp index 54569ede63..8faba7f7bb 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor_MPU9250.cpp +++ b/libraries/AP_InertialSensor/AP_InertialSensor_MPU9250.cpp @@ -644,7 +644,7 @@ int AP_MPU9250_AuxiliaryBusSlave::passthrough_write(uint8_t reg, uint8_t val) /* disable new writes */ backend._register_write(_mpu9250_ctrl, 0); - return 0; + return 1; } int AP_MPU9250_AuxiliaryBusSlave::read(uint8_t *buf) @@ -655,9 +655,11 @@ int AP_MPU9250_AuxiliaryBusSlave::read(uint8_t *buf) } auto &backend = AP_InertialSensor_MPU9250::from(_bus.get_backend()); - backend._block_read(MPUREG_EXT_SENS_DATA_00 + _ext_sens_data, buf, _sample_size); + if (!backend._block_read(MPUREG_EXT_SENS_DATA_00 + _ext_sens_data, buf, _sample_size)) { + return -1; + } - return 0; + return _sample_size; } /* MPU9250 provides up to 5 slave devices, but the 5th is way too different to diff --git a/libraries/AP_InertialSensor/AP_InertialSensor_MPU9250.h b/libraries/AP_InertialSensor/AP_InertialSensor_MPU9250.h index f341e3ae83..54a702b147 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor_MPU9250.h +++ b/libraries/AP_InertialSensor/AP_InertialSensor_MPU9250.h @@ -83,7 +83,7 @@ private: * account */ bool _block_read(uint8_t reg, uint8_t *buf, uint32_t size); uint8_t _register_read(uint8_t reg); - void _register_write(uint8_t reg, uint8_t val ); + void _register_write(uint8_t reg, uint8_t val); void _register_write_check(uint8_t reg, uint8_t val); void _accumulate(uint8_t *sample);