diff --git a/libraries/AP_Compass/AP_Compass_VRBRAIN.cpp b/libraries/AP_Compass/AP_Compass_VRBRAIN.cpp index 3794016ec8..fe42a63929 100644 --- a/libraries/AP_Compass/AP_Compass_VRBRAIN.cpp +++ b/libraries/AP_Compass/AP_Compass_VRBRAIN.cpp @@ -44,18 +44,18 @@ extern const AP_HAL::HAL& hal; bool AP_Compass_VRBRAIN::init(void) { _mag_fd[0] = open(MAG_DEVICE_PATH, O_RDONLY); - if (_mag_fd[0] < 0) { + _mag_fd[1] = open(MAG_DEVICE_PATH "1", O_RDONLY); + _num_instances = 0; + for (uint8_t i=0; i= 0) { + _num_instances = i+1; + } + } + if (_num_instances == 0) { hal.console->printf("Unable to open " MAG_DEVICE_PATH "\n"); return false; } - _mag_fd[1] = open(MAG_DEVICE_PATH "1", O_RDONLY); - if (_mag_fd[1] >= 0) { - _num_instances = 2; - } else { - _num_instances = 1; - } - for (uint8_t i=0; i<_num_instances; i++) { #ifdef DEVIOCGDEVICEID // get device id