AP_Compass: VRBRAIN. Deal with external mag connected on internal I2C on VRBRAIN 4.5

This enables user to set the external parameter to true even if only one compass is connected
This commit is contained in:
Emile Castelnuovo 2014-08-14 08:18:39 +02:00 committed by Andrew Tridgell
parent bbb9925c47
commit 3b53c167a0

View File

@ -57,10 +57,8 @@ bool AP_Compass_VRBRAIN::init(void)
}
for (uint8_t i=0; i<_num_instances; i++) {
#ifdef DEVIOCGDEVICEID
// get device id
_dev_id[i] = ioctl(_mag_fd[i], DEVIOCGDEVICEID, 0);
#endif
// average over up to 20 samples
if (ioctl(_mag_fd[i], SENSORIOCSQUEUEDEPTH, 20) != 0) {
@ -70,6 +68,11 @@ bool AP_Compass_VRBRAIN::init(void)
// remember if the compass is external
_is_external[i] = (ioctl(_mag_fd[i], MAGIOCGEXTERNAL, 0) > 0);
#if defined(CONFIG_ARCH_BOARD_VRBRAIN_V45)
//deal with situations where user has cut internal mag on VRBRAIN 4.5
//and uses only one external mag attached to the internal I2C bus
_is_external[i] = _external.load() ? _external.get() : _is_external[i];
#endif
if (_is_external[i]) {
hal.console->printf("Using external compass[%u]\n", (unsigned)i);
}
@ -109,7 +112,7 @@ bool AP_Compass_VRBRAIN::read(void)
_sum[i].rotate(MAG_BOARD_ORIENTATION);
// override any user setting of COMPASS_EXTERNAL
_external.set(_is_external[0]);
//_external.set(_is_external[0]);
if (_is_external[i]) {
// add user selectable orientation